diff --git a/README.md b/README.md index d7ba021..fe3bdfb 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ We use interfaces where is possible, so you can implement your own version of ta com.github.aquality-automation aquality-selenium - 1.1.2 + 1.1.3 ``` diff --git a/pom.xml b/pom.xml index f749dff..9a56269 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.aquality-automation aquality-selenium - 1.1.2 + 1.1.3 jar Aquality Selenium diff --git a/src/main/java/aquality/selenium/browser/BrowserManager.java b/src/main/java/aquality/selenium/browser/BrowserManager.java index 2852503..81c815c 100644 --- a/src/main/java/aquality/selenium/browser/BrowserManager.java +++ b/src/main/java/aquality/selenium/browser/BrowserManager.java @@ -3,6 +3,9 @@ import aquality.selenium.configuration.Configuration; import aquality.selenium.configuration.IConfiguration; +/** + * Controls browser instance creation. + */ public class BrowserManager { private static final ThreadLocal browserContainer = new ThreadLocal<>(); private static final ThreadLocal factoryContainer = new ThreadLocal<>(); @@ -10,6 +13,10 @@ public class BrowserManager { private BrowserManager(){ } + /** + * Gets instance of browser. + * @return Instance of desired browser. + */ public static Browser getBrowser(){ if(browserContainer.get() == null || browserContainer.get().getDriver().getSessionId() == null) { setDefaultBrowser(); @@ -17,6 +24,9 @@ public static Browser getBrowser(){ return browserContainer.get(); } + /** + * Sets default(local {@link LocalBrowserFactory} or remote {@link RemoteBrowserFactory}) browser factory. + */ public static void setDefaultFactory(){ IConfiguration configuration = Configuration.getInstance(); IBrowserFactory browserFactory = Configuration.getInstance().getBrowserProfile().isRemote() @@ -24,6 +34,10 @@ public static void setDefaultFactory(){ setFactory(browserFactory); } + /** + * Sets custom browser factory. + * @param browserFactory Custom implementation of {@link IBrowserFactory} + */ public static void setFactory(IBrowserFactory browserFactory){ remove(factoryContainer); BrowserManager.factoryContainer.set(browserFactory); @@ -36,6 +50,10 @@ private static void setDefaultBrowser(){ setBrowser(factoryContainer.get().getBrowser()); } + /** + * Sets instance of browser. + * @param browser Instance of desired browser. + */ public static void setBrowser(Browser browser){ remove(browserContainer); BrowserManager.browserContainer.set(browser); diff --git a/src/main/java/aquality/selenium/browser/IBrowserFactory.java b/src/main/java/aquality/selenium/browser/IBrowserFactory.java index 2323a02..8976373 100644 --- a/src/main/java/aquality/selenium/browser/IBrowserFactory.java +++ b/src/main/java/aquality/selenium/browser/IBrowserFactory.java @@ -1,6 +1,13 @@ package aquality.selenium.browser; +/** + * Factory that creates instance of desired Browser based on {@link aquality.selenium.configuration.IConfiguration} + */ public interface IBrowserFactory { + /** + * Gets instance of Browser. + * @return Instance of desired Browser. + */ Browser getBrowser(); } diff --git a/src/main/java/aquality/selenium/configuration/IBrowserProfile.java b/src/main/java/aquality/selenium/configuration/IBrowserProfile.java index a3232fe..383db18 100644 --- a/src/main/java/aquality/selenium/configuration/IBrowserProfile.java +++ b/src/main/java/aquality/selenium/configuration/IBrowserProfile.java @@ -5,15 +5,38 @@ import java.net.URL; +/** + * Describes browser settings. + */ public interface IBrowserProfile { + /** + * Gets name of target browser. + * @return Browser name. + */ BrowserName getBrowserName(); + /** + * Checks if is remote browser or not. + * @return true if remote browser and false if local. + */ boolean isRemote(); + /** + * Is element hightlight enabled or not. + * @return true if element highlight is enabled and false otherwise. + */ boolean isElementHighlightEnabled(); + /** + * Gets driver settings for target browser. + * @return Driver settings. + */ IDriverSettings getDriverSettings(); + /** + * Gets remote connection URI is case of remote browser. + * @return Remote connection URI. + */ URL getRemoteConnectionUrl(); } diff --git a/src/main/java/aquality/selenium/configuration/IConfiguration.java b/src/main/java/aquality/selenium/configuration/IConfiguration.java index 8a6fe7b..1f92fd3 100644 --- a/src/main/java/aquality/selenium/configuration/IConfiguration.java +++ b/src/main/java/aquality/selenium/configuration/IConfiguration.java @@ -1,12 +1,31 @@ package aquality.selenium.configuration; +/** + * Describes tool configuration. + */ public interface IConfiguration { + /** + * Gets desired browser profile. + * @return Profile of browser. + */ IBrowserProfile getBrowserProfile(); + /** + * Gets configuration of timeouts. + * @return Configuration of timeouts. + */ ITimeoutConfiguration getTimeoutConfiguration(); + /** + * Gets configuration of retries. + * @return Configuration of retries. + */ IRetryConfiguration getRetryConfiguration(); + /** + * Gets configuration of logger. + * @return Configuration of logger. + */ ILoggerConfiguration getLoggerConfiguration(); } \ No newline at end of file diff --git a/src/main/java/aquality/selenium/configuration/ILoggerConfiguration.java b/src/main/java/aquality/selenium/configuration/ILoggerConfiguration.java index 8dc75e0..e340dbc 100644 --- a/src/main/java/aquality/selenium/configuration/ILoggerConfiguration.java +++ b/src/main/java/aquality/selenium/configuration/ILoggerConfiguration.java @@ -2,7 +2,14 @@ import aquality.selenium.localization.SupportedLanguage; +/** + * Describes logger configuration. + */ public interface ILoggerConfiguration { + /** + * Gets language which will be used for framework logger. + * @return Supported language. + */ SupportedLanguage getLanguage(); } diff --git a/src/main/java/aquality/selenium/configuration/ITimeoutConfiguration.java b/src/main/java/aquality/selenium/configuration/ITimeoutConfiguration.java index 5b6f5ce..1413e94 100644 --- a/src/main/java/aquality/selenium/configuration/ITimeoutConfiguration.java +++ b/src/main/java/aquality/selenium/configuration/ITimeoutConfiguration.java @@ -1,16 +1,43 @@ package aquality.selenium.configuration; +/** + * Describes timeouts configuration. + */ public interface ITimeoutConfiguration { + /** + * Gets WedDriver ImplicitWait timeout. + * @return ImplicitWait timeout. + */ long getImplicit(); + /** + * Gets default ConditionalWait timeout. + * @return ConditionalWait timeout. + */ long getCondition(); + /** + * Gets WedDriver AsynchronousJavaScript timeout. + * @return AsynchronousJavaScript timeout. + */ long getScript(); + /** + * Gets WedDriver PageLoad timeout. + * @return PageLoad timeout. + */ long getPageLoad(); + /** + * Gets ConditionalWait polling interval. + * @return ConditionalWait polling interval. + */ long getPollingInterval(); + /** + * Gets Command timeout. + * @return Command timeout. + */ long getCommand(); } diff --git a/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java b/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java index 859a9cd..c282cc2 100644 --- a/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java +++ b/src/main/java/aquality/selenium/configuration/driversettings/IDriverSettings.java @@ -4,20 +4,51 @@ import aquality.selenium.utils.JsonFile; import org.openqa.selenium.Capabilities; +/** + * Describes web driver settings. + */ public interface IDriverSettings { + /** + * Gets web driver capabilities. + * @return initialized {@link Capabilities} + */ Capabilities getCapabilities(); + /** + * Gets version of web driver for WebDriverManager. + * @return Version of web driver. + */ String getWebDriverVersion(); + /** + * Gets target system architecture for WebDriverManager. + * @return System architecture. + */ String getSystemArchitecture(); + /** + * Gets download directory for web driver. + * @return Path to download directory. + */ String getDownloadDir(); + /** + * Gets web driver capability key for download directory. + * @return Web driver capability key + */ String getDownloadDirCapabilityKey(); + /** + * Get desired browser name. + * @return Browser name + */ BrowserName getBrowserName(); + /** + * Gets desired json file. + * @return Json file. + */ JsonFile getSettingsFile(); } diff --git a/src/main/java/aquality/selenium/elements/actions/CheckBoxJsActions.java b/src/main/java/aquality/selenium/elements/actions/CheckBoxJsActions.java index c6a91c6..14fa624 100644 --- a/src/main/java/aquality/selenium/elements/actions/CheckBoxJsActions.java +++ b/src/main/java/aquality/selenium/elements/actions/CheckBoxJsActions.java @@ -3,6 +3,9 @@ import aquality.selenium.browser.JavaScript; import aquality.selenium.elements.interfaces.ICheckBox; +/** + * Allows to perform actions on elements via JavaScript specific for CheckBoxes. + */ public class CheckBoxJsActions extends JsActions { public CheckBoxJsActions(ICheckBox checkBox, String elementType) { @@ -17,18 +20,31 @@ public boolean getState() { return Boolean.valueOf(executeScript(JavaScript.GET_CHECKBOX_STATE, element).toString()); } + /** + * Performs check action on the element. + */ public void check() { setState(true); } + /** + * Performs uncheck action on the element. + */ public void uncheck() { setState(false); } + /** + * Get status if element is checked + * @return true if checked, false otherwise + */ public boolean isChecked() { return getState(); } + /** + * Performs toggle action on the element. + */ public void toggle() { setState(!isChecked()); } diff --git a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java index e1b566e..5637a43 100644 --- a/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java +++ b/src/main/java/aquality/selenium/elements/interfaces/IElementFactory.java @@ -7,53 +7,164 @@ import java.util.List; +/** + * Defines the interface used to create the elements. + */ public interface IElementFactory { + /** + * Creates element that implements IButton interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements IButton interface + */ default IButton getButton(By locator, String name) { return getButton(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements IButton interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements IButton interface + */ IButton getButton(By locator, String name, ElementState state); + /** + * Creates element that implements ICheckBox interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements ICheckBox interface + */ default ICheckBox getCheckBox(By locator, String name) { return getCheckBox(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements ICheckBox interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements ICheckBox interface + */ ICheckBox getCheckBox(By locator, String name, ElementState state); + /** + * Creates element that implements IComboBox interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements IComboBox interface + */ default IComboBox getComboBox(By locator, String name) { return getComboBox(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements IComboBox interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements IComboBox interface + */ IComboBox getComboBox(By locator, String name, ElementState state); + /** + * Creates element that implements ILabel interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements ILabel interface + */ default ILabel getLabel(By locator, String name) { return getLabel(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements ILabel interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements ILabel interface + */ ILabel getLabel(By locator, String name, ElementState state); + /** + * Creates element that implements ILink interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements ILink interface + */ default ILink getLink(By locator, String name) { return getLink(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements ILink interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements ILink interface + */ ILink getLink(By locator, String name, ElementState state); + /** + * Creates element that implements IRadioButton interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements IRadioButton interface + */ default IRadioButton getRadioButton(By locator, String name) { return getRadioButton(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements IRadioButton interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements IRadioButton interface + */ IRadioButton getRadioButton(By locator, String name, ElementState state); + /** + * Creates element that implements ITextBox interface. + * @param locator Element locator + * @param name Element name + * @return Instance of element that implements ITextBox interface + */ default ITextBox getTextBox(By locator, String name) { return getTextBox(locator, name, ElementState.DISPLAYED); } + /** + * Creates element that implements ITextBox interface. + * @param locator Element locator + * @param name Element name + * @param state Element state + * @return Instance of element that implements ITextBox interface + */ ITextBox getTextBox(By locator, String name, ElementState state); + /** + * Creates an instance of custom element that implements IElement interface. + * @param supplier Delegate that defines constructor of element + * @param locator Element locator + * @param name Element name + * @param Type of custom element that has to implement IElement + * @return Instance of custom element that implements IElement interface + */ default T getCustomElement(IElementSupplier supplier, By locator, String name) { return getCustomElement(supplier, locator, name, ElementState.DISPLAYED); } + /** + * Creates an instance of custom element that implements IElement interface. + * @param supplier Delegate that defines constructor of element + * @param locator Element locator + * @param name Element name + * @param state Element state + * @param Type of custom element that has to implement IElement + * @return Instance of custom element that implements IElement interface + */ T getCustomElement(IElementSupplier supplier, By locator, String name, ElementState state); /** diff --git a/src/main/java/aquality/selenium/utils/JsonFile.java b/src/main/java/aquality/selenium/utils/JsonFile.java index bff4bf3..09dbeb3 100644 --- a/src/main/java/aquality/selenium/utils/JsonFile.java +++ b/src/main/java/aquality/selenium/utils/JsonFile.java @@ -11,23 +11,44 @@ import java.nio.file.Paths; import java.util.*; +/** + * Provides methods to get info from JSON files. + * Note that the value can be overriden via Environment variable with the same name + * (e.g. for json path ".timeouts.timeoutScript" you can set environment variable "timeouts.timeoutScript") + */ public class JsonFile { private final ObjectMapper mapper = new ObjectMapper(); private final String fileCanonicalPath; private final String content; + /** + * Inistantiates class using desired JSON file. + * @param file JSON file. + * @throws IOException if file is not found + */ public JsonFile(File file) throws IOException { this.content = getFileContent(file.getCanonicalPath()); fileCanonicalPath = file.getCanonicalPath(); } + /** + * Inistantiates class using desired JSON file. + * @param resourceName path to JSON relatively resources + */ public JsonFile(String resourceName) { ResourceFile resourceFile = new ResourceFile(resourceName); this.content = resourceFile.getFileContent(); this.fileCanonicalPath = resourceFile.getFileCanonicalPath(); } + /** + * Gets value from JSON. + * Note that the value can be overriden via Environment variable with the same name + * (e.g. for json path ".timeouts.timeoutScript" you can set environment variable "timeouts.timeoutScript") + * @param jsonPath Relative jsonPath to the value. + * @return Value from JSON/Environment by jsonPath. + */ public Object getValue(String jsonPath){ return getEnvValueOrDefault(jsonPath); } @@ -50,12 +71,24 @@ private Object getEnvValueOrDefault(String jsonPath){ } } + /** + * Gets list of values from JSON. + * @param jsonPath Relative JsonPath to the values. + * @return Values from JSON/Environment by jsonPath. + */ public List getList(String jsonPath){ List list = new ArrayList<>(); getJsonNode(jsonPath).elements().forEachRemaining(node -> list.add(node.asText())); return list; } + /** + * Gets map of values from JSON. + * Note that the value can be overriden via Environment variable with the same name + * (e.g. for json path ".timeouts.timeoutScript" you can set environment variable "timeouts.timeoutScript") + * @param jsonPath + * @return + */ public Map getMap(String jsonPath) { Iterator> iterator = getJsonNode(jsonPath).fields(); final Map result = new HashMap<>(); @@ -80,10 +113,18 @@ private String getFileContent(String filename) { } } + /** + * Gets content of JsonFile + * @return content of the file + */ public String getContent() { return content; } + /** + * Gets canonical path to the file + * @return canonical path to the file + */ public String getFileCanonicalPath() { return fileCanonicalPath; } diff --git a/src/test/java/automationpractice/forms/ProductListForm.java b/src/test/java/automationpractice/forms/ProductListForm.java index 1b8bc68..42ef047 100644 --- a/src/test/java/automationpractice/forms/ProductListForm.java +++ b/src/test/java/automationpractice/forms/ProductListForm.java @@ -39,7 +39,7 @@ public ILabel getLblLastProduct(){ public IButton getBtnLastProductMoreFocused() { getLblFirstProduct().getMouseActions().moveMouseToElement(); getLblLastProduct().getMouseActions().moveMouseToElement(); - IButton btnLastProductMore = getLblLastProduct().findChildElement(By.xpath(".//a[contains(@class, 'lnk_view')]"), ElementType.BUTTON); + IButton btnLastProductMore = getLblLastProduct().findChildElement(By.xpath(".//a[contains(@class, 'lnk_view')]"), ElementType.BUTTON, ElementState.EXISTS_IN_ANY_STATE); if(!btnLastProductMore.state().isDisplayed()) { getLblLastProduct().getMouseActions().moveMouseFromElement(); getLblLastProduct().getMouseActions().moveMouseToElement();