From 8b2fb317e2f3e74694b332bb25cdc82df2ee64bf Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Mon, 10 Feb 2020 17:26:54 +0300 Subject: [PATCH 01/21] #15 extracted IElement --- .../selenium/core/elements/Element.java | 139 ++++++++++++++++++ .../core/elements/interfaces/IElement.java | 74 ++++++++++ .../elements/interfaces/IElementSupplier.java | 21 +++ .../core/elements/interfaces/IParent.java | 97 ++++++++++++ src/main/resources/localization/be.json | 3 +- src/main/resources/localization/en.json | 3 +- src/main/resources/localization/ru.json | 3 +- 7 files changed, 337 insertions(+), 3 deletions(-) create mode 100644 src/main/java/aquality/selenium/core/elements/Element.java create mode 100644 src/main/java/aquality/selenium/core/elements/interfaces/IElement.java create mode 100644 src/main/java/aquality/selenium/core/elements/interfaces/IElementSupplier.java create mode 100644 src/main/java/aquality/selenium/core/elements/interfaces/IParent.java diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java new file mode 100644 index 0000000..2b31ea2 --- /dev/null +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -0,0 +1,139 @@ +package aquality.selenium.core.elements; + +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.configurations.IElementCacheConfiguration; +import aquality.selenium.core.elements.interfaces.IElement; +import aquality.selenium.core.elements.interfaces.IElementFinder; +import aquality.selenium.core.elements.interfaces.IElementSupplier; +import aquality.selenium.core.localization.ILocalizedLogger; +import aquality.selenium.core.logging.Logger; +import aquality.selenium.core.utilities.IElementActionRetrier; +import aquality.selenium.core.waitings.ConditionalWait; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.WebDriverException; +import org.openqa.selenium.remote.RemoteWebElement; + +import java.util.function.Supplier; + +/** + * Abstract class, describing wrapper of WebElement. + */ +public abstract class Element implements IElement { + + private final String name; + private final ElementState elementState; + private final By locator; + private IElementCacheHandler elementCacheHandler; + + protected Element(final By loc, final String name, final ElementState state) { + locator = loc; + this.name = name; + elementState = state; + } + + protected abstract IApplication getApplication(); + + protected abstract IElementFactory getElementFactory(); + + protected abstract IElementFinder getElementFinder(); + + protected abstract IElementCacheConfiguration getElementCacheConfiguration(); + + protected abstract IElementActionRetrier getElementActionRetrier(); + + protected abstract ILocalizedLogger getLocalizedLogger(); + + protected abstract String getElementType(); + + protected abstract ConditionalWait getConditionalWait(); + + protected abstract IElementCacheHandler getCache() { + if (elementCacheHandler == null) { + elementCacheHandler = new ElementCacheHandler(locator, elementState, getElementFinder()); + } + } + + protected Logger getLogger() { + return Logger.getInstance(); + } + + @Override + public By getLocator() { + return locator; + } + + @Override + public String getName() { + return name; + } + + @Override + public IElementStateProvider state() { + return getElementCacheConfiguration().isEnabled() + ? (IElementStateProvider) new CachedElementStateProvider(locator, getConditionalWait(), getCache()) + : new ElementStateProvider(locator, getConditionalWait(), getElementFinder()); + } + + @Override + public RemoteWebElement getElement(Long timeout) { + try { + return getElementCacheConfiguration().isEnabled() + ? getCache().getElement(timeout) + : (RemoteWebElement) getElementFinder().findElement(locator, elementState, timeout); + } catch (NoSuchElementException e) { + logPageSource(e); + throw e; + } + } + + protected void logPageSource(WebDriverException exception) { + try { + getLogger().debug("Page source:".concat(System.lineSeparator()).concat(getApplication().getDriver().getPageSource()), exception); + } catch (WebDriverException e) { + getLogger().error(exception.getMessage()); + getLocalizedLogger().fatal("loc.get.page.source.failed", e); + } + } + + @Override + public String getText() { + logElementAction("loc.get.text"); + return doWithRetry(() -> getElement().getText()); + } + + @Override + public String getAttribute(String attr) { + logElementAction("loc.el.getattr", attr); + return doWithRetry(() -> getElement().getAttribute(attr)); + } + + @Override + public void sendKeys(String keys) { + logElementAction("loc.text.sending.keys", keys); + doWithRetry(() -> getElement().sendKeys(keys)); + } + + @Override + public void click() { + logElementAction("loc.clicking"); + doWithRetry(() -> getElement().click()); + } + + @Override + public T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state) { + return getElementFactory.findChildElement(this, childLoc, name, supplier, state); + } + + protected T doWithRetry(Supplier action) { + return getElementActionRetrier().doWithRetry(action); + } + + protected void doWithRetry(Runnable action) { + getElementActionRetrier().doWithRetry(action); + } + + protected void logElementAction(String messageKey, Object... args) { + getLocalizedLogger().infoElementAction(getElementType(), name, messageKey, args); + } +} diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java b/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java new file mode 100644 index 0000000..d925e17 --- /dev/null +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java @@ -0,0 +1,74 @@ +package aquality.selenium.core.elements.interfaces; + +import org.openqa.selenium.By; +import org.openqa.selenium.remote.RemoteWebElement; + +public interface IElement extends IParent { + /** + * Gets unique locator of element. + * + * @return Element locator + */ + By getLocator(); + + /** + * Gets unique name of element + * + * @return name + */ + String getName(); + + /** + * Provides ability to define of element's state (whether it is displayed, exists or not) and respective waiting functions + * + * @return provider to define element's state + */ + IElementStateProvider state(); + + /** + * Gets current element by specified {@link #getLocator()} + * Default timeout is provided in {@link aquality.selenium.core.configurations.ITimeoutConfiguration}/> + * {@link org.openqa.selenium.NoSuchElementException} throws if element not found + * + * @return instance of {@link RemoteWebElement} if found. + */ + default RemoteWebElement getElement() { + return getElement(null); + } + + /** + * Gets current element by specified {@link #getLocator()} + * {@link org.openqa.selenium.NoSuchElementException} throws if element not found + * + * @param timeout Timeout for waiting + * @return instance of {@link RemoteWebElement} if found. + */ + RemoteWebElement getElement(Long timeout); + + /** + * Gets the item text (inner text). + * + * @return text of element + */ + String getText(); + + /** + * Gets attribute value of the element. + * + * @param attr Attribute name + * @return Attribute value + */ + String getAttribute(String attr); + + /** + * Sends keys + * + * @param keys keys for sending + */ + void sendKeys(String keys); + + /** + * Clicks on the item. + */ + void click(); +} diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IElementSupplier.java b/src/main/java/aquality/selenium/core/elements/interfaces/IElementSupplier.java new file mode 100644 index 0000000..61a0b95 --- /dev/null +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElementSupplier.java @@ -0,0 +1,21 @@ +package aquality.selenium.core.elements.interfaces; + +import aquality.selenium.core.elements.ElementState; +import org.openqa.selenium.By; + +/** + * Describes interface to supply class which implements IElement interface + * + * @param type of the element to be supplied + */ +public interface IElementSupplier { + /** + * Returns an instance of element + * + * @param locator By locator + * @param name output name in logs + * @param state desired element's state + * @return an instance of element + */ + T get(By locator, String name, ElementState state); +} diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java new file mode 100644 index 0000000..d0d758a --- /dev/null +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java @@ -0,0 +1,97 @@ +package aquality.selenium.core.elements.interfaces; + +import aquality.selenium.core.elements.ElementState; +import org.openqa.selenium.By; + +public interface IParent { + /** + * Finds an element in the parent element + * + * @param childLoc child element locator + * @return child element + */ + default T findChildElement(By childLoc) { + return findChildElement(childLoc, null, null, null); + } + + /** + * Finds an element in the parent element + * + * @param childLoc child element locator + * @param name output name in logs + * @return child element + */ + default T findChildElement(By childLoc, String name) { + return findChildElement(childLoc, name, null, null); + } + + /** + * Finds an element in the parent element + * + * @param childLoc Child element locator + * @param state visibility state of target element + * @return child element + */ + default T findChildElement(By childLoc, ElementState state) { + return findChildElement(childLoc, null, null, state); + } + + /** + * Finds an element in the parent element + * + * @param childLoc Child element locator + * @param supplier required element's supplier + * @return found child element + */ + default T findChildElement(By childLoc, IElementSupplier supplier) { + return findChildElement(childLoc, null, supplier, null); + } + + /** + * Finds an element in the parent element + * + * @param childLoc child element locator + * @param name output name in logs + * @param supplier required element's supplier + * @return found child element + */ + default T findChildElement(By childLoc, String name, IElementSupplier supplier) { + return findChildElement(childLoc, name, supplier, null); + } + + /** + * Finds an element in the parent element + * + * @param childLoc child element locator + * @param name output name in logs + * @param state visibility state of target element + * @return found child element + */ + default T findChildElement(By childLoc, String name, ElementState state) { + return findChildElement(childLoc, name, null, state); + } + + /** + * Finds an element in the parent element + * + * @param childLoc Child element locator + * @param supplier required element's supplier + * @param state visibility state of target element + * @return found child element + */ + default T findChildElement(By childLoc, IElementSupplier supplier, ElementState state) { + return findChildElement(childLoc, null, supplier, state); + } + + /** + * Finds an element in the parent element + * + * @param childLoc Child element locator + * @param name output name in logs + * @param supplier required element's supplier + * @param state visibility state of target element + * @param the type of the element to be obtained + * @return found child element + */ + T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state); +} diff --git a/src/main/resources/localization/be.json b/src/main/resources/localization/be.json index b364b8a..8da2d81 100644 --- a/src/main/resources/localization/be.json +++ b/src/main/resources/localization/be.json @@ -7,5 +7,6 @@ "loc.no.elements.found.by.locator": "Не знайшлі элементаў па лакатару '%1$s'", "loc.elements.were.found.but.not.in.state": "Знайшлі элементы па лакатару '%1$s', але яны не ў жаданым стане %2$s", "loc.elements.found.but.should.not": "Не павінна быць знойдзена элементаў па лакатару '%1$s' у %2$s стане", - "loc.search.of.elements.failed": "Пошук элемента па лакатару '%1$s' прайшоў няўдала" + "loc.search.of.elements.failed": "Пошук элемента па лакатару '%1$s' прайшоў няўдала", + "loc.get.page.source.failed": "Адбылася памылка ў час атрымання разметкі старонкі" } \ No newline at end of file diff --git a/src/main/resources/localization/en.json b/src/main/resources/localization/en.json index 0021326..77ddf56 100644 --- a/src/main/resources/localization/en.json +++ b/src/main/resources/localization/en.json @@ -7,5 +7,6 @@ "loc.no.elements.found.by.locator": "No elements were found by locator '%1$s'", "loc.elements.were.found.but.not.in.state": "Elements were found by locator '%1$s' but not in desired state %2$s", "loc.elements.found.but.should.not": "No elements should be found by locator '%1$s' in %2$s state", - "loc.search.of.elements.failed": "Search of element by locator '%1$s' failed" + "loc.search.of.elements.failed": "Search of element by locator '%1$s' failed", + "loc.get.page.source.failed": "An exception occurred while tried to save the page source" } \ No newline at end of file diff --git a/src/main/resources/localization/ru.json b/src/main/resources/localization/ru.json index c1eba70..fb95cb7 100644 --- a/src/main/resources/localization/ru.json +++ b/src/main/resources/localization/ru.json @@ -7,5 +7,6 @@ "loc.no.elements.found.by.locator": "Не удалось найти элементов по локатору '%1$s'", "loc.elements.were.found.but.not.in.state": "Удалось найти элементы по локатору '%1$s', но они не в желаемом состоянии %2$s", "loc.elements.found.but.should.not": "Не должно быть найдено элементов по локатору '%1$s' в %2$s состоянии", - "loc.search.of.elements.failed": "Поиск элемента по локатору '%1$s' прошел неудачно" + "loc.search.of.elements.failed": "Поиск элемента по локатору '%1$s' прошел неудачно", + "loc.get.page.source.failed": "Произошла ошибка во время получения разметки страницы" } \ No newline at end of file From eb6f9bfbad2fe3963b67626e27943f01cef79b5e Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Tue, 11 Feb 2020 10:59:09 +0300 Subject: [PATCH 02/21] #14 merged with master and fixed issues --- .../aquality/selenium/core/elements/Element.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index 2b31ea2..cab5526 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -2,9 +2,7 @@ import aquality.selenium.core.applications.IApplication; import aquality.selenium.core.configurations.IElementCacheConfiguration; -import aquality.selenium.core.elements.interfaces.IElement; -import aquality.selenium.core.elements.interfaces.IElementFinder; -import aquality.selenium.core.elements.interfaces.IElementSupplier; +import aquality.selenium.core.elements.interfaces.*; import aquality.selenium.core.localization.ILocalizedLogger; import aquality.selenium.core.logging.Logger; import aquality.selenium.core.utilities.IElementActionRetrier; @@ -48,10 +46,12 @@ protected Element(final By loc, final String name, final ElementState state) { protected abstract ConditionalWait getConditionalWait(); - protected abstract IElementCacheHandler getCache() { + protected IElementCacheHandler getCache() { if (elementCacheHandler == null) { elementCacheHandler = new ElementCacheHandler(locator, elementState, getElementFinder()); } + + return elementCacheHandler; } protected Logger getLogger() { @@ -71,8 +71,8 @@ public String getName() { @Override public IElementStateProvider state() { return getElementCacheConfiguration().isEnabled() - ? (IElementStateProvider) new CachedElementStateProvider(locator, getConditionalWait(), getCache()) - : new ElementStateProvider(locator, getConditionalWait(), getElementFinder()); + ? new CachedElementStateProvider(locator, getConditionalWait(), getCache(), getLocalizedLogger()) + : new DefaultElementStateProvider(locator, getConditionalWait(), getElementFinder()); } @Override @@ -122,7 +122,7 @@ public void click() { @Override public T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state) { - return getElementFactory.findChildElement(this, childLoc, name, supplier, state); + return getElementFactory().findChildElement(this, childLoc, name, supplier, state); } protected T doWithRetry(Supplier action) { From e5355fdae5a3f93ce08e24bb209836e96459ea6e Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Tue, 11 Feb 2020 12:39:56 +0300 Subject: [PATCH 03/21] #14 inherited Custom element from Element --- .../selenium/core/elements/Element.java | 15 ++++- .../core/elements/interfaces/IParent.java | 9 --- .../tests/elements/factory/CustomElement.java | 60 ++++++++++++------- 3 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index cab5526..092638d 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -6,7 +6,7 @@ import aquality.selenium.core.localization.ILocalizedLogger; import aquality.selenium.core.logging.Logger; import aquality.selenium.core.utilities.IElementActionRetrier; -import aquality.selenium.core.waitings.ConditionalWait; +import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriverException; @@ -42,9 +42,9 @@ protected Element(final By loc, final String name, final ElementState state) { protected abstract ILocalizedLogger getLocalizedLogger(); - protected abstract String getElementType(); + protected abstract IConditionalWait getConditionalWait(); - protected abstract ConditionalWait getConditionalWait(); + protected abstract String getElementType(); protected IElementCacheHandler getCache() { if (elementCacheHandler == null) { @@ -58,6 +58,10 @@ protected Logger getLogger() { return Logger.getInstance(); } + protected ElementState getElementState() { + return elementState; + } + @Override public By getLocator() { return locator; @@ -120,6 +124,11 @@ public void click() { doWithRetry(() -> getElement().click()); } + @Override + public T findChildElement(By childLoc, Class clazz, ElementState state) { + return (T) getElementFactory().findChildElement(this, childLoc, clazz, state); + } + @Override public T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state) { return getElementFactory().findChildElement(this, childLoc, name, supplier, state); diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java index bc3948b..5999655 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java @@ -26,15 +26,6 @@ default T findChildElement(By childLoc, Class T findChildElement(By childLoc, Class clazz, ElementState state); - /** - * Find an element in the parent element - * - * @param childLoc Child element locator - * @param supplier required element's supplier - * @param state visibility state of target element - * @return found child element - */ - T findChildElement(By childLoc, IElementSupplier supplier, ElementState state); /** * Finds an element in the parent element * diff --git a/src/test/java/tests/elements/factory/CustomElement.java b/src/test/java/tests/elements/factory/CustomElement.java index 358feac..07d009d 100644 --- a/src/test/java/tests/elements/factory/CustomElement.java +++ b/src/test/java/tests/elements/factory/CustomElement.java @@ -1,50 +1,64 @@ package tests.elements.factory; +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.configurations.IElementCacheConfiguration; +import aquality.selenium.core.elements.Element; import aquality.selenium.core.elements.ElementState; -import aquality.selenium.core.elements.interfaces.IElement; -import aquality.selenium.core.elements.interfaces.IElementSupplier; -import org.apache.commons.lang3.NotImplementedException; +import aquality.selenium.core.elements.interfaces.IElementFactory; +import aquality.selenium.core.elements.interfaces.IElementFinder; +import aquality.selenium.core.localization.ILocalizedLogger; +import aquality.selenium.core.utilities.IElementActionRetrier; +import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; -import org.openqa.selenium.remote.RemoteWebElement; +import tests.application.windowsApp.AqualityServices; -public class CustomElement implements ICustomElement { +public class CustomElement extends Element implements ICustomElement { - private final By locator; - private final String name; - private final ElementState state; + CustomElement(By locator, String name, ElementState state) { + super(locator, name, state); + } + + @Override + protected IApplication getApplication() { + return AqualityServices.getApplication(); + } - protected CustomElement(By locator, String name, ElementState state) { - this.locator = locator; - this.name = name; - this.state = state; + @Override + protected IElementFactory getElementFactory() { + return AqualityServices.get(IElementFactory.class); + } + + @Override + protected IElementFinder getElementFinder() { + return AqualityServices.get(IElementFinder.class); } @Override - public RemoteWebElement getElement(Long timeout) { - return null; + protected IElementCacheConfiguration getElementCacheConfiguration() { + return AqualityServices.get(IElementCacheConfiguration.class); } @Override - public String getName() { - return name; + protected IElementActionRetrier getElementActionRetrier() { + return AqualityServices.get(IElementActionRetrier.class); } @Override - public By getLocator() { - return locator; + protected ILocalizedLogger getLocalizedLogger() { + return AqualityServices.get(ILocalizedLogger.class); } @Override - public T findChildElement(By childLoc, Class clazz, ElementState state) { - throw new NotImplementedException("not implemented in tests"); + protected IConditionalWait getConditionalWait() { + return AqualityServices.get(IConditionalWait.class); } @Override - public T findChildElement(By childLoc, IElementSupplier supplier, ElementState state) { - throw new NotImplementedException("not implemented in tests"); + protected String getElementType() { + return "Custom"; } public ElementState getState() { - return state; + return getElementState(); } } From 6a53ed1225a1aac9557e2624711a5ec675fd1b3a Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Wed, 12 Feb 2020 15:18:54 +0300 Subject: [PATCH 04/21] #14 updated IElement and added tests for this --- .../core/applications/AqualityServices.java | 10 +- .../core/applications/IApplication.java | 4 +- .../selenium/core/elements/Element.java | 4 +- .../core/elements/interfaces/IParent.java | 92 ++++++------- .../windowsApp/CalculatorWindow.java | 37 ------ .../AqualityServicesTests.java | 2 +- .../CustomAqualityServices.java | 6 +- .../CustomDependency.java | 2 +- .../IApplicationTests.java | 14 +- .../ICachedElement.java | 2 +- .../ICustomDependency.java | 2 +- .../TestModule.java | 4 +- .../browser/AqualityServices.java | 2 +- .../browser/BrowserTests.java | 4 +- .../browser/CachedLabel.java | 4 +- .../browser/ChromeApplication.java | 2 +- .../browser/ITheInternetPageTest.java | 2 +- .../windowsApp/ApplicationTests.java | 4 +- .../windowsApp/AqualityServices.java | 2 +- .../windowsApp/CachedButton.java | 4 +- .../windowsApp/CalculatorWindow.java | 51 ++++++++ .../windowsApp/WindowsApplication.java | 2 +- .../configurations/ConfigurationTests.java | 2 +- .../configurations/EnvConfigurationTests.java | 4 +- .../ProfileConfigurationTests.java | 2 +- .../CachedElementStateProviderTests.java | 2 +- .../tests/elements/CachedWebElementTests.java | 8 +- .../elements/CachedWindowsElementTests.java | 24 ++-- .../DefaultElementStateProviderTests.java | 2 +- .../tests/elements/ElementFinderTests.java | 14 +- .../tests/elements/IElementFinderTests.java | 20 +-- .../IWebElementStateProviderTests.java | 4 +- .../elements/RelativeElementFinderTests.java | 6 +- .../java/tests/elements/WebElementTests.java | 123 ++++++++++++++++++ .../tests/elements/WindowsElementTests.java | 108 +++++++++++++++ .../tests/elements/factory/CustomElement.java | 4 +- .../factory/CustomElementFactory.java | 1 + .../elements/factory/CustomWebElement.java | 64 +++++++++ .../elements/factory/ElementFactoryTests.java | 22 ++-- .../elements/factory/IWebCustomElement.java | 6 + .../LocalizationManagerTests.java | 4 +- src/test/java/tests/logger/LoggerTests.java | 1 - .../utilities/CustomSettingsFileTests.java | 4 +- .../utilities/ElementActionRetrierTests.java | 2 +- .../tests/utilities/SettingsFileTests.java | 4 +- .../waitings/BaseConditionalWaitTest.java | 3 +- .../java/theinternet/DynamicControlsForm.java | 26 +++- .../java/theinternet/DynamicLoadingForm.java | 2 +- src/test/java/theinternet/InputsForm.java | 23 ++++ .../java/theinternet/TheInternetPage.java | 3 +- src/test/resources/TestSuite.xml | 8 +- 51 files changed, 551 insertions(+), 201 deletions(-) delete mode 100644 src/test/java/tests/application/windowsApp/CalculatorWindow.java rename src/test/java/tests/{application => applications}/AqualityServicesTests.java (98%) rename src/test/java/tests/{application => applications}/CustomAqualityServices.java (90%) rename src/test/java/tests/{application => applications}/CustomDependency.java (67%) rename src/test/java/tests/{application => applications}/IApplicationTests.java (76%) rename src/test/java/tests/{application => applications}/ICachedElement.java (98%) rename src/test/java/tests/{application => applications}/ICustomDependency.java (54%) rename src/test/java/tests/{application => applications}/TestModule.java (84%) rename src/test/java/tests/{application => applications}/browser/AqualityServices.java (97%) rename src/test/java/tests/{application => applications}/browser/BrowserTests.java (86%) rename src/test/java/tests/{application => applications}/browser/CachedLabel.java (95%) rename src/test/java/tests/{application => applications}/browser/ChromeApplication.java (96%) rename src/test/java/tests/{application => applications}/browser/ITheInternetPageTest.java (96%) rename src/test/java/tests/{application => applications}/windowsApp/ApplicationTests.java (85%) rename src/test/java/tests/{application => applications}/windowsApp/AqualityServices.java (98%) rename src/test/java/tests/{application => applications}/windowsApp/CachedButton.java (94%) create mode 100644 src/test/java/tests/applications/windowsApp/CalculatorWindow.java rename src/test/java/tests/{application => applications}/windowsApp/WindowsApplication.java (97%) create mode 100644 src/test/java/tests/elements/WebElementTests.java create mode 100644 src/test/java/tests/elements/WindowsElementTests.java create mode 100644 src/test/java/tests/elements/factory/CustomWebElement.java create mode 100644 src/test/java/tests/elements/factory/IWebCustomElement.java create mode 100644 src/test/java/theinternet/InputsForm.java diff --git a/src/main/java/aquality/selenium/core/applications/AqualityServices.java b/src/main/java/aquality/selenium/core/applications/AqualityServices.java index 03572d2..3cc435b 100644 --- a/src/main/java/aquality/selenium/core/applications/AqualityServices.java +++ b/src/main/java/aquality/selenium/core/applications/AqualityServices.java @@ -24,14 +24,14 @@ protected > AqualityServices(Provider application } /** - * @return true if the application is already started, false otherwise. + * @return true if the applications is already started, false otherwise. */ protected boolean isAppStarted() { return app != null && app.isStarted(); } /** - * Sets the application instance, saving it to DI container. + * Sets the applications instance, saving it to DI container. * @param application instance to set into container. */ protected void setApp(T application) { @@ -39,9 +39,9 @@ protected void setApp(T application) { } /** - * Returns an existing application or initializes a new one based on passed parameter. - * @param startApplicationFunction function to start the application, where the injector could be used. - * @return started application. + * Returns an existing applications or initializes a new one based on passed parameter. + * @param startApplicationFunction function to start the applications, where the injector could be used. + * @return started applications. */ protected T getApp(Function startApplicationFunction) { if (!isAppStarted()) { diff --git a/src/main/java/aquality/selenium/core/applications/IApplication.java b/src/main/java/aquality/selenium/core/applications/IApplication.java index 6b61943..c171c65 100644 --- a/src/main/java/aquality/selenium/core/applications/IApplication.java +++ b/src/main/java/aquality/selenium/core/applications/IApplication.java @@ -5,7 +5,7 @@ import java.util.concurrent.TimeUnit; /** - * Interface of any application controlled by Selenium WebDriver API + * Interface of any applications controlled by Selenium WebDriver API */ public interface IApplication { @@ -15,7 +15,7 @@ public interface IApplication { RemoteWebDriver getDriver(); /** - * @return Is the application already running or not. + * @return Is the applications already running or not. */ boolean isStarted(); diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index 092638d..ebcbefc 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -125,8 +125,8 @@ public void click() { } @Override - public T findChildElement(By childLoc, Class clazz, ElementState state) { - return (T) getElementFactory().findChildElement(this, childLoc, clazz, state); + public T findChildElement(By childLoc, String name, Class clazz, ElementState state) { + return getElementFactory().findChildElement(this, childLoc, name, clazz, state); } @Override diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java index 5999655..58857a3 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java @@ -8,97 +8,85 @@ public interface IParent { /** * Find an element in the parent element * - * @param childLoc Child element locator - * @param clazz class or interface of the element to be obtained - * @return found child element - */ - default T findChildElement(By childLoc, Class clazz){ - return findChildElement(childLoc, clazz, ElementState.DISPLAYED); - } - - /** - * Find an element in the parent element - * - * @param childLoc Child element locator - * @param clazz class or interface of the element to be obtained - * @param state visibility state of target element + * @param childLoc child element locator + * @param name output name in logs + * @param clazz class or interface of the element to be obtained + * @param state visibility state of target element + * @param the type of the element to be obtained * @return found child element */ - T findChildElement(By childLoc, Class clazz, ElementState state); + T findChildElement(By childLoc, String name, Class clazz, ElementState state); /** - * Finds an element in the parent element + * Find an element in the parent element with DISPLAYED state * * @param childLoc child element locator - * @return child element + * @param name output name in logs + * @param clazz class or interface of the element to be obtained + * @param the type of the element to be obtained + * @return found child element */ - default T findChildElement(By childLoc) { - return findChildElement(childLoc, null, null, null); + default T findChildElement(By childLoc, String name, Class clazz) { + return findChildElement(childLoc, name, clazz, ElementState.DISPLAYED); } /** - * Finds an element in the parent element + * Find an element in the parent element * * @param childLoc child element locator - * @param name output name in logs - * @return child element + * @param clazz class or interface of the element to be obtained + * @param state visibility state of target element + * @param the type of the element to be obtained + * @return found child element */ - default T findChildElement(By childLoc, String name) { - return findChildElement(childLoc, name, null, null); + default T findChildElement(By childLoc, Class clazz, ElementState state) { + return findChildElement(childLoc, null, clazz, state); } /** - * Finds an element in the parent element + * Find an element in the parent element with DISPLAYED state * - * @param childLoc Child element locator - * @param state visibility state of target element - * @return child element + * @param childLoc child element locator + * @param clazz class or interface of the element to be obtained + * @param the type of the element to be obtained + * @return found child element */ - default T findChildElement(By childLoc, ElementState state) { - return findChildElement(childLoc, null, null, state); + default T findChildElement(By childLoc, Class clazz) { + return findChildElement(childLoc, null, clazz, ElementState.DISPLAYED); } /** * Finds an element in the parent element * * @param childLoc Child element locator + * @param name output name in logs * @param supplier required element's supplier + * @param state visibility state of target element + * @param the type of the element to be obtained * @return found child element */ - default T findChildElement(By childLoc, IElementSupplier supplier) { - return findChildElement(childLoc, null, supplier, null); - } + T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state); /** - * Finds an element in the parent element + * Find an element in the parent element with DISPLAYED state * * @param childLoc child element locator * @param name output name in logs * @param supplier required element's supplier + * @param the type of the element to be obtained * @return found child element */ default T findChildElement(By childLoc, String name, IElementSupplier supplier) { - return findChildElement(childLoc, name, supplier, null); + return findChildElement(childLoc, name, supplier, ElementState.DISPLAYED); } /** * Finds an element in the parent element * * @param childLoc child element locator - * @param name output name in logs - * @param state visibility state of target element - * @return found child element - */ - default T findChildElement(By childLoc, String name, ElementState state) { - return findChildElement(childLoc, name, null, state); - } - - /** - * Finds an element in the parent element - * - * @param childLoc Child element locator * @param supplier required element's supplier * @param state visibility state of target element + * @param the type of the element to be obtained * @return found child element */ default T findChildElement(By childLoc, IElementSupplier supplier, ElementState state) { @@ -106,14 +94,14 @@ default T findChildElement(By childLoc, IElementSupplier } /** - * Finds an element in the parent element + * Find an element in the parent element with DISPLAYED state * - * @param childLoc Child element locator - * @param name output name in logs + * @param childLoc child element locator * @param supplier required element's supplier - * @param state visibility state of target element * @param the type of the element to be obtained * @return found child element */ - T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state); + default T findChildElement(By childLoc, IElementSupplier supplier) { + return findChildElement(childLoc, null, supplier, ElementState.DISPLAYED); + } } diff --git a/src/test/java/tests/application/windowsApp/CalculatorWindow.java b/src/test/java/tests/application/windowsApp/CalculatorWindow.java deleted file mode 100644 index 26a6cfe..0000000 --- a/src/test/java/tests/application/windowsApp/CalculatorWindow.java +++ /dev/null @@ -1,37 +0,0 @@ -package tests.application.windowsApp; - -import io.appium.java_client.MobileBy; -import org.openqa.selenium.By; - -public class CalculatorWindow { - private CalculatorWindow(){ - } - - public static By getWindowLocator() { - return By.tagName("Window"); - } - - public static By getOneButton() { - return By.name("1"); - } - - public static By getTwoButton() { - return By.name("2"); - } - - public static By getPlusButton() { - return By.name("+"); - } - - public static By getEqualsButton() { - return By.name("="); - } - - public static By getEqualsButtonByXPath() { - return By.xpath("//*[@Name='=']"); - } - - public static By getResultsLabel() { - return MobileBy.AccessibilityId("48"); - } -} diff --git a/src/test/java/tests/application/AqualityServicesTests.java b/src/test/java/tests/applications/AqualityServicesTests.java similarity index 98% rename from src/test/java/tests/application/AqualityServicesTests.java rename to src/test/java/tests/applications/AqualityServicesTests.java index 68b5bb6..9b7361a 100644 --- a/src/test/java/tests/application/AqualityServicesTests.java +++ b/src/test/java/tests/applications/AqualityServicesTests.java @@ -1,4 +1,4 @@ -package tests.application; +package tests.applications; import aquality.selenium.core.applications.AqualityModule; import aquality.selenium.core.logging.Logger; diff --git a/src/test/java/tests/application/CustomAqualityServices.java b/src/test/java/tests/applications/CustomAqualityServices.java similarity index 90% rename from src/test/java/tests/application/CustomAqualityServices.java rename to src/test/java/tests/applications/CustomAqualityServices.java index b34842f..46aab30 100644 --- a/src/test/java/tests/application/CustomAqualityServices.java +++ b/src/test/java/tests/applications/CustomAqualityServices.java @@ -1,9 +1,9 @@ -package tests.application; +package tests.applications; import aquality.selenium.core.applications.AqualityModule; import aquality.selenium.core.applications.AqualityServices; import com.google.inject.Injector; -import tests.application.browser.ChromeApplication; +import tests.applications.browser.ChromeApplication; public class CustomAqualityServices extends AqualityServices { private static final ThreadLocal INSTANCE_CONTAINER = ThreadLocal.withInitial(CustomAqualityServices::new); @@ -21,7 +21,7 @@ private static CustomAqualityServices getInstance() { } public static ChromeApplication getApplication() { - return getInstance().getApp(injector -> tests.application.browser.AqualityServices.getApplication()); + return getInstance().getApp(injector -> tests.applications.browser.AqualityServices.getApplication()); } public static Injector getServiceProvider() { diff --git a/src/test/java/tests/application/CustomDependency.java b/src/test/java/tests/applications/CustomDependency.java similarity index 67% rename from src/test/java/tests/application/CustomDependency.java rename to src/test/java/tests/applications/CustomDependency.java index 22711be..661ba17 100644 --- a/src/test/java/tests/application/CustomDependency.java +++ b/src/test/java/tests/applications/CustomDependency.java @@ -1,4 +1,4 @@ -package tests.application; +package tests.applications; class CustomDependency implements ICustomDependency { } diff --git a/src/test/java/tests/application/IApplicationTests.java b/src/test/java/tests/applications/IApplicationTests.java similarity index 76% rename from src/test/java/tests/application/IApplicationTests.java rename to src/test/java/tests/applications/IApplicationTests.java index f204de3..0590de3 100644 --- a/src/test/java/tests/application/IApplicationTests.java +++ b/src/test/java/tests/applications/IApplicationTests.java @@ -1,4 +1,4 @@ -package tests.application; +package tests.applications; import aquality.selenium.core.applications.IApplication; import com.google.inject.Injector; @@ -21,7 +21,7 @@ default void testShouldBePossibleToGetApplication() { @Test default void testShouldBePossibleToGetDriver() { - Assert.assertNotNull(getApplication().getDriver(), "should be possible get driver from the application"); + Assert.assertNotNull(getApplication().getDriver(), "should be possible get driver from the applications"); } @Test @@ -41,16 +41,16 @@ default void checkImplicitWaitSetting(int valueInSeconds) { @Test default void testShouldBePossibleToDefineIsStarted() { Assert.assertFalse(isApplicationStarted(), - "application should not be started before getting"); + "applications should not be started before getting"); IApplication application = getApplication(); Assert.assertTrue(application.isStarted(), - "application should be started when got it from the aquality services"); + "applications should be started when got it from the aquality services"); Assert.assertTrue(isApplicationStarted(), - "application should be started when check it's state from the aquality services"); + "applications should be started when check it's state from the aquality services"); application.getDriver().quit(); Assert.assertFalse(application.isStarted(), - "application should not be started after quit"); + "applications should not be started after quit"); Assert.assertFalse(isApplicationStarted(), - "application should not be started when check it's state from the aquality services after quit"); + "applications should not be started when check it's state from the aquality services after quit"); } } diff --git a/src/test/java/tests/application/ICachedElement.java b/src/test/java/tests/applications/ICachedElement.java similarity index 98% rename from src/test/java/tests/application/ICachedElement.java rename to src/test/java/tests/applications/ICachedElement.java index b14f39e..bad5c0a 100644 --- a/src/test/java/tests/application/ICachedElement.java +++ b/src/test/java/tests/applications/ICachedElement.java @@ -1,4 +1,4 @@ -package tests.application; +package tests.applications; import aquality.selenium.core.elements.CachedElementStateProvider; import aquality.selenium.core.elements.ElementCacheHandler; diff --git a/src/test/java/tests/application/ICustomDependency.java b/src/test/java/tests/applications/ICustomDependency.java similarity index 54% rename from src/test/java/tests/application/ICustomDependency.java rename to src/test/java/tests/applications/ICustomDependency.java index 8227f68..3630efb 100644 --- a/src/test/java/tests/application/ICustomDependency.java +++ b/src/test/java/tests/applications/ICustomDependency.java @@ -1,4 +1,4 @@ -package tests.application; +package tests.applications; interface ICustomDependency { } diff --git a/src/test/java/tests/application/TestModule.java b/src/test/java/tests/applications/TestModule.java similarity index 84% rename from src/test/java/tests/application/TestModule.java rename to src/test/java/tests/applications/TestModule.java index a345669..378e5c9 100644 --- a/src/test/java/tests/application/TestModule.java +++ b/src/test/java/tests/applications/TestModule.java @@ -1,8 +1,8 @@ -package tests.application; +package tests.applications; import aquality.selenium.core.applications.AqualityModule; import com.google.inject.Provider; -import tests.application.browser.ChromeApplication; +import tests.applications.browser.ChromeApplication; public class TestModule extends AqualityModule { public TestModule(Provider applicationProvider) { diff --git a/src/test/java/tests/application/browser/AqualityServices.java b/src/test/java/tests/applications/browser/AqualityServices.java similarity index 97% rename from src/test/java/tests/application/browser/AqualityServices.java rename to src/test/java/tests/applications/browser/AqualityServices.java index 0eb1b1e..27324bc 100644 --- a/src/test/java/tests/application/browser/AqualityServices.java +++ b/src/test/java/tests/applications/browser/AqualityServices.java @@ -1,4 +1,4 @@ -package tests.application.browser; +package tests.applications.browser; import com.google.inject.Injector; import io.github.bonigarcia.wdm.WebDriverManager; diff --git a/src/test/java/tests/application/browser/BrowserTests.java b/src/test/java/tests/applications/browser/BrowserTests.java similarity index 86% rename from src/test/java/tests/application/browser/BrowserTests.java rename to src/test/java/tests/applications/browser/BrowserTests.java index 0b731c0..ec51fe8 100644 --- a/src/test/java/tests/application/browser/BrowserTests.java +++ b/src/test/java/tests/applications/browser/BrowserTests.java @@ -1,8 +1,8 @@ -package tests.application.browser; +package tests.applications.browser; import aquality.selenium.core.applications.IApplication; import com.google.inject.Injector; -import tests.application.IApplicationTests; +import tests.applications.IApplicationTests; public class BrowserTests implements IApplicationTests { @Override diff --git a/src/test/java/tests/application/browser/CachedLabel.java b/src/test/java/tests/applications/browser/CachedLabel.java similarity index 95% rename from src/test/java/tests/application/browser/CachedLabel.java rename to src/test/java/tests/applications/browser/CachedLabel.java index a53bae3..9b92dcb 100644 --- a/src/test/java/tests/application/browser/CachedLabel.java +++ b/src/test/java/tests/applications/browser/CachedLabel.java @@ -1,4 +1,4 @@ -package tests.application.browser; +package tests.applications.browser; import aquality.selenium.core.elements.ElementState; import aquality.selenium.core.elements.interfaces.IElementCacheHandler; @@ -6,7 +6,7 @@ import aquality.selenium.core.localization.ILocalizedLogger; import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; -import tests.application.ICachedElement; +import tests.applications.ICachedElement; public class CachedLabel implements ICachedElement { private final By locator; diff --git a/src/test/java/tests/application/browser/ChromeApplication.java b/src/test/java/tests/applications/browser/ChromeApplication.java similarity index 96% rename from src/test/java/tests/application/browser/ChromeApplication.java rename to src/test/java/tests/applications/browser/ChromeApplication.java index ec787df..950c139 100644 --- a/src/test/java/tests/application/browser/ChromeApplication.java +++ b/src/test/java/tests/applications/browser/ChromeApplication.java @@ -1,4 +1,4 @@ -package tests.application.browser; +package tests.applications.browser; import aquality.selenium.core.applications.IApplication; import org.openqa.selenium.chrome.ChromeDriver; diff --git a/src/test/java/tests/application/browser/ITheInternetPageTest.java b/src/test/java/tests/applications/browser/ITheInternetPageTest.java similarity index 96% rename from src/test/java/tests/application/browser/ITheInternetPageTest.java rename to src/test/java/tests/applications/browser/ITheInternetPageTest.java index 97f7447..0084b94 100644 --- a/src/test/java/tests/application/browser/ITheInternetPageTest.java +++ b/src/test/java/tests/applications/browser/ITheInternetPageTest.java @@ -1,4 +1,4 @@ -package tests.application.browser; +package tests.applications.browser; import aquality.selenium.core.applications.IApplication; import org.openqa.selenium.Dimension; diff --git a/src/test/java/tests/application/windowsApp/ApplicationTests.java b/src/test/java/tests/applications/windowsApp/ApplicationTests.java similarity index 85% rename from src/test/java/tests/application/windowsApp/ApplicationTests.java rename to src/test/java/tests/applications/windowsApp/ApplicationTests.java index 478a754..1d91887 100644 --- a/src/test/java/tests/application/windowsApp/ApplicationTests.java +++ b/src/test/java/tests/applications/windowsApp/ApplicationTests.java @@ -1,8 +1,8 @@ -package tests.application.windowsApp; +package tests.applications.windowsApp; import aquality.selenium.core.applications.IApplication; import com.google.inject.Injector; -import tests.application.IApplicationTests; +import tests.applications.IApplicationTests; public class ApplicationTests implements IApplicationTests { diff --git a/src/test/java/tests/application/windowsApp/AqualityServices.java b/src/test/java/tests/applications/windowsApp/AqualityServices.java similarity index 98% rename from src/test/java/tests/application/windowsApp/AqualityServices.java rename to src/test/java/tests/applications/windowsApp/AqualityServices.java index eca4368..b7bd404 100644 --- a/src/test/java/tests/application/windowsApp/AqualityServices.java +++ b/src/test/java/tests/applications/windowsApp/AqualityServices.java @@ -1,4 +1,4 @@ -package tests.application.windowsApp; +package tests.applications.windowsApp; import aquality.selenium.core.logging.Logger; import com.google.inject.Injector; diff --git a/src/test/java/tests/application/windowsApp/CachedButton.java b/src/test/java/tests/applications/windowsApp/CachedButton.java similarity index 94% rename from src/test/java/tests/application/windowsApp/CachedButton.java rename to src/test/java/tests/applications/windowsApp/CachedButton.java index 668d6cd..8ae0b88 100644 --- a/src/test/java/tests/application/windowsApp/CachedButton.java +++ b/src/test/java/tests/applications/windowsApp/CachedButton.java @@ -1,4 +1,4 @@ -package tests.application.windowsApp; +package tests.applications.windowsApp; import aquality.selenium.core.elements.ElementState; import aquality.selenium.core.elements.interfaces.IElementCacheHandler; @@ -6,7 +6,7 @@ import aquality.selenium.core.localization.ILocalizedLogger; import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; -import tests.application.ICachedElement; +import tests.applications.ICachedElement; public class CachedButton implements ICachedElement { private final By locator; diff --git a/src/test/java/tests/applications/windowsApp/CalculatorWindow.java b/src/test/java/tests/applications/windowsApp/CalculatorWindow.java new file mode 100644 index 0000000..9a49340 --- /dev/null +++ b/src/test/java/tests/applications/windowsApp/CalculatorWindow.java @@ -0,0 +1,51 @@ +package tests.applications.windowsApp; + +import aquality.selenium.core.elements.ElementState; +import io.appium.java_client.MobileBy; +import org.openqa.selenium.By; +import tests.elements.factory.CustomElement; + +public class CalculatorWindow { + private CalculatorWindow(){ + } + + public static By getWindowLocator() { + return By.tagName("Window"); + } + + public static CustomElement getWindowLabel() { + return new CustomElement(getWindowLocator(), "Window", ElementState.DISPLAYED); + } + + public static By getOneButtonLoc() { + return By.name("1"); + } + + public static CustomElement getOneButton() { + return new CustomElement(getOneButtonLoc(), "1", ElementState.DISPLAYED); + } + + public static By getTwoButtonLoc() { + return By.name("2"); + } + + public static By getPlusButtonLoc() { + return By.name("+"); + } + + public static By getEqualsButtonLoc() { + return By.name("="); + } + + public static By getEqualsButtonByXPath() { + return By.xpath("//*[@Name='=']"); + } + + public static By getResultsLabelLoc() { + return MobileBy.AccessibilityId("48"); + } + + public static CustomElement getLeftValueTextBox() { + return new CustomElement(MobileBy.xpath("//*[@AutomationId='50']"), "Left value", ElementState.DISPLAYED); + } +} diff --git a/src/test/java/tests/application/windowsApp/WindowsApplication.java b/src/test/java/tests/applications/windowsApp/WindowsApplication.java similarity index 97% rename from src/test/java/tests/application/windowsApp/WindowsApplication.java rename to src/test/java/tests/applications/windowsApp/WindowsApplication.java index 84b38d2..0971e29 100644 --- a/src/test/java/tests/application/windowsApp/WindowsApplication.java +++ b/src/test/java/tests/applications/windowsApp/WindowsApplication.java @@ -1,4 +1,4 @@ -package tests.application.windowsApp; +package tests.applications.windowsApp; import aquality.selenium.core.applications.IApplication; import io.appium.java_client.windows.WindowsDriver; diff --git a/src/test/java/tests/configurations/ConfigurationTests.java b/src/test/java/tests/configurations/ConfigurationTests.java index a259ced..80d1a9a 100644 --- a/src/test/java/tests/configurations/ConfigurationTests.java +++ b/src/test/java/tests/configurations/ConfigurationTests.java @@ -3,7 +3,7 @@ import aquality.selenium.core.configurations.*; import aquality.selenium.core.utilities.ISettingsFile; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; +import tests.applications.CustomAqualityServices; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; diff --git a/src/test/java/tests/configurations/EnvConfigurationTests.java b/src/test/java/tests/configurations/EnvConfigurationTests.java index cab602d..63dcf46 100644 --- a/src/test/java/tests/configurations/EnvConfigurationTests.java +++ b/src/test/java/tests/configurations/EnvConfigurationTests.java @@ -7,8 +7,8 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; -import tests.application.TestModule; +import tests.applications.CustomAqualityServices; +import tests.applications.TestModule; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; diff --git a/src/test/java/tests/configurations/ProfileConfigurationTests.java b/src/test/java/tests/configurations/ProfileConfigurationTests.java index 4b81c44..8ed61b0 100644 --- a/src/test/java/tests/configurations/ProfileConfigurationTests.java +++ b/src/test/java/tests/configurations/ProfileConfigurationTests.java @@ -5,7 +5,7 @@ import aquality.selenium.core.utilities.ISettingsFile; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; +import tests.applications.CustomAqualityServices; import static org.testng.Assert.assertEquals; diff --git a/src/test/java/tests/elements/CachedElementStateProviderTests.java b/src/test/java/tests/elements/CachedElementStateProviderTests.java index dfe5622..d01277f 100644 --- a/src/test/java/tests/elements/CachedElementStateProviderTests.java +++ b/src/test/java/tests/elements/CachedElementStateProviderTests.java @@ -8,7 +8,7 @@ import aquality.selenium.core.localization.ILocalizedLogger; import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; -import tests.application.browser.AqualityServices; +import tests.applications.browser.AqualityServices; public class CachedElementStateProviderTests implements IWebElementStateProviderTests { diff --git a/src/test/java/tests/elements/CachedWebElementTests.java b/src/test/java/tests/elements/CachedWebElementTests.java index b9eccfa..a190442 100644 --- a/src/test/java/tests/elements/CachedWebElementTests.java +++ b/src/test/java/tests/elements/CachedWebElementTests.java @@ -4,9 +4,9 @@ import aquality.selenium.core.waitings.IConditionalWait; import org.testng.Assert; import org.testng.annotations.Test; -import tests.application.browser.AqualityServices; -import tests.application.browser.CachedLabel; -import tests.application.browser.ITheInternetPageTest; +import tests.applications.browser.AqualityServices; +import tests.applications.browser.CachedLabel; +import tests.applications.browser.ITheInternetPageTest; import theinternet.DynamicControlsForm; import theinternet.DynamicLoadingForm; import theinternet.TheInternetPage; @@ -67,7 +67,7 @@ public void testShouldBeStaleWhenBecameInvisible() { @Test public void testShouldRefreshElementWhenItIsStale() { openDynamicControls(); - CachedLabel example = DynamicControlsForm.getContentLabel(); + CachedLabel example = DynamicControlsForm.getContentCachedLabel(); String exampleToString = example.getElement().getId(); getBrowser().getDriver().navigate().refresh(); Assert.assertTrue(example.cache().isRefreshNeeded(), "refresh should be needed when refreshed the page"); diff --git a/src/test/java/tests/elements/CachedWindowsElementTests.java b/src/test/java/tests/elements/CachedWindowsElementTests.java index 28ac2fb..693728a 100644 --- a/src/test/java/tests/elements/CachedWindowsElementTests.java +++ b/src/test/java/tests/elements/CachedWindowsElementTests.java @@ -5,9 +5,9 @@ import org.testng.Assert; import org.testng.annotations.Test; import tests.ITestWithApplication; -import tests.application.windowsApp.AqualityServices; -import tests.application.windowsApp.CachedButton; -import tests.application.windowsApp.CalculatorWindow; +import tests.applications.windowsApp.AqualityServices; +import tests.applications.windowsApp.CachedButton; +import tests.applications.windowsApp.CalculatorWindow; import java.util.function.Predicate; @@ -25,17 +25,17 @@ public boolean isApplicationStarted() { @Test public void testShouldWorkWithCalculatorWithCachedElement() { - new CachedButton(CalculatorWindow.getOneButton()).click(); - new CachedButton(CalculatorWindow.getPlusButton()).click(); - new CachedButton(CalculatorWindow.getOneButton()).click(); - new CachedButton(CalculatorWindow.getEqualsButton()).click(); - String result = new CachedButton(CalculatorWindow.getResultsLabel()).getElement().getText(); + new CachedButton(CalculatorWindow.getOneButtonLoc()).click(); + new CachedButton(CalculatorWindow.getPlusButtonLoc()).click(); + new CachedButton(CalculatorWindow.getOneButtonLoc()).click(); + new CachedButton(CalculatorWindow.getEqualsButtonLoc()).click(); + String result = new CachedButton(CalculatorWindow.getResultsLabelLoc()).getElement().getText(); Assert.assertTrue(result.contains("2")); } @Test public void testShouldReturnSameElementAfterInteraction() { - CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButton()); + CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButtonLoc()); String initialElement = oneButton.getElement().getId(); oneButton.click(); String resultElement = oneButton.getElement().getId(); @@ -44,7 +44,7 @@ public void testShouldReturnSameElementAfterInteraction() { @Test public void testShouldReturnSameElementAfterGetState() { - CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButton()); + CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButtonLoc()); String initialElement = oneButton.getElement().getId(); oneButton.state().waitForClickable(); String resultElement = oneButton.getElement().getId(); @@ -53,7 +53,7 @@ public void testShouldReturnSameElementAfterGetState() { @Test public void testShouldReturnNewElementWhenWindowIsReopened() { - CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButton()); + CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButtonLoc()); String initialElement = oneButton.getElement().getId(); getApplication().getDriver().quit(); oneButton.state().waitForClickable(); @@ -72,7 +72,7 @@ public void testShouldReturnCorrectStateAndReopenApplicationWhenWindowIsClosed(P } private void assertStateConditionAfterQuit(Predicate stateCondition, boolean expectedValue, boolean shouldAppRestart){ - CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButton()); + CachedButton oneButton = new CachedButton(CalculatorWindow.getOneButtonLoc()); oneButton.getElement(); getApplication().getDriver().quit(); Assert.assertEquals(stateCondition.test(oneButton.state()), expectedValue, diff --git a/src/test/java/tests/elements/DefaultElementStateProviderTests.java b/src/test/java/tests/elements/DefaultElementStateProviderTests.java index 2694c6d..c759811 100644 --- a/src/test/java/tests/elements/DefaultElementStateProviderTests.java +++ b/src/test/java/tests/elements/DefaultElementStateProviderTests.java @@ -5,7 +5,7 @@ import aquality.selenium.core.elements.interfaces.IElementStateProvider; import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; -import tests.application.browser.AqualityServices; +import tests.applications.browser.AqualityServices; public class DefaultElementStateProviderTests implements IWebElementStateProviderTests { diff --git a/src/test/java/tests/elements/ElementFinderTests.java b/src/test/java/tests/elements/ElementFinderTests.java index 8afa9fc..b629f5e 100644 --- a/src/test/java/tests/elements/ElementFinderTests.java +++ b/src/test/java/tests/elements/ElementFinderTests.java @@ -4,8 +4,8 @@ import aquality.selenium.core.waitings.IConditionalWait; import org.testng.Assert; import org.testng.annotations.Test; -import tests.application.windowsApp.AqualityServices; -import tests.application.windowsApp.CalculatorWindow; +import tests.applications.windowsApp.AqualityServices; +import tests.applications.windowsApp.CalculatorWindow; import java.util.function.BooleanSupplier; @@ -19,14 +19,14 @@ public IElementFinder getElementFinder() { @Test public void shouldBePossibleToUseConditionalWaitWithElementFinder() { BooleanSupplier elementFinderCondition = () -> - getElementFinder().findElement(CalculatorWindow.getResultsLabel()).getText().contains("3"); + getElementFinder().findElement(CalculatorWindow.getResultsLabelLoc()).getText().contains("3"); Assert.assertFalse(elementFinderCondition.getAsBoolean(), "condition should not match before actions"); Assert.assertTrue(AqualityServices.get(IConditionalWait.class) .waitFor(driver -> { - driver.findElement(CalculatorWindow.getTwoButton()).click(); - driver.findElement(CalculatorWindow.getPlusButton()).click(); - driver.findElement(CalculatorWindow.getOneButton()).click(); - driver.findElement(CalculatorWindow.getEqualsButton()).click(); + driver.findElement(CalculatorWindow.getTwoButtonLoc()).click(); + driver.findElement(CalculatorWindow.getPlusButtonLoc()).click(); + driver.findElement(CalculatorWindow.getOneButtonLoc()).click(); + driver.findElement(CalculatorWindow.getEqualsButtonLoc()).click(); return elementFinderCondition.getAsBoolean(); })); } diff --git a/src/test/java/tests/elements/IElementFinderTests.java b/src/test/java/tests/elements/IElementFinderTests.java index c7f8979..c8c84c2 100644 --- a/src/test/java/tests/elements/IElementFinderTests.java +++ b/src/test/java/tests/elements/IElementFinderTests.java @@ -10,8 +10,8 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import tests.ITestWithApplication; -import tests.application.windowsApp.AqualityServices; -import tests.application.windowsApp.CalculatorWindow; +import tests.applications.windowsApp.AqualityServices; +import tests.applications.windowsApp.CalculatorWindow; public interface IElementFinderTests extends ITestWithApplication { IElementFinder getElementFinder(); @@ -44,52 +44,52 @@ default By getAbsentLocator() { @Test() default void shouldFindMultipleElementsInDefaultStateWithCustomTimeout() { Assert.assertTrue(getElementFinder() - .findElements(CalculatorWindow.getEqualsButton(), getCustomTimeout()) + .findElements(CalculatorWindow.getEqualsButtonLoc(), getCustomTimeout()) .size() > 1); } @Test(dataProvider = "elementStates") default void shouldFindMultipleElements(ElementState state) { Assert.assertTrue(getElementFinder() - .findElements(CalculatorWindow.getEqualsButton(), state) + .findElements(CalculatorWindow.getEqualsButtonLoc(), state) .size() > 1); } @Test(dataProvider = "elementStates") default void shouldFindSingleElementViaFindElements(ElementState state) { Assert.assertEquals(getElementFinder() - .findElements(CalculatorWindow.getOneButton(), state, getCustomTimeout()) + .findElements(CalculatorWindow.getOneButtonLoc(), state, getCustomTimeout()) .size(), 1); } @Test(dataProvider = "elementStates") default void shouldFindSingleElement(ElementState state) { Assert.assertNotNull(getElementFinder() - .findElement(CalculatorWindow.getOneButton(), state)); + .findElement(CalculatorWindow.getOneButtonLoc(), state)); } @Test(dataProvider = "elementStates") default void shouldFindSingleElementWithCustomTimeout(ElementState state) { Assert.assertNotNull(getElementFinder() - .findElement(CalculatorWindow.getOneButton(), state, getCustomTimeout())); + .findElement(CalculatorWindow.getOneButtonLoc(), state, getCustomTimeout())); } @Test default void shouldFindSingleElementByPredicate() { Assert.assertNotNull(getElementFinder() - .findElement(CalculatorWindow.getOneButton(), WebElement::isEnabled)); + .findElement(CalculatorWindow.getOneButtonLoc(), WebElement::isEnabled)); } @Test default void shouldFindMultipleElementsByPredicate() { Assert.assertTrue(getElementFinder() - .findElements(CalculatorWindow.getEqualsButton(), WebElement::isEnabled).size() > 1); + .findElements(CalculatorWindow.getEqualsButtonLoc(), WebElement::isEnabled).size() > 1); } @Test default void shouldFindSingleElementByPredicateWithCustomTimeout() { Assert.assertNotNull(getElementFinder() - .findElement(CalculatorWindow.getOneButton(), WebElement::isEnabled, getCustomTimeout())); + .findElement(CalculatorWindow.getOneButtonLoc(), WebElement::isEnabled, getCustomTimeout())); } @Test(dataProvider = "elementStates") diff --git a/src/test/java/tests/elements/IWebElementStateProviderTests.java b/src/test/java/tests/elements/IWebElementStateProviderTests.java index cf2b078..4614d56 100644 --- a/src/test/java/tests/elements/IWebElementStateProviderTests.java +++ b/src/test/java/tests/elements/IWebElementStateProviderTests.java @@ -6,8 +6,8 @@ import org.openqa.selenium.NoSuchElementException; import org.testng.Assert; import org.testng.annotations.Test; -import tests.application.browser.AqualityServices; -import tests.application.browser.ITheInternetPageTest; +import tests.applications.browser.AqualityServices; +import tests.applications.browser.ITheInternetPageTest; import theinternet.DynamicControlsForm; import theinternet.DynamicLoadingForm; import theinternet.TheInternetPage; diff --git a/src/test/java/tests/elements/RelativeElementFinderTests.java b/src/test/java/tests/elements/RelativeElementFinderTests.java index db0dec2..953b652 100644 --- a/src/test/java/tests/elements/RelativeElementFinderTests.java +++ b/src/test/java/tests/elements/RelativeElementFinderTests.java @@ -6,8 +6,8 @@ import aquality.selenium.core.waitings.IConditionalWait; import org.testng.Assert; import org.testng.annotations.Test; -import tests.application.windowsApp.AqualityServices; -import tests.application.windowsApp.CalculatorWindow; +import tests.applications.windowsApp.AqualityServices; +import tests.applications.windowsApp.CalculatorWindow; public class RelativeElementFinderTests implements IElementFinderTests { @@ -21,6 +21,6 @@ public IElementFinder getElementFinder() { @Test public void shouldFindChildElements() { - Assert.assertNotNull(getElementFinder().findElement(CalculatorWindow.getOneButton())); + Assert.assertNotNull(getElementFinder().findElement(CalculatorWindow.getOneButtonLoc())); } } diff --git a/src/test/java/tests/elements/WebElementTests.java b/src/test/java/tests/elements/WebElementTests.java new file mode 100644 index 0000000..4dc7819 --- /dev/null +++ b/src/test/java/tests/elements/WebElementTests.java @@ -0,0 +1,123 @@ +package tests.elements; + +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.elements.ElementState; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.RemoteWebElement; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import tests.ITestWithApplication; +import tests.applications.browser.AqualityServices; +import tests.elements.factory.CustomWebElement; +import theinternet.DynamicControlsForm; +import theinternet.InputsForm; +import theinternet.TheInternetPage; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +public class WebElementTests implements ITestWithApplication { + + private static final By LOCATOR = By.xpath("//id"); + private static final String ELEMENT_NAME = "CustomElement"; + private static final ElementState ELEMENT_STATE = ElementState.EXISTS_IN_ANY_STATE; + private static final CustomWebElement CUSTOM_WEB_ELEMENT = new CustomWebElement(LOCATOR, ELEMENT_NAME, ELEMENT_STATE); + + @Override + public IApplication getApplication() { + return AqualityServices.getApplication(); + } + + @Override + public boolean isApplicationStarted() { + return AqualityServices.isApplicationStarted(); + } + + @Test + public void testShouldBePossibleToGetLocator() { + Assert.assertEquals(CUSTOM_WEB_ELEMENT.getLocator(), LOCATOR); + } + + @Test + public void testShouldBePossibleToGetElementName() { + Assert.assertEquals(CUSTOM_WEB_ELEMENT.getName(), ELEMENT_NAME); + } + + @Test + public void testShouldBePossibleToGetState() { + Assert.assertNotNull(CUSTOM_WEB_ELEMENT.state(), "State provider should not be null"); + } + + @Test + public void testShouldBePossibleToGetbElement() { + getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); + RemoteWebElement element = DynamicControlsForm.getEnableButton().getElement(); + Assert.assertNotNull(element, "RemoteWebElement should not be null"); + } + + @Test + public void testShouldBePossibleToGetElementWithCustomTimeout() { + getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); + RemoteWebElement element = DynamicControlsForm.getEnableButton().getElement(1L); + Assert.assertNotNull(element, "RemoteWebElement should not be null"); + } + + @Test + public void testShouldBePossibleToClickOnElement() { + getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); + DynamicControlsForm.getEnableButton().click(); + Assert.assertTrue(DynamicControlsForm.getLoadingLabel().state().isDisplayed(), "Loading element should be displayed after click"); + } + + @Test + public void testShouldBePossibleToSendKeysToElement() { + getApplication().getDriver().navigate().to(TheInternetPage.INPUTS.getAddress()); + String keys = "12345"; + InputsForm.getInputTextBox().sendKeys(keys); + Assert.assertEquals(InputsForm.getInputTextBox().getAttribute("value"), keys, "Text should be entered"); + } + + @Test + public void testShouldBePossibleToGetAttributeFromElement() { + getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); + String type = DynamicControlsForm.getRemoveButton().getAttribute("type"); + Assert.assertEquals(type, "button", "Attribute should be got successfully"); + } + + @Test + public void testShouldBePossibleToGetTextFromElement() { + getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); + String text = DynamicControlsForm.getRemoveButton().getText(); + Assert.assertEquals(text, "Remove", "Text should be got successfully"); + } + + @Test(dataProvider = "getChildElementFunctions") + public void testShouldBePossibleToFindChildElement(Callable findChildElement) { + getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); + try { + CustomWebElement element = findChildElement.call(); + Assert.assertNotNull(element, "Child element should be found"); + Assert.assertTrue(element.state().isDisplayed(), "Child element should be displayed"); + } catch (Exception e) { + Assert.fail("Cannot find child element", e); + } + } + + @DataProvider(name = "getChildElementFunctions", parallel = true) + public Object[] getChildElementFunctions() { + String name = "Child checkbox"; + By childLoc = DynamicControlsForm.getCheckboxLocator(); + List> findFunctions = new ArrayList<>(); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, name, CustomWebElement.class, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, name, CustomWebElement.class)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, CustomWebElement.class, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, CustomWebElement.class)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, name, CustomWebElement::new, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, name, CustomWebElement::new)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, CustomWebElement::new, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> DynamicControlsForm.getContentLabel().findChildElement(childLoc, CustomWebElement::new)); + return findFunctions.toArray(); + } +} diff --git a/src/test/java/tests/elements/WindowsElementTests.java b/src/test/java/tests/elements/WindowsElementTests.java new file mode 100644 index 0000000..649060e --- /dev/null +++ b/src/test/java/tests/elements/WindowsElementTests.java @@ -0,0 +1,108 @@ +package tests.elements; + +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.elements.ElementState; +import org.openqa.selenium.By; +import org.openqa.selenium.remote.RemoteWebElement; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import tests.ITestWithApplication; +import tests.applications.windowsApp.AqualityServices; +import tests.applications.windowsApp.CalculatorWindow; +import tests.elements.factory.CustomElement; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +public class WindowsElementTests implements ITestWithApplication { + + private static final By LOCATOR = By.xpath("//id"); + private static final String ELEMENT_NAME = "CustomElement"; + private static final ElementState ELEMENT_STATE = ElementState.EXISTS_IN_ANY_STATE; + private static final CustomElement CUSTOM_WEB_ELEMENT = new CustomElement(LOCATOR, ELEMENT_NAME, ELEMENT_STATE); + + @Override + public IApplication getApplication() { + return AqualityServices.getApplication(); + } + + @Override + public boolean isApplicationStarted() { + return AqualityServices.isApplicationStarted(); + } + + @Test + public void testShouldBePossibleToGetLocator() { + Assert.assertEquals(CUSTOM_WEB_ELEMENT.getLocator(), LOCATOR); + } + + @Test + public void testShouldBePossibleToGetElementName() { + Assert.assertEquals(CUSTOM_WEB_ELEMENT.getName(), ELEMENT_NAME); + } + + @Test + public void testShouldBePossibleToGetState() { + Assert.assertNotNull(CUSTOM_WEB_ELEMENT.state(), "State provider should not be null"); + } + + @Test + public void testShouldBePossibleToGetElement() { + RemoteWebElement element = CalculatorWindow.getOneButton().getElement(); + Assert.assertNotNull(element, "RemoteWebElement should not be null"); + } + + @Test + public void testShouldBePossibleToGetElementWithCustomTimeout() { + RemoteWebElement element = CalculatorWindow.getOneButton().getElement(1L); + Assert.assertNotNull(element, "RemoteWebElement should not be null"); + } + + @Test + public void testShouldBePossibleToClickOnElementAndGetText() { + CalculatorWindow.getOneButton().click(); + Assert.assertEquals(CalculatorWindow.getLeftValueTextBox().getText(), "1", "1 should be entered"); + } + + @Test + public void testShouldBePossibleToSendKeysToElement() { + String keys = "12"; + CalculatorWindow.getLeftValueTextBox().sendKeys(keys); + Assert.assertEquals(CalculatorWindow.getLeftValueTextBox().getText(), keys, "Keys should be entered"); + } + + @Test + public void testShouldBePossibleToGetAttributeFromElement() { + String value = CalculatorWindow.getOneButton().getAttribute("AutomationId"); + Assert.assertEquals(value, "26", "Keys should be entered"); + } + + @Test(dataProvider = "getChildElementFunctions") + public void testShouldBePossibleToFindChildElement(Callable findChildElement) { + try { + CustomElement element = findChildElement.call(); + Assert.assertNotNull(element, "Child element should be found"); + Assert.assertTrue(element.state().isDisplayed(), "Child element should be displayed"); + } catch (Exception e) { + Assert.fail("Cannot find child element", e); + } + } + + @DataProvider(name = "getChildElementFunctions") + public Object[] getChildElementFunctions() { + String name = "Child button"; + By childLoc = CalculatorWindow.getOneButtonLoc(); + List> findFunctions = new ArrayList<>(); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, name, CustomElement.class, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, name, CustomElement.class)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, CustomElement.class, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, CustomElement.class)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, name, CustomElement::new, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, name, CustomElement::new)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, CustomElement::new, ElementState.EXISTS_IN_ANY_STATE)); + findFunctions.add(() -> CalculatorWindow.getWindowLabel().findChildElement(childLoc, CustomElement::new)); + return findFunctions.toArray(); + } +} diff --git a/src/test/java/tests/elements/factory/CustomElement.java b/src/test/java/tests/elements/factory/CustomElement.java index 07d009d..4eb0731 100644 --- a/src/test/java/tests/elements/factory/CustomElement.java +++ b/src/test/java/tests/elements/factory/CustomElement.java @@ -10,11 +10,11 @@ import aquality.selenium.core.utilities.IElementActionRetrier; import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; -import tests.application.windowsApp.AqualityServices; +import tests.applications.windowsApp.AqualityServices; public class CustomElement extends Element implements ICustomElement { - CustomElement(By locator, String name, ElementState state) { + public CustomElement(By locator, String name, ElementState state) { super(locator, name, state); } diff --git a/src/test/java/tests/elements/factory/CustomElementFactory.java b/src/test/java/tests/elements/factory/CustomElementFactory.java index b3bb37c..faa73d1 100644 --- a/src/test/java/tests/elements/factory/CustomElementFactory.java +++ b/src/test/java/tests/elements/factory/CustomElementFactory.java @@ -18,6 +18,7 @@ public class CustomElementFactory extends ElementFactory { protected Map, Class> getElementTypesMap() { Map, Class> typesMap = new HashMap<>(); typesMap.put(ICustomElement.class, CustomElement.class); + typesMap.put(IWebCustomElement.class, CustomWebElement.class); return typesMap; } } diff --git a/src/test/java/tests/elements/factory/CustomWebElement.java b/src/test/java/tests/elements/factory/CustomWebElement.java new file mode 100644 index 0000000..14a49b6 --- /dev/null +++ b/src/test/java/tests/elements/factory/CustomWebElement.java @@ -0,0 +1,64 @@ +package tests.elements.factory; + +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.configurations.IElementCacheConfiguration; +import aquality.selenium.core.elements.Element; +import aquality.selenium.core.elements.ElementState; +import aquality.selenium.core.elements.interfaces.IElementFactory; +import aquality.selenium.core.elements.interfaces.IElementFinder; +import aquality.selenium.core.localization.ILocalizedLogger; +import aquality.selenium.core.utilities.IElementActionRetrier; +import aquality.selenium.core.waitings.IConditionalWait; +import org.openqa.selenium.By; +import tests.applications.browser.AqualityServices; + +public class CustomWebElement extends Element implements IWebCustomElement { + + public CustomWebElement(By locator, String name, ElementState state) { + super(locator, name, state); + } + + @Override + protected IApplication getApplication() { + return AqualityServices.getApplication(); + } + + @Override + protected IElementFactory getElementFactory() { + return AqualityServices.get(IElementFactory.class); + } + + @Override + protected IElementFinder getElementFinder() { + return AqualityServices.get(IElementFinder.class); + } + + @Override + protected IElementCacheConfiguration getElementCacheConfiguration() { + return AqualityServices.get(IElementCacheConfiguration.class); + } + + @Override + protected IElementActionRetrier getElementActionRetrier() { + return AqualityServices.get(IElementActionRetrier.class); + } + + @Override + protected ILocalizedLogger getLocalizedLogger() { + return AqualityServices.get(ILocalizedLogger.class); + } + + @Override + protected IConditionalWait getConditionalWait() { + return AqualityServices.get(IConditionalWait.class); + } + + @Override + protected String getElementType() { + return "Custom Web"; + } + + public ElementState getState() { + return getElementState(); + } +} diff --git a/src/test/java/tests/elements/factory/ElementFactoryTests.java b/src/test/java/tests/elements/factory/ElementFactoryTests.java index 746617c..8a221d2 100644 --- a/src/test/java/tests/elements/factory/ElementFactoryTests.java +++ b/src/test/java/tests/elements/factory/ElementFactoryTests.java @@ -16,8 +16,8 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import tests.ITestWithApplication; -import tests.application.windowsApp.AqualityServices; -import tests.application.windowsApp.CalculatorWindow; +import tests.applications.windowsApp.AqualityServices; +import tests.applications.windowsApp.CalculatorWindow; public class ElementFactoryTests implements ITestWithApplication { private static final String CONDITION_TIMEOUT_KEY = "timeouts.timeoutCondition"; @@ -127,7 +127,7 @@ public void shouldThrowTimeoutExceptionWhenCountIsNotExpected() { @Test public void shouldThrowInvalidArgumentExceptionInFindElementsWhenLocatorIsNotSupported() { - Assert.assertThrows(InvalidArgumentException.class, () -> customFactory().findElements(CalculatorWindow.getEqualsButton(), ICustomElement.class, ElementsCount.MORE_THEN_ZERO)); + Assert.assertThrows(InvalidArgumentException.class, () -> customFactory().findElements(CalculatorWindow.getEqualsButtonLoc(), ICustomElement.class, ElementsCount.MORE_THEN_ZERO)); } @Test @@ -148,40 +148,40 @@ public void shouldThrowIllegalArgumentExceptionInGetCustomElementElementTypeIsUn @Test public void shouldBePossibleToFindChildElementViaCustomFactory() { IElement parent = getParentElement(); - Assert.assertNotNull(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButton(), ICustomElement.class)); + Assert.assertNotNull(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), ICustomElement.class)); } @Test public void shouldBePossibleToFindChildElementWithSpecificName() { IElement parent = getParentElement(); String name = "123"; - Assert.assertEquals(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButton(), name, ICustomElement.class).getName(), name); + Assert.assertEquals(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), name, ICustomElement.class).getName(), name); } @Test public void shouldBePossibleToFindChildElementWithSpecificNameUsingSupplier() { IElement parent = getParentElement(); String name = "123"; - Assert.assertEquals(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButton(), name, CustomElement::new).getName(), name); + Assert.assertEquals(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), name, CustomElement::new).getName(), name); } @Test public void shouldBePossibleToFindChildElementViaCustomFactoryUsingSupplier() { IElement parent = getParentElement(); - Assert.assertNotNull(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButton(), CustomElement::new)); + Assert.assertNotNull(customFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), CustomElement::new)); } @Test public void shouldBePossibleToFindChildElementViaDefaultFactoryUsingImplementation() { IElement parent = defaultFactory().getCustomElement(CustomElement.class, CalculatorWindow.getWindowLocator(), "window"); - Assert.assertNotNull(defaultFactory().findChildElement(parent, CalculatorWindow.getEqualsButton(), CustomElement.class)); + Assert.assertNotNull(defaultFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), CustomElement.class)); } @Test public void shouldBePossibleToFindChildElementWithCustomState() { IElement parent = getParentElement(); Assert.assertEquals( - defaultFactory().findChildElement(parent, CalculatorWindow.getEqualsButton(), CustomElement.class, + defaultFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), CustomElement.class, ElementState.EXISTS_IN_ANY_STATE).getState(), ElementState.EXISTS_IN_ANY_STATE); } @@ -189,8 +189,8 @@ public void shouldBePossibleToFindChildElementWithCustomState() { @Test public void shouldSetCorrectParametersWhenGettingElement() { String name = "1some2"; - CustomElement element = defaultFactory().getCustomElement(CustomElement::new, CalculatorWindow.getEqualsButton(), name, ElementState.EXISTS_IN_ANY_STATE); - Assert.assertEquals(element.getLocator(), CalculatorWindow.getEqualsButton()); + CustomElement element = defaultFactory().getCustomElement(CustomElement::new, CalculatorWindow.getEqualsButtonLoc(), name, ElementState.EXISTS_IN_ANY_STATE); + Assert.assertEquals(element.getLocator(), CalculatorWindow.getEqualsButtonLoc()); Assert.assertEquals(element.getName(), name); Assert.assertEquals(element.getState(), ElementState.EXISTS_IN_ANY_STATE); } diff --git a/src/test/java/tests/elements/factory/IWebCustomElement.java b/src/test/java/tests/elements/factory/IWebCustomElement.java new file mode 100644 index 0000000..8ad872f --- /dev/null +++ b/src/test/java/tests/elements/factory/IWebCustomElement.java @@ -0,0 +1,6 @@ +package tests.elements.factory; + +import aquality.selenium.core.elements.interfaces.IElement; + +public interface IWebCustomElement extends IElement { +} diff --git a/src/test/java/tests/localization/LocalizationManagerTests.java b/src/test/java/tests/localization/LocalizationManagerTests.java index 6c3d203..00cc44b 100644 --- a/src/test/java/tests/localization/LocalizationManagerTests.java +++ b/src/test/java/tests/localization/LocalizationManagerTests.java @@ -7,8 +7,8 @@ import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; -import tests.application.browser.AqualityServices; +import tests.applications.CustomAqualityServices; +import tests.applications.browser.AqualityServices; import java.util.MissingFormatArgumentException; diff --git a/src/test/java/tests/logger/LoggerTests.java b/src/test/java/tests/logger/LoggerTests.java index 55a4260..929f146 100644 --- a/src/test/java/tests/logger/LoggerTests.java +++ b/src/test/java/tests/logger/LoggerTests.java @@ -6,7 +6,6 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; import java.io.File; import java.io.IOException; diff --git a/src/test/java/tests/utilities/CustomSettingsFileTests.java b/src/test/java/tests/utilities/CustomSettingsFileTests.java index abe2013..92634e9 100644 --- a/src/test/java/tests/utilities/CustomSettingsFileTests.java +++ b/src/test/java/tests/utilities/CustomSettingsFileTests.java @@ -6,8 +6,8 @@ import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; -import tests.application.browser.ChromeApplication; +import tests.applications.CustomAqualityServices; +import tests.applications.browser.ChromeApplication; import java.util.List; import java.util.Map; diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index 8f29c3e..f14baab 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -8,7 +8,7 @@ import org.openqa.selenium.StaleElementReferenceException; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import tests.application.browser.AqualityServices; +import tests.applications.browser.AqualityServices; import java.util.Date; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/test/java/tests/utilities/SettingsFileTests.java b/src/test/java/tests/utilities/SettingsFileTests.java index 15397b6..643f4a7 100644 --- a/src/test/java/tests/utilities/SettingsFileTests.java +++ b/src/test/java/tests/utilities/SettingsFileTests.java @@ -5,8 +5,8 @@ import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import tests.application.CustomAqualityServices; -import tests.application.TestModule; +import tests.applications.CustomAqualityServices; +import tests.applications.TestModule; import tests.configurations.BaseProfileTest; import java.util.Arrays; diff --git a/src/test/java/tests/waitings/BaseConditionalWaitTest.java b/src/test/java/tests/waitings/BaseConditionalWaitTest.java index 247d592..d2dd705 100644 --- a/src/test/java/tests/waitings/BaseConditionalWaitTest.java +++ b/src/test/java/tests/waitings/BaseConditionalWaitTest.java @@ -3,10 +3,9 @@ import aquality.selenium.core.applications.IApplication; import aquality.selenium.core.configurations.ITimeoutConfiguration; import aquality.selenium.core.waitings.ConditionalWait; -import com.google.inject.Injector; import com.google.inject.Provider; import org.testng.annotations.AfterMethod; -import tests.application.browser.AqualityServices; +import tests.applications.browser.AqualityServices; import utils.Timer; import java.util.Collection; diff --git a/src/test/java/theinternet/DynamicControlsForm.java b/src/test/java/theinternet/DynamicControlsForm.java index 7888519..8c2976c 100644 --- a/src/test/java/theinternet/DynamicControlsForm.java +++ b/src/test/java/theinternet/DynamicControlsForm.java @@ -4,13 +4,15 @@ import aquality.selenium.core.elements.ElementState; import aquality.selenium.core.elements.interfaces.IElementStateProvider; import org.openqa.selenium.By; -import tests.application.browser.CachedLabel; +import tests.applications.browser.CachedLabel; +import tests.elements.factory.CustomWebElement; import java.util.function.Function; import java.util.function.Supplier; public class DynamicControlsForm extends BaseForm { private static final By ENABLE_BUTTON_LOCATOR = By.xpath("//button[contains(@onclick, 'swapInput()')][contains(.,'Enable')]"); + private static final By LOADING_LABEL_LOCATOR = By.id("loading"); private static final By REMOVE_BUTTON_LOCATOR = By.xpath("//button[contains(@onclick, 'swapCheckbox()')]"); private static final By INPUT_TEXTBOX_LOCATOR = By.xpath("//input[@type='text']"); private static final By CHECKBOX_LOCATOR = By.xpath("//div[@id='checkbox']"); @@ -36,10 +38,14 @@ public IElementStateProvider checkboxState() { return state(CHECKBOX_LOCATOR); } - public static CachedLabel getContentLabel() { + public static CachedLabel getContentCachedLabel() { return new CachedLabel(CONTENT_LOCATOR, ElementState.DISPLAYED); } + public static By getCheckboxLocator() { + return CHECKBOX_LOCATOR; + } + public static CachedLabel getCheckboxLabel() { return new CachedLabel(CHECKBOX_LOCATOR, ElementState.EXISTS_IN_ANY_STATE); } @@ -47,4 +53,20 @@ public static CachedLabel getCheckboxLabel() { public static CachedLabel getRemoveLabel() { return new CachedLabel(REMOVE_BUTTON_LOCATOR, ElementState.EXISTS_IN_ANY_STATE); } + + public static CustomWebElement getEnableButton() { + return new CustomWebElement(ENABLE_BUTTON_LOCATOR, "Enable", ElementState.EXISTS_IN_ANY_STATE); + } + + public static CustomWebElement getRemoveButton() { + return new CustomWebElement(REMOVE_BUTTON_LOCATOR, "Remove", ElementState.EXISTS_IN_ANY_STATE); + } + + public static CustomWebElement getLoadingLabel() { + return new CustomWebElement(LOADING_LABEL_LOCATOR, "Loading", ElementState.DISPLAYED); + } + + public static CustomWebElement getContentLabel() { + return new CustomWebElement(CONTENT_LOCATOR, "Content", ElementState.DISPLAYED); + } } diff --git a/src/test/java/theinternet/DynamicLoadingForm.java b/src/test/java/theinternet/DynamicLoadingForm.java index 8de7e90..c36c11e 100644 --- a/src/test/java/theinternet/DynamicLoadingForm.java +++ b/src/test/java/theinternet/DynamicLoadingForm.java @@ -4,7 +4,7 @@ import aquality.selenium.core.elements.ElementState; import aquality.selenium.core.elements.interfaces.IElementStateProvider; import org.openqa.selenium.By; -import tests.application.browser.CachedLabel; +import tests.applications.browser.CachedLabel; import java.util.function.Function; import java.util.function.Supplier; diff --git a/src/test/java/theinternet/InputsForm.java b/src/test/java/theinternet/InputsForm.java new file mode 100644 index 0000000..ba4679b --- /dev/null +++ b/src/test/java/theinternet/InputsForm.java @@ -0,0 +1,23 @@ +package theinternet; + +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.elements.ElementState; +import aquality.selenium.core.elements.interfaces.IElementStateProvider; +import org.openqa.selenium.By; +import tests.elements.factory.CustomWebElement; + +import java.util.function.Function; +import java.util.function.Supplier; + +public class InputsForm extends BaseForm { + + private static final CustomWebElement INPUT_TEXT_BOX = new CustomWebElement(By.xpath("//input[@type='number']"), "Input", ElementState.EXISTS_IN_ANY_STATE); + + public InputsForm(Supplier appSupplier, Function stateProviderFunction) { + super(appSupplier, stateProviderFunction); + } + + public static CustomWebElement getInputTextBox(){ + return INPUT_TEXT_BOX; + } +} diff --git a/src/test/java/theinternet/TheInternetPage.java b/src/test/java/theinternet/TheInternetPage.java index b3080d4..3b7152e 100644 --- a/src/test/java/theinternet/TheInternetPage.java +++ b/src/test/java/theinternet/TheInternetPage.java @@ -2,7 +2,8 @@ public enum TheInternetPage { DYNAMIC_CONTROLS, - DYNAMIC_LOADING("dynamic_loading/1"); + DYNAMIC_LOADING("dynamic_loading/1"), + INPUTS("inputs"); private static final String BASE_URL = "http://the-internet.herokuapp.com/"; diff --git a/src/test/resources/TestSuite.xml b/src/test/resources/TestSuite.xml index 013f8cc..dd7df17 100644 --- a/src/test/resources/TestSuite.xml +++ b/src/test/resources/TestSuite.xml @@ -3,8 +3,8 @@ - - + + @@ -16,6 +16,7 @@ + @@ -24,7 +25,7 @@ - + @@ -33,6 +34,7 @@ + \ No newline at end of file From e0f53c3ae36d89e21a710ed7fddc538a9f8d1751 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Wed, 12 Feb 2020 15:28:13 +0300 Subject: [PATCH 05/21] #14 removed last 's' in applications --- .../selenium/core/applications/AqualityServices.java | 10 +++++----- .../selenium/core/applications/IApplication.java | 4 ++-- .../java/tests/applications/IApplicationTests.java | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/aquality/selenium/core/applications/AqualityServices.java b/src/main/java/aquality/selenium/core/applications/AqualityServices.java index 3cc435b..03572d2 100644 --- a/src/main/java/aquality/selenium/core/applications/AqualityServices.java +++ b/src/main/java/aquality/selenium/core/applications/AqualityServices.java @@ -24,14 +24,14 @@ protected > AqualityServices(Provider application } /** - * @return true if the applications is already started, false otherwise. + * @return true if the application is already started, false otherwise. */ protected boolean isAppStarted() { return app != null && app.isStarted(); } /** - * Sets the applications instance, saving it to DI container. + * Sets the application instance, saving it to DI container. * @param application instance to set into container. */ protected void setApp(T application) { @@ -39,9 +39,9 @@ protected void setApp(T application) { } /** - * Returns an existing applications or initializes a new one based on passed parameter. - * @param startApplicationFunction function to start the applications, where the injector could be used. - * @return started applications. + * Returns an existing application or initializes a new one based on passed parameter. + * @param startApplicationFunction function to start the application, where the injector could be used. + * @return started application. */ protected T getApp(Function startApplicationFunction) { if (!isAppStarted()) { diff --git a/src/main/java/aquality/selenium/core/applications/IApplication.java b/src/main/java/aquality/selenium/core/applications/IApplication.java index c171c65..6b61943 100644 --- a/src/main/java/aquality/selenium/core/applications/IApplication.java +++ b/src/main/java/aquality/selenium/core/applications/IApplication.java @@ -5,7 +5,7 @@ import java.util.concurrent.TimeUnit; /** - * Interface of any applications controlled by Selenium WebDriver API + * Interface of any application controlled by Selenium WebDriver API */ public interface IApplication { @@ -15,7 +15,7 @@ public interface IApplication { RemoteWebDriver getDriver(); /** - * @return Is the applications already running or not. + * @return Is the application already running or not. */ boolean isStarted(); diff --git a/src/test/java/tests/applications/IApplicationTests.java b/src/test/java/tests/applications/IApplicationTests.java index 0590de3..71c0e4a 100644 --- a/src/test/java/tests/applications/IApplicationTests.java +++ b/src/test/java/tests/applications/IApplicationTests.java @@ -21,7 +21,7 @@ default void testShouldBePossibleToGetApplication() { @Test default void testShouldBePossibleToGetDriver() { - Assert.assertNotNull(getApplication().getDriver(), "should be possible get driver from the applications"); + Assert.assertNotNull(getApplication().getDriver(), "should be possible get driver from the application"); } @Test @@ -41,16 +41,16 @@ default void checkImplicitWaitSetting(int valueInSeconds) { @Test default void testShouldBePossibleToDefineIsStarted() { Assert.assertFalse(isApplicationStarted(), - "applications should not be started before getting"); + "application should not be started before getting"); IApplication application = getApplication(); Assert.assertTrue(application.isStarted(), - "applications should be started when got it from the aquality services"); + "application should be started when got it from the aquality services"); Assert.assertTrue(isApplicationStarted(), - "applications should be started when check it's state from the aquality services"); + "application should be started when check it's state from the aquality services"); application.getDriver().quit(); Assert.assertFalse(application.isStarted(), - "applications should not be started after quit"); + "application should not be started after quit"); Assert.assertFalse(isApplicationStarted(), - "applications should not be started when check it's state from the aquality services after quit"); + "application should not be started when check it's state from the aquality services after quit"); } } From 05718683c47c23adf40a6d96cda5fec20d848cb0 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Wed, 12 Feb 2020 15:35:03 +0300 Subject: [PATCH 06/21] #14 small fix for docs --- src/main/java/aquality/selenium/core/elements/Element.java | 3 --- .../aquality/selenium/core/elements/interfaces/IElement.java | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index ebcbefc..569ed16 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -14,9 +14,6 @@ import java.util.function.Supplier; -/** - * Abstract class, describing wrapper of WebElement. - */ public abstract class Element implements IElement { private final String name; diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java b/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java index d925e17..ead0444 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java @@ -3,6 +3,9 @@ import org.openqa.selenium.By; import org.openqa.selenium.remote.RemoteWebElement; +/** + * Describes behavior of any UI element. + */ public interface IElement extends IParent { /** * Gets unique locator of element. From f3c13a6ba13de48cbdad33449919fe2d3cd03fde Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Wed, 12 Feb 2020 17:52:53 +0300 Subject: [PATCH 07/21] #14 fix comments --- .../java/aquality/selenium/core/elements/Element.java | 4 ---- src/test/java/tests/elements/WebElementTests.java | 2 +- .../java/tests/elements/factory/CustomElement.java | 4 ---- .../tests/elements/factory/CustomElementFactory.java | 1 - .../java/tests/elements/factory/CustomWebElement.java | 6 +----- .../tests/elements/factory/ElementFactoryTests.java | 11 +++++------ .../tests/elements/factory/IWebCustomElement.java | 6 ------ 7 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 src/test/java/tests/elements/factory/IWebCustomElement.java diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index 569ed16..ee69699 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -55,10 +55,6 @@ protected Logger getLogger() { return Logger.getInstance(); } - protected ElementState getElementState() { - return elementState; - } - @Override public By getLocator() { return locator; diff --git a/src/test/java/tests/elements/WebElementTests.java b/src/test/java/tests/elements/WebElementTests.java index 4dc7819..e076a06 100644 --- a/src/test/java/tests/elements/WebElementTests.java +++ b/src/test/java/tests/elements/WebElementTests.java @@ -51,7 +51,7 @@ public void testShouldBePossibleToGetState() { } @Test - public void testShouldBePossibleToGetbElement() { + public void testShouldBePossibleToGetElement() { getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); RemoteWebElement element = DynamicControlsForm.getEnableButton().getElement(); Assert.assertNotNull(element, "RemoteWebElement should not be null"); diff --git a/src/test/java/tests/elements/factory/CustomElement.java b/src/test/java/tests/elements/factory/CustomElement.java index 4eb0731..1389b7a 100644 --- a/src/test/java/tests/elements/factory/CustomElement.java +++ b/src/test/java/tests/elements/factory/CustomElement.java @@ -57,8 +57,4 @@ protected IConditionalWait getConditionalWait() { protected String getElementType() { return "Custom"; } - - public ElementState getState() { - return getElementState(); - } } diff --git a/src/test/java/tests/elements/factory/CustomElementFactory.java b/src/test/java/tests/elements/factory/CustomElementFactory.java index faa73d1..b3bb37c 100644 --- a/src/test/java/tests/elements/factory/CustomElementFactory.java +++ b/src/test/java/tests/elements/factory/CustomElementFactory.java @@ -18,7 +18,6 @@ public class CustomElementFactory extends ElementFactory { protected Map, Class> getElementTypesMap() { Map, Class> typesMap = new HashMap<>(); typesMap.put(ICustomElement.class, CustomElement.class); - typesMap.put(IWebCustomElement.class, CustomWebElement.class); return typesMap; } } diff --git a/src/test/java/tests/elements/factory/CustomWebElement.java b/src/test/java/tests/elements/factory/CustomWebElement.java index 14a49b6..539a32d 100644 --- a/src/test/java/tests/elements/factory/CustomWebElement.java +++ b/src/test/java/tests/elements/factory/CustomWebElement.java @@ -12,7 +12,7 @@ import org.openqa.selenium.By; import tests.applications.browser.AqualityServices; -public class CustomWebElement extends Element implements IWebCustomElement { +public class CustomWebElement extends Element { public CustomWebElement(By locator, String name, ElementState state) { super(locator, name, state); @@ -57,8 +57,4 @@ protected IConditionalWait getConditionalWait() { protected String getElementType() { return "Custom Web"; } - - public ElementState getState() { - return getElementState(); - } } diff --git a/src/test/java/tests/elements/factory/ElementFactoryTests.java b/src/test/java/tests/elements/factory/ElementFactoryTests.java index 8a221d2..ec7f9bd 100644 --- a/src/test/java/tests/elements/factory/ElementFactoryTests.java +++ b/src/test/java/tests/elements/factory/ElementFactoryTests.java @@ -96,9 +96,9 @@ public void shouldBePossibleToFindCustomElementsViaSupplierWithCustomName() { @Test public void shouldBePossibleToFindCustomElementsViaSupplierWithCustomState() { - Assert.assertEquals(customFactory().findElements( + Assert.assertTrue(customFactory().findElements( CalculatorWindow.getEqualsButtonByXPath(), CustomElement::new, ElementsCount.MORE_THEN_ZERO, - ElementState.EXISTS_IN_ANY_STATE).get(0).getState(), ElementState.EXISTS_IN_ANY_STATE); + ElementState.EXISTS_IN_ANY_STATE).size() > 0); } @Test @@ -180,10 +180,10 @@ public void shouldBePossibleToFindChildElementViaDefaultFactoryUsingImplementati @Test public void shouldBePossibleToFindChildElementWithCustomState() { IElement parent = getParentElement(); - Assert.assertEquals( + Assert.assertNotNull( defaultFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), CustomElement.class, - ElementState.EXISTS_IN_ANY_STATE).getState(), - ElementState.EXISTS_IN_ANY_STATE); + ElementState.EXISTS_IN_ANY_STATE).getElement(), + "Element should be found"); } @Test @@ -192,7 +192,6 @@ public void shouldSetCorrectParametersWhenGettingElement() { CustomElement element = defaultFactory().getCustomElement(CustomElement::new, CalculatorWindow.getEqualsButtonLoc(), name, ElementState.EXISTS_IN_ANY_STATE); Assert.assertEquals(element.getLocator(), CalculatorWindow.getEqualsButtonLoc()); Assert.assertEquals(element.getName(), name); - Assert.assertEquals(element.getState(), ElementState.EXISTS_IN_ANY_STATE); } @Override diff --git a/src/test/java/tests/elements/factory/IWebCustomElement.java b/src/test/java/tests/elements/factory/IWebCustomElement.java deleted file mode 100644 index 8ad872f..0000000 --- a/src/test/java/tests/elements/factory/IWebCustomElement.java +++ /dev/null @@ -1,6 +0,0 @@ -package tests.elements.factory; - -import aquality.selenium.core.elements.interfaces.IElement; - -public interface IWebCustomElement extends IElement { -} From 03fc0acbf3dd164918a1bdcde48668cf5a982549 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Wed, 12 Feb 2020 18:05:59 +0300 Subject: [PATCH 08/21] #14 remove using logger from testRetrierShouldWorkOnceIfMethodSucceeded --- src/test/java/tests/utilities/ElementActionRetrierTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index f14baab..70e55c8 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -35,7 +35,7 @@ private Object[][] handledExceptions() { @Test public void testRetrierShouldWorkOnceIfMethodSucceeded() { - checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> LOGGER.info(""))); + checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> "")); } @Test From dd24d541c00b6f49449064f31da9c75db4857124 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Wed, 12 Feb 2020 18:34:22 +0300 Subject: [PATCH 09/21] #14 reverted getElementState() for Element --- .../java/aquality/selenium/core/elements/Element.java | 4 ++++ .../java/tests/elements/factory/CustomElement.java | 4 ++++ .../tests/elements/factory/ElementFactoryTests.java | 11 ++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index ee69699..95dc88b 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -138,4 +138,8 @@ protected void doWithRetry(Runnable action) { protected void logElementAction(String messageKey, Object... args) { getLocalizedLogger().infoElementAction(getElementType(), name, messageKey, args); } + + protected ElementState getElementState() { + return elementState; + } } diff --git a/src/test/java/tests/elements/factory/CustomElement.java b/src/test/java/tests/elements/factory/CustomElement.java index 1389b7a..4eb0731 100644 --- a/src/test/java/tests/elements/factory/CustomElement.java +++ b/src/test/java/tests/elements/factory/CustomElement.java @@ -57,4 +57,8 @@ protected IConditionalWait getConditionalWait() { protected String getElementType() { return "Custom"; } + + public ElementState getState() { + return getElementState(); + } } diff --git a/src/test/java/tests/elements/factory/ElementFactoryTests.java b/src/test/java/tests/elements/factory/ElementFactoryTests.java index ec7f9bd..8a221d2 100644 --- a/src/test/java/tests/elements/factory/ElementFactoryTests.java +++ b/src/test/java/tests/elements/factory/ElementFactoryTests.java @@ -96,9 +96,9 @@ public void shouldBePossibleToFindCustomElementsViaSupplierWithCustomName() { @Test public void shouldBePossibleToFindCustomElementsViaSupplierWithCustomState() { - Assert.assertTrue(customFactory().findElements( + Assert.assertEquals(customFactory().findElements( CalculatorWindow.getEqualsButtonByXPath(), CustomElement::new, ElementsCount.MORE_THEN_ZERO, - ElementState.EXISTS_IN_ANY_STATE).size() > 0); + ElementState.EXISTS_IN_ANY_STATE).get(0).getState(), ElementState.EXISTS_IN_ANY_STATE); } @Test @@ -180,10 +180,10 @@ public void shouldBePossibleToFindChildElementViaDefaultFactoryUsingImplementati @Test public void shouldBePossibleToFindChildElementWithCustomState() { IElement parent = getParentElement(); - Assert.assertNotNull( + Assert.assertEquals( defaultFactory().findChildElement(parent, CalculatorWindow.getEqualsButtonLoc(), CustomElement.class, - ElementState.EXISTS_IN_ANY_STATE).getElement(), - "Element should be found"); + ElementState.EXISTS_IN_ANY_STATE).getState(), + ElementState.EXISTS_IN_ANY_STATE); } @Test @@ -192,6 +192,7 @@ public void shouldSetCorrectParametersWhenGettingElement() { CustomElement element = defaultFactory().getCustomElement(CustomElement::new, CalculatorWindow.getEqualsButtonLoc(), name, ElementState.EXISTS_IN_ANY_STATE); Assert.assertEquals(element.getLocator(), CalculatorWindow.getEqualsButtonLoc()); Assert.assertEquals(element.getName(), name); + Assert.assertEquals(element.getState(), ElementState.EXISTS_IN_ANY_STATE); } @Override From c8f39927289d2db7cb7e2562ae642846485dcac8 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Thu, 13 Feb 2020 16:35:30 +0300 Subject: [PATCH 10/21] #14 fix localization --- src/main/resources/localization/be.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/localization/be.json b/src/main/resources/localization/be.json index 8f0a39c..28ba29f 100644 --- a/src/main/resources/localization/be.json +++ b/src/main/resources/localization/be.json @@ -8,6 +8,6 @@ "loc.elements.were.found.but.not.in.state": "Знайшлі элементы па лакатару '%1$s', але яны не ў жаданым стане %2$s", "loc.elements.found.but.should.not": "Не павінна быць знойдзена элементаў па лакатару '%1$s' у %2$s стане", "loc.search.of.elements.failed": "Пошук элемента па лакатару '%1$s' прайшоў няўдала", - "loc.element.not.in.state": "Элемент %1$s ня стаў %2$s пасля таймаўта %3$s", + "loc.element.not.in.state": "Элемент %1$s не стаў %2$s пасля таймаўта %3$s", "loc.get.page.source.failed": "Адбылася памылка ў час атрымання разметкі старонкі" } \ No newline at end of file From a7c1814fca84727170e3c8540f7fd9280736b4e7 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 10:38:07 +0300 Subject: [PATCH 11/21] #14 increased accuracy of conditional wait tests --- src/test/java/tests/waitings/BaseConditionalWaitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/tests/waitings/BaseConditionalWaitTest.java b/src/test/java/tests/waitings/BaseConditionalWaitTest.java index 046b427..cdd92af 100644 --- a/src/test/java/tests/waitings/BaseConditionalWaitTest.java +++ b/src/test/java/tests/waitings/BaseConditionalWaitTest.java @@ -16,7 +16,7 @@ class BaseConditionalWaitTest { static final long waitForTimeoutCondition = 10; static final long waitForTimeoutPolling = 150; - static final double accuracy = 0.5; + static final double accuracy = 2; static final Collection> ignoredExceptions = Collections.singleton(IllegalStateException.class); ThreadLocal timer = ThreadLocal.withInitial(Timer::new); protected Provider application = AqualityServices.getServiceProvider().getProvider(IApplication.class); From 3ba1d5e39c1170d2a154b837bf591da688d97368 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 10:43:08 +0300 Subject: [PATCH 12/21] #14 added taskkill chromedriver --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bdabf17..eec5d38 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -7,6 +7,7 @@ pool: vmImage: 'windows-latest' steps: + - script: taskkill /f /im chromedriver.exe - task: SonarCloudPrepare@1 inputs: SonarCloud: 'SonarCloud' From da4b6ffd8636e716d0e94cb23edd694952df93fd Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 10:45:07 +0300 Subject: [PATCH 13/21] #14 removed taskkill chromedriver --- azure-pipelines.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index eec5d38..bdabf17 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -7,7 +7,6 @@ pool: vmImage: 'windows-latest' steps: - - script: taskkill /f /im chromedriver.exe - task: SonarCloudPrepare@1 inputs: SonarCloud: 'SonarCloud' From 9a4538b3894067bf0da36ad480ac52f98bc721a3 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 12:50:12 +0300 Subject: [PATCH 14/21] #14 hot fix for WaitForObjectTests --- src/test/java/tests/waitings/WaitForObjectTests.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/tests/waitings/WaitForObjectTests.java b/src/test/java/tests/waitings/WaitForObjectTests.java index f4a20fb..3c250ed 100644 --- a/src/test/java/tests/waitings/WaitForObjectTests.java +++ b/src/test/java/tests/waitings/WaitForObjectTests.java @@ -17,7 +17,7 @@ import static org.testng.Assert.assertTrue; public class WaitForObjectTests extends BaseConditionalWaitTest { - + private static final double SELENIUM_ACCURACY = 0.1; private static final String RESULT_STRING = "result"; @BeforeMethod @@ -46,9 +46,10 @@ public void testShouldThrowTimeoutExceptionIfConditionIsNotMetAndTimeoutIsOver(C } catch (TimeoutException e) { double duration = timer.get().stop(); double interval = timeout + pollingInterval / 1000 + accuracy; - assertTrue(duration >= timeout && duration < interval, + double accuracyTimeout = timeout - SELENIUM_ACCURACY; + assertTrue(duration >= accuracyTimeout && duration < interval, String.format("Duration '%s' should be between '%s' and '%s' (timeout and (timeout + pollingInterval + accuracy)) when condition is not satisfied.", - duration, timeout, interval)); + duration, accuracyTimeout, interval)); } } From 701bce950bfdc2cbbbcb898449bb02d1d94d8345 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 13:02:16 +0300 Subject: [PATCH 15/21] #14 removed redundant , --- src/test/java/tests/waitings/WaitForTests.java | 2 +- src/test/java/tests/waitings/WaitForTrueTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/tests/waitings/WaitForTests.java b/src/test/java/tests/waitings/WaitForTests.java index 977112a..0e791cb 100644 --- a/src/test/java/tests/waitings/WaitForTests.java +++ b/src/test/java/tests/waitings/WaitForTests.java @@ -118,7 +118,7 @@ private Object[][] getDataProvider(BooleanSupplier action) { {actionWithCustomTimeouts, waitForTimeoutCondition, waitForTimeoutPolling}, {actionWithCustomTimeoutsAndMessage, waitForTimeoutCondition, waitForTimeoutPolling}, {actionWithCustomTimeoutsAndExceptions, waitForTimeoutCondition, waitForTimeoutPolling}, - {actionWithAllParameters, waitForTimeoutCondition, waitForTimeoutPolling}, + {actionWithAllParameters, waitForTimeoutCondition, waitForTimeoutPolling} }; } } diff --git a/src/test/java/tests/waitings/WaitForTrueTests.java b/src/test/java/tests/waitings/WaitForTrueTests.java index 908e4e1..234484c 100644 --- a/src/test/java/tests/waitings/WaitForTrueTests.java +++ b/src/test/java/tests/waitings/WaitForTrueTests.java @@ -174,7 +174,7 @@ private Object[][] getDataProvider(BooleanSupplier action) { {actionWithCustomTimeouts, waitForTimeoutCondition, waitForTimeoutPolling}, {actionWithCustomTimeoutsAndMessage, waitForTimeoutCondition, waitForTimeoutPolling}, {actionWithCustomTimeoutsAndException, waitForTimeoutCondition, waitForTimeoutPolling}, - {actionWithAllParameters, waitForTimeoutCondition, waitForTimeoutPolling}, + {actionWithAllParameters, waitForTimeoutCondition, waitForTimeoutPolling} }; } } From a60d9c550988378104acc5d47d184422fbbbcd7f Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 13:28:16 +0300 Subject: [PATCH 16/21] #14 added debug info --- .../java/aquality/selenium/core/waitings/ConditionalWait.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java index 79cc46b..2954700 100644 --- a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java +++ b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java @@ -2,6 +2,7 @@ import aquality.selenium.core.applications.IApplication; import aquality.selenium.core.configurations.ITimeoutConfiguration; +import aquality.selenium.core.logging.Logger; import com.google.common.base.Strings; import com.google.inject.Inject; import com.google.inject.Provider; @@ -59,6 +60,7 @@ public void waitForTrue(BooleanSupplier condition, Long timeoutInSeconds, Long p try { Thread.sleep(pollingInterval); } catch (InterruptedException e) { + Logger.getInstance().info(String.format("Thread.sleep with %s pollingInterval is failed", pollingInterval)); Thread.currentThread().interrupt(); } } From 6264ee670a1f302d38ac50cacfa22883e7e11d6a Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 14:17:00 +0300 Subject: [PATCH 17/21] #14 added catching of InterruptedException --- .../selenium/core/waitings/ConditionalWait.java | 1 - .../tests/utilities/ElementActionRetrierTests.java | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java index 2954700..ed13b63 100644 --- a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java +++ b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java @@ -60,7 +60,6 @@ public void waitForTrue(BooleanSupplier condition, Long timeoutInSeconds, Long p try { Thread.sleep(pollingInterval); } catch (InterruptedException e) { - Logger.getInstance().info(String.format("Thread.sleep with %s pollingInterval is failed", pollingInterval)); Thread.currentThread().interrupt(); } } diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index 70e55c8..7795ef3 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -138,17 +138,21 @@ public void testRetrierShouldReturnValue() { } @Test(dataProvider = "handledExceptions", timeOut = 10000) - public void testRetrierShouldNotThrowExceptionOnInterruption(RuntimeException handledException) throws InterruptedException { + public void testRetrierShouldNotThrowExceptionOnInterruption(RuntimeException handledException) { AtomicBoolean isRetrierPaused = new AtomicBoolean(false); Thread thread = new Thread(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> { isRetrierPaused.set(true); throw handledException; })); thread.start(); - while (!isRetrierPaused.get()) { - Thread.sleep(POLLING_INTERVAL / 10); + try { + while (!isRetrierPaused.get()) { + Thread.sleep(POLLING_INTERVAL / 10); + } + Thread.sleep(POLLING_INTERVAL / 3); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } - Thread.sleep(POLLING_INTERVAL / 3); thread.interrupt(); } } From da2f07a00a6794b737f9c6d41cfd9209472789e9 Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 16:42:44 +0300 Subject: [PATCH 18/21] #14 removed parallel = true for data driven --- src/test/java/tests/elements/WebElementTests.java | 2 +- src/test/java/tests/waitings/WaitForObjectTests.java | 6 +++--- src/test/java/tests/waitings/WaitForTests.java | 6 +++--- src/test/java/tests/waitings/WaitForTrueTests.java | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/tests/elements/WebElementTests.java b/src/test/java/tests/elements/WebElementTests.java index e076a06..5aff7a2 100644 --- a/src/test/java/tests/elements/WebElementTests.java +++ b/src/test/java/tests/elements/WebElementTests.java @@ -105,7 +105,7 @@ public void testShouldBePossibleToFindChildElement(Callable fi } } - @DataProvider(name = "getChildElementFunctions", parallel = true) + @DataProvider(name = "getChildElementFunctions") public Object[] getChildElementFunctions() { String name = "Child checkbox"; By childLoc = DynamicControlsForm.getCheckboxLocator(); diff --git a/src/test/java/tests/waitings/WaitForObjectTests.java b/src/test/java/tests/waitings/WaitForObjectTests.java index 3c250ed..b3282da 100644 --- a/src/test/java/tests/waitings/WaitForObjectTests.java +++ b/src/test/java/tests/waitings/WaitForObjectTests.java @@ -32,7 +32,7 @@ public void quit() { } } - @DataProvider(name = "failWaitForAction", parallel = true) + @DataProvider(name = "failWaitForAction") public Object[][] failWaitForAction() { return getDataProvider((app) -> false); } @@ -53,7 +53,7 @@ public void testShouldThrowTimeoutExceptionIfConditionIsNotMetAndTimeoutIsOver(C } } - @DataProvider(name = "successWaitForAction", parallel = true) + @DataProvider(name = "successWaitForAction") public Object[][] successWaitForAction() { return getDataProvider((app) -> RESULT_STRING); } @@ -70,7 +70,7 @@ public void testShouldReturnAnObjectIfConditionIsMetAndTimeoutIsNotOver(Callable assertEquals(result, RESULT_STRING, "Method should return correct object"); } - @DataProvider(name = "throwWaitForAction", parallel = true) + @DataProvider(name = "throwWaitForAction") public Object[][] throwWaitForAction() { return getDataProvider((app) -> { throw new IllegalArgumentException("I am exception"); diff --git a/src/test/java/tests/waitings/WaitForTests.java b/src/test/java/tests/waitings/WaitForTests.java index 0e791cb..5b634de 100644 --- a/src/test/java/tests/waitings/WaitForTests.java +++ b/src/test/java/tests/waitings/WaitForTests.java @@ -13,7 +13,7 @@ public class WaitForTests extends BaseConditionalWaitTest { - @DataProvider(name = "falseWaitForAction", parallel = true) + @DataProvider(name = "falseWaitForAction") public Object[][] falseWaitForAction() { return getDataProvider(() -> false); } @@ -30,7 +30,7 @@ public void testFalseShouldBeReturnedIfConditionIsNotMetAndTimeoutIsOver(Boolean duration, timeout, accuracyPollingInterval)); } - @DataProvider(name = "trueWaitForAction", parallel = true) + @DataProvider(name = "trueWaitForAction") public Object[][] trueWaitForAction() { return getDataProvider(() -> true); } @@ -83,7 +83,7 @@ private void checkWaitForMethodForPassedCondition(BooleanSupplier waitAction, do duration, checkedTimeout)); } - @DataProvider(name = "throwExceptionAction", parallel = true) + @DataProvider(name = "throwExceptionAction") public Object[][] throwExceptionAction() { BooleanSupplier throwEx = () -> { throw new StaleElementReferenceException(""); diff --git a/src/test/java/tests/waitings/WaitForTrueTests.java b/src/test/java/tests/waitings/WaitForTrueTests.java index 234484c..0699f68 100644 --- a/src/test/java/tests/waitings/WaitForTrueTests.java +++ b/src/test/java/tests/waitings/WaitForTrueTests.java @@ -15,7 +15,7 @@ public class WaitForTrueTests extends BaseConditionalWaitTest { - @DataProvider(name = "falseWaitForTrueAction", parallel = true) + @DataProvider(name = "falseWaitForTrueAction") public Object[][] falseWaitForAction() { return getDataProvider(() -> false); } @@ -35,7 +35,7 @@ public void testTimeoutExceptionShouldBeThrownIfConditionIsMetAndTimeoutIsOver(C } } - @DataProvider(name = "successWaitForAction", parallel = true) + @DataProvider(name = "successWaitForAction") public Object[][] successWaitForAction() { return getDataProvider(() -> true); } @@ -50,7 +50,7 @@ public void testTimeoutExceptionShouldNotBeThrownIfConditionIsMetAndTimeoutIsNot String.format("Duration '%s' should be less than accuracy polling interval '%s'", duration, accuracyPollingInterval)); } - @DataProvider(name = "throwExceptionAction", parallel = true) + @DataProvider(name = "throwExceptionAction") public Object[][] throwExceptionAction() { BooleanSupplier throwEx = () -> { throw new StaleElementReferenceException(""); From 53fe0d1fe645f3406ce08272c3abad59338b4b9f Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 16:52:21 +0300 Subject: [PATCH 19/21] #14 reverted for element action retrier tests --- src/test/java/tests/utilities/ElementActionRetrierTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index 7795ef3..99cde2e 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -6,6 +6,7 @@ import org.openqa.selenium.InvalidArgumentException; import org.openqa.selenium.InvalidElementStateException; import org.openqa.selenium.StaleElementReferenceException; +import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import tests.applications.browser.AqualityServices; @@ -152,6 +153,7 @@ public void testRetrierShouldNotThrowExceptionOnInterruption(RuntimeException ha Thread.sleep(POLLING_INTERVAL / 3); } catch (InterruptedException e) { Thread.currentThread().interrupt(); + Assert.fail("Retrier should handle InterruptedException"); } thread.interrupt(); } From 55d49eef767abba7d057b14f5b0c25cdd3fb0afd Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 17:06:42 +0300 Subject: [PATCH 20/21] #14 added accuracy for checkRetrierShouldWaitPollingTimeBetweenMethodsCall --- src/test/java/tests/utilities/ElementActionRetrierTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index 99cde2e..3faae3a 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -25,6 +25,7 @@ public class ElementActionRetrierTests { private static final int RETRIES_COUNT = RETRY_CONFIGURATION.getNumber(); private static final long POLLING_INTERVAL = RETRY_CONFIGURATION.getPollingInterval(); private static final ElementActionRetrier ELEMENT_ACTION_RETRIER = new ElementActionRetrier(RETRY_CONFIGURATION); + private static final long ACCURACY = 100; @DataProvider private Object[][] handledExceptions() { @@ -82,8 +83,10 @@ private void checkRetrierShouldWaitPollingTimeBetweenMethodsCall(Runnable retryF Date startTime = new Date(); retryFunction.run(); long duration = new Date().getTime() - startTime.getTime(); + long doubledAccuracyPollingInterval = 2 * POLLING_INTERVAL + ACCURACY; assertTrue(duration >= POLLING_INTERVAL, String.format("duration '%s' should be more than polling interval '%s'", duration, POLLING_INTERVAL)); - assertTrue(duration <= 2 * POLLING_INTERVAL, String.format("duration '%s' should be less than doubled polling interval '%s'", duration, POLLING_INTERVAL)); + assertTrue(duration <= doubledAccuracyPollingInterval, + String.format("duration '%s' should be less than doubled polling interval '%s'", duration, doubledAccuracyPollingInterval)); } @Test(expectedExceptions = InvalidArgumentException.class) From be548c2e34c8d83c3dc03c80cb9946515360c86f Mon Sep 17 00:00:00 2001 From: Sergey Knysh Date: Fri, 14 Feb 2020 17:27:54 +0300 Subject: [PATCH 21/21] #14 removed unused import --- .../java/aquality/selenium/core/waitings/ConditionalWait.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java index ed13b63..79cc46b 100644 --- a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java +++ b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java @@ -2,7 +2,6 @@ import aquality.selenium.core.applications.IApplication; import aquality.selenium.core.configurations.ITimeoutConfiguration; -import aquality.selenium.core.logging.Logger; import com.google.common.base.Strings; import com.google.inject.Inject; import com.google.inject.Provider;