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..95dc88b --- /dev/null +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -0,0 +1,145 @@ +package aquality.selenium.core.elements; + +import aquality.selenium.core.applications.IApplication; +import aquality.selenium.core.configurations.IElementCacheConfiguration; +import aquality.selenium.core.elements.interfaces.*; +import aquality.selenium.core.localization.ILocalizedLogger; +import aquality.selenium.core.logging.Logger; +import aquality.selenium.core.utilities.IElementActionRetrier; +import aquality.selenium.core.waitings.IConditionalWait; +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; + +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 IConditionalWait getConditionalWait(); + + protected abstract String getElementType(); + + protected IElementCacheHandler getCache() { + if (elementCacheHandler == null) { + elementCacheHandler = new ElementCacheHandler(locator, elementState, getElementFinder()); + } + + return elementCacheHandler; + } + + 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() + ? new CachedElementStateProvider(locator, getConditionalWait(), getCache(), getLocalizedLogger()) + : new DefaultElementStateProvider(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, Class clazz, ElementState state) { + return getElementFactory().findChildElement(this, childLoc, name, clazz, state); + } + + @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); + } + + protected ElementState getElementState() { + return elementState; + } +} 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 f3b5b63..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,36 +3,75 @@ 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. + * + * @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 clear WebElement. + * 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 WebElement + * @return instance of {@link RemoteWebElement} if found. */ default RemoteWebElement getElement() { return getElement(null); } /** - * Gets clear WebElement. + * Gets current element by specified {@link #getLocator()} + * {@link org.openqa.selenium.NoSuchElementException} throws if element not found * * @param timeout Timeout for waiting - * @return WebElement + * @return instance of {@link RemoteWebElement} if found. */ RemoteWebElement getElement(Long timeout); /** - * Gets element name. + * Gets the item text (inner text). * - * @return name + * @return text of element */ - String getName(); + String getText(); /** - * Gets element locator. + * Gets attribute value of the element. * - * @return locator + * @param attr Attribute name + * @return Attribute value */ - By getLocator(); + 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/IParent.java b/src/main/java/aquality/selenium/core/elements/interfaces/IParent.java index 9efa4f9..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,31 +8,100 @@ 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 + * @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 */ - default T findChildElement(By childLoc, Class clazz){ - return findChildElement(childLoc, clazz, ElementState.DISPLAYED); + T findChildElement(By childLoc, String name, Class clazz, ElementState state); + + /** + * Find an element in the parent element with DISPLAYED state + * + * @param childLoc child element locator + * @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, String name, Class clazz) { + return findChildElement(childLoc, name, 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 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); + default T findChildElement(By childLoc, Class clazz, ElementState state) { + return findChildElement(childLoc, null, clazz, state); + } /** - * Find an element in the parent element + * Find an element in the parent element with DISPLAYED state + * + * @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, 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 + */ + T findChildElement(By childLoc, String name, IElementSupplier supplier, ElementState state); + + /** + * 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, ElementState.DISPLAYED); + } + + /** + * 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 state visibility state of target element + * @param the type of the element to be obtained * @return found child element */ - T findChildElement(By childLoc, IElementSupplier supplier, ElementState state); + default T findChildElement(By childLoc, IElementSupplier supplier, ElementState state) { + return findChildElement(childLoc, null, supplier, state); + } + + /** + * Find an element in the parent element with DISPLAYED state + * + * @param childLoc child element locator + * @param supplier required element's supplier + * @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, ElementState.DISPLAYED); + } } diff --git a/src/main/resources/localization/be.json b/src/main/resources/localization/be.json index 3fbde43..28ba29f 100644 --- a/src/main/resources/localization/be.json +++ b/src/main/resources/localization/be.json @@ -8,5 +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 diff --git a/src/main/resources/localization/en.json b/src/main/resources/localization/en.json index 76aac44..c327953 100644 --- a/src/main/resources/localization/en.json +++ b/src/main/resources/localization/en.json @@ -8,5 +8,6 @@ "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.element.not.in.state": "Element %1$s has not become %2$s after timeout %3$s" + "loc.element.not.in.state": "Element %1$s has not become %2$s after timeout %3$s", + "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 6395e8a..812a206 100644 --- a/src/main/resources/localization/ru.json +++ b/src/main/resources/localization/ru.json @@ -8,5 +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 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 98% rename from src/test/java/tests/application/IApplicationTests.java rename to src/test/java/tests/applications/IApplicationTests.java index f204de3..71c0e4a 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; 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..5aff7a2 --- /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 testShouldBePossibleToGetElement() { + 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") + 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 358feac..4eb0731 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.applications.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; + public 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(); } } 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..539a32d --- /dev/null +++ b/src/test/java/tests/elements/factory/CustomWebElement.java @@ -0,0 +1,60 @@ +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 { + + 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"; + } +} 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/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..3faae3a 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -6,9 +6,10 @@ 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.application.browser.AqualityServices; +import tests.applications.browser.AqualityServices; import java.util.Date; import java.util.concurrent.atomic.AtomicBoolean; @@ -24,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() { @@ -35,7 +37,7 @@ private Object[][] handledExceptions() { @Test public void testRetrierShouldWorkOnceIfMethodSucceeded() { - checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> LOGGER.info(""))); + checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> "")); } @Test @@ -81,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) @@ -138,17 +142,22 @@ 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(); + Assert.fail("Retrier should handle InterruptedException"); } - Thread.sleep(POLLING_INTERVAL / 3); thread.interrupt(); } } diff --git a/src/test/java/tests/utilities/SettingsFileTests.java b/src/test/java/tests/utilities/SettingsFileTests.java index c38d830..c999e81 100644 --- a/src/test/java/tests/utilities/SettingsFileTests.java +++ b/src/test/java/tests/utilities/SettingsFileTests.java @@ -7,8 +7,8 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; 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.*; diff --git a/src/test/java/tests/waitings/BaseConditionalWaitTest.java b/src/test/java/tests/waitings/BaseConditionalWaitTest.java index 40b5cd9..cdd92af 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; @@ -17,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); diff --git a/src/test/java/tests/waitings/WaitForObjectTests.java b/src/test/java/tests/waitings/WaitForObjectTests.java index f4a20fb..b3282da 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 @@ -32,7 +32,7 @@ public void quit() { } } - @DataProvider(name = "failWaitForAction", parallel = true) + @DataProvider(name = "failWaitForAction") public Object[][] failWaitForAction() { return getDataProvider((app) -> false); } @@ -46,13 +46,14 @@ 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)); } } - @DataProvider(name = "successWaitForAction", parallel = true) + @DataProvider(name = "successWaitForAction") public Object[][] successWaitForAction() { return getDataProvider((app) -> RESULT_STRING); } @@ -69,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 977112a..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(""); @@ -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..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(""); @@ -174,7 +174,7 @@ private Object[][] getDataProvider(BooleanSupplier action) { {actionWithCustomTimeouts, waitForTimeoutCondition, waitForTimeoutPolling}, {actionWithCustomTimeoutsAndMessage, waitForTimeoutCondition, waitForTimeoutPolling}, {actionWithCustomTimeoutsAndException, waitForTimeoutCondition, waitForTimeoutPolling}, - {actionWithAllParameters, waitForTimeoutCondition, waitForTimeoutPolling}, + {actionWithAllParameters, waitForTimeoutCondition, waitForTimeoutPolling} }; } } 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