diff --git a/src/main/java/aquality/selenium/core/applications/IApplication.java b/src/main/java/aquality/selenium/core/applications/IApplication.java index 6b61943..f3fc5a4 100644 --- a/src/main/java/aquality/selenium/core/applications/IApplication.java +++ b/src/main/java/aquality/selenium/core/applications/IApplication.java @@ -2,7 +2,7 @@ import org.openqa.selenium.remote.RemoteWebDriver; -import java.util.concurrent.TimeUnit; +import java.time.Duration; /** * Interface of any application controlled by Selenium WebDriver API @@ -22,7 +22,6 @@ public interface IApplication { /** * Sets implicit wait timeout to Selenium WebDriver. * @param value timeout value to set. - * @param timeUnit timeUnit of timeout value. */ - void setImplicitWaitTimeout(long value, TimeUnit timeUnit); + void setImplicitWaitTimeout(Duration value); } diff --git a/src/main/java/aquality/selenium/core/configurations/IRetryConfiguration.java b/src/main/java/aquality/selenium/core/configurations/IRetryConfiguration.java index e6d9ca3..f0f76f6 100644 --- a/src/main/java/aquality/selenium/core/configurations/IRetryConfiguration.java +++ b/src/main/java/aquality/selenium/core/configurations/IRetryConfiguration.java @@ -1,5 +1,7 @@ package aquality.selenium.core.configurations; +import java.time.Duration; + /** * Describes retry configuration. */ @@ -17,5 +19,5 @@ public interface IRetryConfiguration { * * @return Polling interval for retry. */ - long getPollingInterval(); + Duration getPollingInterval(); } diff --git a/src/main/java/aquality/selenium/core/configurations/ITimeoutConfiguration.java b/src/main/java/aquality/selenium/core/configurations/ITimeoutConfiguration.java index bfc69c5..892f59e 100644 --- a/src/main/java/aquality/selenium/core/configurations/ITimeoutConfiguration.java +++ b/src/main/java/aquality/selenium/core/configurations/ITimeoutConfiguration.java @@ -1,5 +1,7 @@ package aquality.selenium.core.configurations; +import java.time.Duration; + /** * Provides timeouts configuration. */ @@ -10,26 +12,26 @@ public interface ITimeoutConfiguration { * * @return ImplicitWait timeout. */ - long getImplicit(); + Duration getImplicit(); /** * Gets default ConditionalWait timeout. * * @return ConditionalWait timeout. */ - long getCondition(); + Duration getCondition(); /** * Gets ConditionalWait polling interval. * * @return polling interval. */ - long getPollingInterval(); + Duration getPollingInterval(); /** * Gets Command timeout. * * @return Command timeout. */ - long getCommand(); + Duration getCommand(); } diff --git a/src/main/java/aquality/selenium/core/configurations/RetryConfiguration.java b/src/main/java/aquality/selenium/core/configurations/RetryConfiguration.java index 4121510..690ee29 100644 --- a/src/main/java/aquality/selenium/core/configurations/RetryConfiguration.java +++ b/src/main/java/aquality/selenium/core/configurations/RetryConfiguration.java @@ -3,14 +3,16 @@ import aquality.selenium.core.utilities.ISettingsFile; import com.google.inject.Inject; +import java.time.Duration; + public class RetryConfiguration implements IRetryConfiguration { private final int number; - private final long pollingInterval; + private final Duration pollingInterval; @Inject public RetryConfiguration(ISettingsFile settingsFile) { this.number = Integer.parseInt(settingsFile.getValue("/retry/number").toString()); - this.pollingInterval = Long.parseLong(settingsFile.getValue("/retry/pollingInterval").toString()); + this.pollingInterval = Duration.ofMillis(Long.parseLong(settingsFile.getValue("/retry/pollingInterval").toString())); } @Override @@ -19,7 +21,7 @@ public int getNumber() { } @Override - public long getPollingInterval() { + public Duration getPollingInterval() { return pollingInterval; } } diff --git a/src/main/java/aquality/selenium/core/configurations/TimeoutConfiguration.java b/src/main/java/aquality/selenium/core/configurations/TimeoutConfiguration.java index b5d8cd9..a6ef488 100644 --- a/src/main/java/aquality/selenium/core/configurations/TimeoutConfiguration.java +++ b/src/main/java/aquality/selenium/core/configurations/TimeoutConfiguration.java @@ -3,40 +3,46 @@ import aquality.selenium.core.utilities.ISettingsFile; import com.google.inject.Inject; -public class TimeoutConfiguration implements ITimeoutConfiguration{ +import java.time.Duration; + +public class TimeoutConfiguration implements ITimeoutConfiguration { private final ISettingsFile settingsFile; - private final long condition; - private final long pollInterval; - private final long implicit; - private final long command; + private final Duration condition; + private final Duration pollInterval; + private final Duration implicit; + private final Duration command; @Inject public TimeoutConfiguration(ISettingsFile settingsFile) { this.settingsFile = settingsFile; - condition = getTimeout(TIMEOUT.CONDITION); - pollInterval = getTimeout(TIMEOUT.POLL_INTERVAL); - implicit = getTimeout(TIMEOUT.IMPLICIT); - command = getTimeout(TIMEOUT.COMMAND); + condition = getDurationFromSeconds(TIMEOUT.CONDITION); + pollInterval = Duration.ofMillis(getTimeout(TIMEOUT.POLL_INTERVAL)); + implicit = getDurationFromSeconds(TIMEOUT.IMPLICIT); + command = getDurationFromSeconds(TIMEOUT.COMMAND); } - private long getTimeout(TIMEOUT timeout){ + private long getTimeout(TIMEOUT timeout) { return Long.valueOf(settingsFile.getValue(timeout.getKey()).toString()); } - public long getImplicit(){ + private Duration getDurationFromSeconds(TIMEOUT timeout) { + return Duration.ofSeconds(getTimeout(timeout)); + } + + public Duration getImplicit() { return implicit; } - public long getCondition(){ + public Duration getCondition() { return condition; } - public long getPollingInterval(){ + public Duration getPollingInterval() { return pollInterval; } - public long getCommand(){ + public Duration getCommand() { return command; } @@ -47,11 +53,12 @@ private enum TIMEOUT { COMMAND("/timeouts/timeoutCommand"); private String key; - TIMEOUT(String key){ + + TIMEOUT(String key) { this.key = key; } - private String getKey(){ + private String getKey() { return key; } } diff --git a/src/main/java/aquality/selenium/core/elements/CachedElementStateProvider.java b/src/main/java/aquality/selenium/core/elements/CachedElementStateProvider.java index db0c56c..1359e55 100644 --- a/src/main/java/aquality/selenium/core/elements/CachedElementStateProvider.java +++ b/src/main/java/aquality/selenium/core/elements/CachedElementStateProvider.java @@ -8,6 +8,7 @@ import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebElement; +import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -42,7 +43,7 @@ protected boolean tryInvokeFunction(Predicate predicate) { protected boolean tryInvokeFunction(Predicate predicate, List> handledExceptions) { try { - return predicate.test(elementCacheHandler.getElement(getZeroTImeout(), ElementState.EXISTS_IN_ANY_STATE)); + return predicate.test(elementCacheHandler.getElement(Duration.ZERO, ElementState.EXISTS_IN_ANY_STATE)); } catch (Exception exception) { if (handledExceptions.contains(exception.getClass())) { return false; @@ -51,10 +52,10 @@ protected boolean tryInvokeFunction(Predicate predicate, List tryInvokeFunction(WebElement::isDisplayed), ElementState.DISPLAYED.toString(), timeout); } @Override - public boolean waitForNotDisplayed(Long timeout) { + public boolean waitForNotDisplayed(Duration timeout) { return waitForCondition(() -> !isDisplayed(), "invisible or absent", timeout); } @@ -97,12 +98,12 @@ public boolean isExist() { } @Override - public boolean waitForExist(Long timeout) { + public boolean waitForExist(Duration timeout) { return waitForCondition(() -> tryInvokeFunction(element -> true), ElementState.EXISTS_IN_ANY_STATE.toString(), timeout); } @Override - public boolean waitForNotExist(Long timeout) { + public boolean waitForNotExist(Duration timeout) { return waitForCondition(() -> !isExist(), "absent", timeout); } @@ -112,12 +113,12 @@ public boolean isEnabled() { } @Override - public boolean waitForEnabled(Long timeout) { + public boolean waitForEnabled(Duration timeout) { return waitForCondition(this::isEnabled, elementEnabled().getStateName(), timeout); } @Override - public boolean waitForNotEnabled(Long timeout) { + public boolean waitForNotEnabled(Duration timeout) { return waitForCondition(() -> !isEnabled(), elementNotEnabled().getStateName(), timeout); } } diff --git a/src/main/java/aquality/selenium/core/elements/DefaultElementStateProvider.java b/src/main/java/aquality/selenium/core/elements/DefaultElementStateProvider.java index f0cc8f6..8c89fea 100644 --- a/src/main/java/aquality/selenium/core/elements/DefaultElementStateProvider.java +++ b/src/main/java/aquality/selenium/core/elements/DefaultElementStateProvider.java @@ -4,6 +4,8 @@ import aquality.selenium.core.waitings.IConditionalWait; import org.openqa.selenium.By; +import java.time.Duration; + public class DefaultElementStateProvider extends ElementStateProvider { private final By locator; @@ -18,70 +20,70 @@ public DefaultElementStateProvider(By locator, IConditionalWait conditionalWait, @Override public boolean isClickable() { - return waitForIsClickable(getZeroTImeout(), true); + return waitForIsClickable(Duration.ZERO, true); } @Override - public void waitForClickable(Long timeout) { + public void waitForClickable(Duration timeout) { waitForIsClickable(timeout, false); } - private boolean waitForIsClickable(Long timeout, boolean catchTimeoutException) { + private boolean waitForIsClickable(Duration timeout, boolean catchTimeoutException) { DesiredState desiredState = elementClickable(); desiredState = catchTimeoutException ? desiredState.withCatchingTimeoutException() : desiredState; return isElementInDesiredCondition(desiredState, timeout); } - private boolean isElementInDesiredCondition(DesiredState elementStateCondition, Long timeout) { + private boolean isElementInDesiredCondition(DesiredState elementStateCondition, Duration timeout) { return !elementFinder.findElements(locator, elementStateCondition, timeout).isEmpty(); } @Override public boolean isDisplayed() { - return waitForDisplayed(getZeroTImeout()); + return waitForDisplayed(Duration.ZERO); } @Override - public boolean waitForDisplayed(Long timeout) { + public boolean waitForDisplayed(Duration timeout) { return isAnyElementFound(timeout, ElementState.DISPLAYED); } - private boolean isAnyElementFound(Long timeout, ElementState state) { + private boolean isAnyElementFound(Duration timeout, ElementState state) { return !elementFinder.findElements(locator, state, timeout).isEmpty(); } @Override - public boolean waitForNotDisplayed(Long timeout) { - return conditionalWait.waitFor(() -> !isDisplayed(), timeout, null); + public boolean waitForNotDisplayed(Duration timeout) { + return conditionalWait.waitFor(() -> !isDisplayed(), timeout); } @Override public boolean isExist() { - return waitForExist(getZeroTImeout()); + return waitForExist(Duration.ZERO); } @Override - public boolean waitForExist(Long timeout) { + public boolean waitForExist(Duration timeout) { return isAnyElementFound(timeout, ElementState.EXISTS_IN_ANY_STATE); } @Override - public boolean waitForNotExist(Long timeout) { - return conditionalWait.waitFor(() -> !isExist(), timeout, null); + public boolean waitForNotExist(Duration timeout) { + return conditionalWait.waitFor(() -> !isExist(), timeout); } @Override public boolean isEnabled() { - return waitForEnabled(getZeroTImeout()); + return waitForEnabled(Duration.ZERO); } @Override - public boolean waitForEnabled(Long timeout) { + public boolean waitForEnabled(Duration timeout) { return isElementInDesiredCondition(elementEnabled(), timeout); } @Override - public boolean waitForNotEnabled(Long timeout) { + public boolean waitForNotEnabled(Duration timeout) { return isElementInDesiredCondition(elementNotEnabled(), timeout); } } diff --git a/src/main/java/aquality/selenium/core/elements/Element.java b/src/main/java/aquality/selenium/core/elements/Element.java index 95dc88b..7a11dec 100644 --- a/src/main/java/aquality/selenium/core/elements/Element.java +++ b/src/main/java/aquality/selenium/core/elements/Element.java @@ -12,6 +12,7 @@ import org.openqa.selenium.WebDriverException; import org.openqa.selenium.remote.RemoteWebElement; +import java.time.Duration; import java.util.function.Supplier; public abstract class Element implements IElement { @@ -73,7 +74,7 @@ public IElementStateProvider state() { } @Override - public RemoteWebElement getElement(Long timeout) { + public RemoteWebElement getElement(Duration timeout) { try { return getElementCacheConfiguration().isEnabled() ? getCache().getElement(timeout) diff --git a/src/main/java/aquality/selenium/core/elements/ElementCacheHandler.java b/src/main/java/aquality/selenium/core/elements/ElementCacheHandler.java index caadf0b..11a6123 100644 --- a/src/main/java/aquality/selenium/core/elements/ElementCacheHandler.java +++ b/src/main/java/aquality/selenium/core/elements/ElementCacheHandler.java @@ -5,6 +5,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.remote.RemoteWebElement; +import java.time.Duration; + /** * Implementation of {@link IElementCacheHandler}. */ @@ -44,7 +46,7 @@ public boolean wasCached() { } @Override - public RemoteWebElement getElement(Long timeout, ElementState customState) { + public RemoteWebElement getElement(Duration timeout, ElementState customState) { ElementState requiredState = customState == null ? state : customState; if (isRefreshNeeded(requiredState)) { remoteElement = (RemoteWebElement) finder.findElement(locator, requiredState, timeout); diff --git a/src/main/java/aquality/selenium/core/elements/ElementFactory.java b/src/main/java/aquality/selenium/core/elements/ElementFactory.java index edacc1d..357aabb 100644 --- a/src/main/java/aquality/selenium/core/elements/ElementFactory.java +++ b/src/main/java/aquality/selenium/core/elements/ElementFactory.java @@ -16,6 +16,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.time.Duration; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -25,7 +26,7 @@ public class ElementFactory implements IElementFactory { private static final int XPATH_SUBSTRING_BEGIN_INDEX = 10; - private static final long ZERO_TIMEOUT = 0L; + private static final Duration ZERO_TIMEOUT = Duration.ZERO; private final IConditionalWait conditionalWait; private final IElementFinder elementFinder; diff --git a/src/main/java/aquality/selenium/core/elements/ElementFinder.java b/src/main/java/aquality/selenium/core/elements/ElementFinder.java index 89455d0..97e5634 100644 --- a/src/main/java/aquality/selenium/core/elements/ElementFinder.java +++ b/src/main/java/aquality/selenium/core/elements/ElementFinder.java @@ -6,6 +6,7 @@ import com.google.inject.Inject; import org.openqa.selenium.*; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -24,14 +25,13 @@ public ElementFinder(ILocalizedLogger localizedLogger, IConditionalWait conditio } @Override - public List findElements(By locator, DesiredState desiredState, Long timeoutInSeconds) { + public List findElements(By locator, DesiredState desiredState, Duration timeout) { AtomicBoolean wasAnyElementFound = new AtomicBoolean(false); List resultElements = new ArrayList<>(); try { conditionalWait.waitFor(driver -> tryToFindElements(locator, desiredState, wasAnyElementFound, resultElements, driver), - timeoutInSeconds, - null); + timeout); } catch (TimeoutException e) { handleTimeoutException(e, locator, desiredState, wasAnyElementFound.get()); } diff --git a/src/main/java/aquality/selenium/core/elements/ElementStateProvider.java b/src/main/java/aquality/selenium/core/elements/ElementStateProvider.java index d0976fe..bc96bf0 100644 --- a/src/main/java/aquality/selenium/core/elements/ElementStateProvider.java +++ b/src/main/java/aquality/selenium/core/elements/ElementStateProvider.java @@ -4,11 +4,6 @@ import org.openqa.selenium.WebElement; public abstract class ElementStateProvider implements IElementStateProvider { - private static final long ZERO_TIMEOUT = 0L; - - protected Long getZeroTImeout() { - return ZERO_TIMEOUT; - } protected boolean isElementEnabled(WebElement element) { return element.isEnabled(); diff --git a/src/main/java/aquality/selenium/core/elements/RelativeElementFinder.java b/src/main/java/aquality/selenium/core/elements/RelativeElementFinder.java index 847114a..8339451 100644 --- a/src/main/java/aquality/selenium/core/elements/RelativeElementFinder.java +++ b/src/main/java/aquality/selenium/core/elements/RelativeElementFinder.java @@ -6,6 +6,7 @@ import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeoutException; @@ -27,15 +28,14 @@ public RelativeElementFinder(ILocalizedLogger localizedLogger, IConditionalWait } @Override - public List findElements(By locator, DesiredState desiredState, Long timeoutInSeconds) { + public List findElements(By locator, DesiredState desiredState, Duration timeout) { AtomicBoolean wasAnyElementFound = new AtomicBoolean(false); List resultElements = new ArrayList<>(); try { conditionalWait.waitForTrue(() -> tryToFindElements(locator, desiredState, wasAnyElementFound, resultElements, searchContextSupplier.get()), - timeoutInSeconds, - null); + timeout); } catch (TimeoutException e) { handleTimeoutException(new org.openqa.selenium.TimeoutException(e.getMessage(), e), locator, desiredState, wasAnyElementFound.get()); 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 ead0444..1240daa 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElement.java @@ -3,9 +3,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.remote.RemoteWebElement; -/** - * Describes behavior of any UI element. - */ +import java.time.Duration; + public interface IElement extends IParent { /** * Gets unique locator of element. @@ -46,7 +45,7 @@ default RemoteWebElement getElement() { * @param timeout Timeout for waiting * @return instance of {@link RemoteWebElement} if found. */ - RemoteWebElement getElement(Long timeout); + RemoteWebElement getElement(Duration timeout); /** * Gets the item text (inner text). diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IElementCacheHandler.java b/src/main/java/aquality/selenium/core/elements/interfaces/IElementCacheHandler.java index 0239153..e384b9b 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IElementCacheHandler.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElementCacheHandler.java @@ -3,6 +3,8 @@ import aquality.selenium.core.elements.ElementState; import org.openqa.selenium.remote.RemoteWebElement; +import java.time.Duration; + /** * Allows to use cached element. */ @@ -27,6 +29,7 @@ default boolean isRefreshNeeded() { /** * Determines is the element stale. + * * @return true if the element was found previously and is currently stale, false otherwise. */ default boolean isStale() { @@ -35,6 +38,7 @@ default boolean isStale() { /** * Determines was the element cached previously. + * * @return true if the element was found and cached previously, false otherwise. */ boolean wasCached(); @@ -42,19 +46,19 @@ default boolean isStale() { /** * Allows to get cached element. * - * @param timeout timeout used to retrive the element when {@see isRefreshNeeded()} is true. + * @param timeout timeout used to retrive the element when {@link #isRefreshNeeded()} is true. * @param customState custom element's existance state used for search. * @return cached element. */ - RemoteWebElement getElement(Long timeout, ElementState customState); + RemoteWebElement getElement(Duration timeout, ElementState customState); /** * Allows to get cached element. * - * @param timeout timeout used to retrive the element when {@see isRefreshNeeded()} is true. + * @param timeout timeout used to retrive the element when {@link #isRefreshNeeded()} is true. * @return cached element. */ - default RemoteWebElement getElement(Long timeout) { + default RemoteWebElement getElement(Duration timeout) { return getElement(timeout, null); } diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IElementFinder.java b/src/main/java/aquality/selenium/core/elements/interfaces/IElementFinder.java index 400432e..f4fcc01 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IElementFinder.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElementFinder.java @@ -6,6 +6,7 @@ import org.openqa.selenium.SearchContext; import org.openqa.selenium.WebElement; +import java.time.Duration; import java.util.List; import java.util.function.Predicate; @@ -40,14 +41,14 @@ default DesiredState resolveState(ElementState state) { /** * Finds element in desired {@link ElementState} * - * @param locator elements locator - * @param state desired {@link ElementState} - * @param timeoutInSeconds timeout for search + * @param locator elements locator + * @param state desired {@link ElementState} + * @param timeout timeout for search * @return found element * @throws org.openqa.selenium.NoSuchElementException if element was not found in time in desired state */ - default WebElement findElement(By locator, ElementState state, Long timeoutInSeconds) { - return findElements(locator, resolveState(state).withThrowingNoSuchElementException(), timeoutInSeconds).get(0); + default WebElement findElement(By locator, ElementState state, Duration timeout) { + return findElements(locator, resolveState(state).withThrowingNoSuchElementException(), timeout).get(0); } /** @@ -65,13 +66,13 @@ default WebElement findElement(By locator, ElementState state) { /** * Finds element in any state. * - * @param locator elements locator - * @param timeoutInSeconds timeout for search + * @param locator elements locator + * @param timeout timeout for search * @return found element * @throws org.openqa.selenium.NoSuchElementException if element was not found in time */ - default WebElement findElement(By locator, Long timeoutInSeconds) { - return findElement(locator, ElementState.EXISTS_IN_ANY_STATE, timeoutInSeconds); + default WebElement findElement(By locator, Duration timeout) { + return findElement(locator, ElementState.EXISTS_IN_ANY_STATE, timeout); } /** @@ -90,14 +91,14 @@ default WebElement findElement(By locator) { * * @param locator elements locator * @param elementStateCondition predicate to define element state - * @param timeoutInSeconds timeout for search + * @param timeout timeout for search * @return found element * @throws org.openqa.selenium.NoSuchElementException if element was not found in time in desired state */ - default WebElement findElement(By locator, Predicate elementStateCondition, Long timeoutInSeconds) { + default WebElement findElement(By locator, Predicate elementStateCondition, Duration timeout) { DesiredState state = new DesiredState(elementStateCondition, "desired") .withThrowingNoSuchElementException(); - return findElements(locator, state, timeoutInSeconds).get(0); + return findElements(locator, state, timeout).get(0); } /** @@ -115,24 +116,24 @@ default WebElement findElement(By locator, Predicate elementStateCon /** * Finds elements in desired {@link ElementState}. * - * @param locator elements locator - * @param state desired {@link ElementState} - * @param timeoutInSeconds timeout for search + * @param locator elements locator + * @param state desired {@link ElementState} + * @param timeout timeout for search * @return list of found elements */ - default List findElements(By locator, ElementState state, Long timeoutInSeconds) { - return findElements(locator, resolveState(state).withCatchingTimeoutException(), timeoutInSeconds); + default List findElements(By locator, ElementState state, Duration timeout) { + return findElements(locator, resolveState(state).withCatchingTimeoutException(), timeout); } /** * Finds elements in any state. * - * @param locator elements locator - * @param timeoutInSeconds timeout for search + * @param locator elements locator + * @param timeout timeout for search * @return list of found elements */ - default List findElements(By locator, Long timeoutInSeconds) { - return findElements(locator, ElementState.EXISTS_IN_ANY_STATE, timeoutInSeconds); + default List findElements(By locator, Duration timeout) { + return findElements(locator, ElementState.EXISTS_IN_ANY_STATE, timeout); } /** @@ -160,13 +161,13 @@ default List findElements(By locator) { * Finds elements in state defined by predicate. * * @param locator elements locator - * @param timeoutInSeconds timeout for search + * @param timeout timeout for search * @param elementStateCondition predicate to define element state * @return list of found elements */ - default List findElements(By locator, Predicate elementStateCondition, Long timeoutInSeconds) { + default List findElements(By locator, Predicate elementStateCondition, Duration timeout) { DesiredState state = new DesiredState(elementStateCondition, "desired").withCatchingTimeoutException(); - return findElements(locator, state, timeoutInSeconds); + return findElements(locator, state, timeout); } /** @@ -183,12 +184,12 @@ default List findElements(By locator, Predicate elementS /** * Finds elements in state defined by {@link DesiredState}. * - * @param locator elements locator - * @param timeoutInSeconds timeout for search - * @param desiredState object with predicate to define element state + * @param locator elements locator + * @param timeout timeout for search + * @param desiredState object with predicate to define element state * @return list of found elements */ - List findElements(By locator, DesiredState desiredState, Long timeoutInSeconds); + List findElements(By locator, DesiredState desiredState, Duration timeout); /** * Finds elements in state defined by {@link DesiredState} with default timeout. diff --git a/src/main/java/aquality/selenium/core/elements/interfaces/IElementStateProvider.java b/src/main/java/aquality/selenium/core/elements/interfaces/IElementStateProvider.java index 980a1ff..c16ad68 100644 --- a/src/main/java/aquality/selenium/core/elements/interfaces/IElementStateProvider.java +++ b/src/main/java/aquality/selenium/core/elements/interfaces/IElementStateProvider.java @@ -1,5 +1,6 @@ package aquality.selenium.core.elements.interfaces; +import java.time.Duration; /** * Provides ability to define of element's state (whether it is displayed, exist or not) @@ -20,7 +21,7 @@ public interface IElementStateProvider { * @param timeout Timeout for waiting * @throws org.openqa.selenium.TimeoutException when timeout exceeded and element is not clickable. */ - void waitForClickable(Long timeout); + void waitForClickable(Duration timeout); /** * Waits for is element clickable on the form. @@ -45,7 +46,7 @@ default void waitForClickable() { * @param timeout Timeout for waiting * @return true if element displayed after waiting, false otherwise */ - boolean waitForDisplayed(Long timeout); + boolean waitForDisplayed(Duration timeout); /** * Waits for is element displayed on the form. @@ -63,7 +64,7 @@ default boolean waitForDisplayed() { * @param timeout Timeout for waiting * @return true if element displayed after waiting, false otherwise */ - boolean waitForNotDisplayed(Long timeout); + boolean waitForNotDisplayed(Duration timeout); /** @@ -89,7 +90,7 @@ default boolean waitForNotDisplayed() { * @param timeout Timeout for waiting * @return true if element exist after waiting, false otherwise */ - boolean waitForExist(Long timeout); + boolean waitForExist(Duration timeout); /** @@ -105,9 +106,10 @@ default boolean waitForExist() { /** * Waits until element does not exist in DOM (without visibility check). * + * @param timeout Timeout for waiting * @return true if element does not exist after waiting, false otherwise */ - boolean waitForNotExist(Long timeout); + boolean waitForNotExist(Duration timeout); /** * Waits until element does not exist in DOM (without visibility check). @@ -134,7 +136,7 @@ default boolean waitForNotExist() { * @return true if enabled * @throws org.openqa.selenium.NoSuchElementException when timeout exceeded and element not found. */ - boolean waitForEnabled(Long timeout); + boolean waitForEnabled(Duration timeout); /** @@ -151,10 +153,11 @@ default boolean waitForEnabled() { /** * Waits until element does not enabled in DOM * + * @param timeout Timeout for waiting * @return true if element does not enabled after waiting, false otherwise * @throws org.openqa.selenium.NoSuchElementException when timeout exceeded and element not found. */ - boolean waitForNotEnabled(Long timeout); + boolean waitForNotEnabled(Duration timeout); /** * Waits until element does not enabled in DOM diff --git a/src/main/java/aquality/selenium/core/utilities/ElementActionRetrier.java b/src/main/java/aquality/selenium/core/utilities/ElementActionRetrier.java index f8ac474..43ff8bb 100644 --- a/src/main/java/aquality/selenium/core/utilities/ElementActionRetrier.java +++ b/src/main/java/aquality/selenium/core/utilities/ElementActionRetrier.java @@ -35,7 +35,7 @@ public T doWithRetry(Supplier function) { } catch (Exception exception) { if (isExceptionHandled(exception) && retryAttemptsLeft != 0) { try { - Thread.sleep(retryConfiguration.getPollingInterval()); + Thread.sleep(retryConfiguration.getPollingInterval().toMillis()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } diff --git a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java index 79cc46b..96ad040 100644 --- a/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java +++ b/src/main/java/aquality/selenium/core/waitings/ConditionalWait.java @@ -13,7 +13,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Optional; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.BooleanSupplier; @@ -29,9 +28,9 @@ public ConditionalWait(Provider applicationProvider, ITimeoutConfi } @Override - public boolean waitFor(BooleanSupplier condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore) { + public boolean waitFor(BooleanSupplier condition, Duration timeout, Duration pollingInterval, String message, Collection> exceptionsToIgnore) { try { - waitForTrue(condition, timeoutInSeconds, pollingIntervalInMilliseconds, message, exceptionsToIgnore); + waitForTrue(condition, timeout, pollingInterval, message, exceptionsToIgnore); return true; } catch (TimeoutException e) { return false; @@ -39,10 +38,10 @@ public boolean waitFor(BooleanSupplier condition, Long timeoutInSeconds, Long po } @Override - public void waitForTrue(BooleanSupplier condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore) throws TimeoutException { + public void waitForTrue(BooleanSupplier condition, Duration timeout, Duration pollingInterval, String message, Collection> exceptionsToIgnore) throws TimeoutException { BooleanSupplier supplier = Optional.ofNullable(condition).orElseThrow(() -> new IllegalArgumentException("Condition cannot be null")); - Long timeout = resolveConditionTimeout(timeoutInSeconds); - Long pollingInterval = resolvePollingInterval(pollingIntervalInMilliseconds); + long timeoutInSeconds = resolveConditionTimeoutInSeconds(timeout); + long pollingIntervalInMilliseconds = resolvePollingInterval(pollingInterval).toMillis(); String exMessage = resolveMessage(message); double startTime = getCurrentTime(); while (true) { @@ -51,13 +50,13 @@ public void waitForTrue(BooleanSupplier condition, Long timeoutInSeconds, Long p } double currentTime = getCurrentTime(); - if ((currentTime - startTime) > timeout) { - String exceptionMessage = String.format("Timed out after %1$s seconds during wait for condition '%2$s'", timeout, exMessage); + if ((currentTime - startTime) > timeoutInSeconds) { + String exceptionMessage = String.format("Timed out after %1$s seconds during wait for condition '%2$s'", timeoutInSeconds, exMessage); throw new TimeoutException(exceptionMessage); } try { - Thread.sleep(pollingInterval); + Thread.sleep(pollingIntervalInMilliseconds); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } @@ -65,20 +64,20 @@ public void waitForTrue(BooleanSupplier condition, Long timeoutInSeconds, Long p } @Override - public T waitFor(ExpectedCondition condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore) { + public T waitFor(ExpectedCondition condition, Duration timeout, Duration pollingInterval, String message, Collection> exceptionsToIgnore) { IApplication app = applicationProvider.get(); - app.setImplicitWaitTimeout(0, TimeUnit.SECONDS); - Long timeout = resolveConditionTimeout(timeoutInSeconds); - Long pollingInterval = resolvePollingInterval(pollingIntervalInMilliseconds); + app.setImplicitWaitTimeout(Duration.ZERO); + long timeoutInSeconds = resolveConditionTimeoutInSeconds(timeout); + Duration actualPollingInterval = resolvePollingInterval(pollingInterval); String exMessage = resolveMessage(message); - WebDriverWait wait = new WebDriverWait(app.getDriver(), timeout); - wait.pollingEvery(Duration.ofMillis(pollingInterval)); + WebDriverWait wait = new WebDriverWait(app.getDriver(), timeoutInSeconds); + wait.pollingEvery(actualPollingInterval); wait.withMessage(exMessage); wait.ignoreAll(exceptionsToIgnore == null ? Collections.singleton(StaleElementReferenceException.class) : exceptionsToIgnore); try { return wait.until(condition); } finally { - app.setImplicitWaitTimeout(timeoutConfiguration.getImplicit(), TimeUnit.SECONDS); + app.setImplicitWaitTimeout(timeoutConfiguration.getImplicit()); } } @@ -98,12 +97,12 @@ private boolean isConditionSatisfied(BooleanSupplier condition, Collection> exceptionsToIgnore) { - return waitFor(condition, timeoutInSeconds, pollingIntervalInMilliseconds, null, exceptionsToIgnore); + default boolean waitFor(BooleanSupplier condition, Duration timeout, Duration pollingInterval, String message) { + return waitFor(condition, timeout, pollingInterval, message, null); } /** * Wait for some condition within timeout. Method does not use WebDriverWait * - * @param condition Condition with boolean result (predicate) - * @param timeoutInSeconds Condition timeout - * @param pollingIntervalInMilliseconds Condition check interval - * @param message Part of error message in case of Timeout exception - * @param exceptionsToIgnore Exceptions to ignore + * @param condition Condition with boolean result (predicate) + * @param timeout Condition timeout + * @param pollingInterval Condition check interval + * @param exceptionsToIgnore Exceptions to ignore + * @return true if the condition has been met during the timeout + */ + default boolean waitFor(BooleanSupplier condition, Duration timeout, Duration pollingInterval, Collection> exceptionsToIgnore) { + return waitFor(condition, timeout, pollingInterval, null, exceptionsToIgnore); + } + + /** + * Wait for some condition within timeout. Method does not use WebDriverWait + * + * @param condition Condition with boolean result (predicate) + * @param timeout Condition timeout + * @param pollingInterval Condition check interval + * @param message Part of error message in case of Timeout exception + * @param exceptionsToIgnore Exceptions to ignore * @return true if the condition has been met during the timeout */ - boolean waitFor(BooleanSupplier condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore); + boolean waitFor(BooleanSupplier condition, Duration timeout, Duration pollingInterval, String message, Collection> exceptionsToIgnore); /** * Wait for some condition within timeout. Method does not use WebDriverWait @@ -161,53 +173,64 @@ default void waitForTrue(BooleanSupplier condition, String message, Collection> exceptionsToIgnore) throws TimeoutException { - waitForTrue(condition, timeoutInSeconds, pollingIntervalInMilliseconds, null, exceptionsToIgnore); + default void waitForTrue(BooleanSupplier condition, Duration timeout, Duration pollingInterval, String message) throws TimeoutException { + waitForTrue(condition, timeout, pollingInterval, message, null); + } + + /** + * Wait for some condition within timeout. Method does not use WebDriverWait + * + * @param condition Condition with boolean result (predicate) + * @param timeout Condition timeout + * @param pollingInterval Condition check interval + * @param exceptionsToIgnore Exceptions to ignore + * @throws TimeoutException will be thrown in case if timeout is over but condition was not met + */ + default void waitForTrue(BooleanSupplier condition, Duration timeout, Duration pollingInterval, Collection> exceptionsToIgnore) throws TimeoutException { + waitForTrue(condition, timeout, pollingInterval, null, exceptionsToIgnore); } /** * Wait for some condition within timeout. Method does not use WebDriverWait * - * @param condition Condition with boolean result (predicate) - * @param timeoutInSeconds Condition timeout - * @param pollingIntervalInMilliseconds Condition check interval - * @param message Part of error message in case of Timeout exception - * @param exceptionsToIgnore Exceptions to ignore + * @param condition Condition with boolean result (predicate) + * @param timeout Condition timeout + * @param pollingInterval Condition check interval + * @param message Part of error message in case of Timeout exception + * @param exceptionsToIgnore Exceptions to ignore * @throws TimeoutException will be thrown in case if timeout is over but condition was not met */ - void waitForTrue(BooleanSupplier condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore) throws TimeoutException; + void waitForTrue(BooleanSupplier condition, Duration timeout, Duration pollingInterval, String message, Collection> exceptionsToIgnore) throws TimeoutException; /** * Waits for function will be true or return some except false. @@ -267,55 +290,68 @@ default T waitFor(ExpectedCondition condition, String message, Collection * Waits for function will be true or return some except false. * StaleElementReferenceException will be handled by default * - * @param condition Function for waiting {@link Function} - * @param timeOutInSeconds Time-out in seconds - * @param pollingIntervalInMilliseconds interval in milliseconds between checks whether condition match - * @param Type of object which is waiting + * @param condition Function for waiting {@link Function} + * @param timeout Duration before the time-out + * @param pollingInterval interval between checks whether condition match + * @param Type of object which is waiting * @return Object which waiting for or null - is exceptions occured */ - default T waitFor(ExpectedCondition condition, Long timeOutInSeconds, Long pollingIntervalInMilliseconds) { - return waitFor(condition, timeOutInSeconds, pollingIntervalInMilliseconds, null, null); + default T waitFor(ExpectedCondition condition, Duration timeout, Duration pollingInterval) { + return waitFor(condition, timeout, pollingInterval, null, null); } /** * Waits for function will be true or return some except false. * StaleElementReferenceException will be handled by default * - * @param condition Function for waiting {@link Function} - * @param timeoutInSeconds Time-out in seconds - * @param pollingIntervalInMilliseconds interval in milliseconds between checks whether condition match - * @param message the message that will be added to an error in case if the condition is not matched during the timeout - * @param Type of object which is waiting + * @param condition Function for waiting {@link Function} + * @param timeout Duration before the time-out + * @param Type of object which is waiting * @return Object which waiting for or null - is exceptions occured */ - default T waitFor(ExpectedCondition condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message) { - return waitFor(condition, timeoutInSeconds, pollingIntervalInMilliseconds, message, null); + default T waitFor(ExpectedCondition condition, Duration timeout) { + return waitFor(condition, timeout, null); } /** * Waits for function will be true or return some except false. + * StaleElementReferenceException will be handled by default * - * @param condition Function for waiting {@link Function} - * @param timeoutInSeconds Time-out in seconds - * @param pollingIntervalInMilliseconds interval in milliseconds between checks whether condition match - * @param exceptionsToIgnore list of exceptions that should be ignored during waiting - * @param Type of object which is waiting + * @param condition Function for waiting {@link Function} + * @param timeout Duration before the time-out + * @param pollingInterval interval between checks whether condition match + * @param message the message that will be added to an error in case if the condition is not matched during the timeout + * @param Type of object which is waiting * @return Object which waiting for or null - is exceptions occured */ - default T waitFor(ExpectedCondition condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, Collection> exceptionsToIgnore) { - return waitFor(condition, timeoutInSeconds, pollingIntervalInMilliseconds, null, exceptionsToIgnore); + default T waitFor(ExpectedCondition condition, Duration timeout, Duration pollingInterval, String message) { + return waitFor(condition, timeout, pollingInterval, message, null); } /** * Waits for function will be true or return some except false. * - * @param condition Function for waiting {@link Function} - * @param timeoutInSeconds Time-out in seconds - * @param pollingIntervalInMilliseconds interval in milliseconds between checks whether condition match - * @param message the message that will be added to an error in case if the condition is not matched during the timeout - * @param exceptionsToIgnore list of exceptions that should be ignored during waiting - * @param Type of object which is waiting + * @param condition Function for waiting {@link Function} + * @param timeout Duration before the time-out + * @param pollingInterval interval between checks whether condition match + * @param exceptionsToIgnore list of exceptions that should be ignored during waiting + * @param Type of object which is waiting + * @return Object which waiting for or null - is exceptions occured + */ + default T waitFor(ExpectedCondition condition, Duration timeout, Duration pollingInterval, Collection> exceptionsToIgnore) { + return waitFor(condition, timeout, pollingInterval, null, exceptionsToIgnore); + } + + /** + * Waits for function will be true or return some except false. + * + * @param condition Function for waiting {@link Function} + * @param timeout Duration before the time-out + * @param pollingInterval interval between checks whether condition match + * @param message the message that will be added to an error in case if the condition is not matched during the timeout + * @param exceptionsToIgnore list of exceptions that should be ignored during waiting + * @param Type of object which is waiting * @return Object which waiting for or null - is exceptions occured */ - T waitFor(ExpectedCondition condition, Long timeoutInSeconds, Long pollingIntervalInMilliseconds, String message, Collection> exceptionsToIgnore); + T waitFor(ExpectedCondition condition, Duration timeout, Duration pollingInterval, String message, Collection> exceptionsToIgnore); } diff --git a/src/test/java/tests/applications/IApplicationTests.java b/src/test/java/tests/applications/IApplicationTests.java index 71c0e4a..88b8571 100644 --- a/src/test/java/tests/applications/IApplicationTests.java +++ b/src/test/java/tests/applications/IApplicationTests.java @@ -6,7 +6,7 @@ import org.testng.annotations.Test; import tests.ITestWithApplication; -import java.util.concurrent.TimeUnit; +import java.time.Duration; public interface IApplicationTests extends ITestWithApplication { Injector getServiceProvider(); @@ -32,7 +32,7 @@ default void testShouldBePossibleToSetImplicitWait() { default void checkImplicitWaitSetting(int valueInSeconds) { try { - getApplication().setImplicitWaitTimeout(1, TimeUnit.SECONDS); + getApplication().setImplicitWaitTimeout(Duration.ofSeconds(1)); } catch (Throwable e){ Assert.fail("An error occured when tried to set implicit wait", e); } diff --git a/src/test/java/tests/applications/browser/ChromeApplication.java b/src/test/java/tests/applications/browser/ChromeApplication.java index 950c139..c7bccac 100644 --- a/src/test/java/tests/applications/browser/ChromeApplication.java +++ b/src/test/java/tests/applications/browser/ChromeApplication.java @@ -5,15 +5,16 @@ import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.RemoteWebDriver; +import java.time.Duration; import java.util.concurrent.TimeUnit; public class ChromeApplication implements IApplication { - private long implicitWaitSeconds; + private Duration implicitWait; private final RemoteWebDriver driver; - public ChromeApplication(long implicitWaitSeconds) { + ChromeApplication(long implicitWaitSeconds) { driver = new ChromeDriver(new ChromeOptions().setHeadless(true)); - setImplicitWaitTimeout(implicitWaitSeconds, TimeUnit.SECONDS); + setImplicitWaitTimeout(Duration.ofSeconds(implicitWaitSeconds)); } @Override @@ -27,11 +28,10 @@ public boolean isStarted() { } @Override - public void setImplicitWaitTimeout(long value, TimeUnit timeUnit) { - long valueInSeconds = TimeUnit.SECONDS.convert(value, timeUnit); - if (implicitWaitSeconds != valueInSeconds){ - driver.manage().timeouts().implicitlyWait(value, timeUnit); - implicitWaitSeconds = valueInSeconds; + public void setImplicitWaitTimeout(Duration value) { + if (implicitWait != value){ + driver.manage().timeouts().implicitlyWait(value.getSeconds(), TimeUnit.SECONDS); + implicitWait = value; } } } diff --git a/src/test/java/tests/applications/windowsApp/WindowsApplication.java b/src/test/java/tests/applications/windowsApp/WindowsApplication.java index 0971e29..00c2f73 100644 --- a/src/test/java/tests/applications/windowsApp/WindowsApplication.java +++ b/src/test/java/tests/applications/windowsApp/WindowsApplication.java @@ -7,17 +7,18 @@ import org.openqa.selenium.remote.RemoteWebDriver; import java.net.URL; +import java.time.Duration; import java.util.concurrent.TimeUnit; public class WindowsApplication implements IApplication { private long implicitWaitSeconds; private final RemoteWebDriver driver; - public WindowsApplication(long implicitWaitSeconds, String appPath, URL serviceUrl) { + WindowsApplication(long implicitWaitSeconds, String appPath, URL serviceUrl) { DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("app", appPath); driver = new WindowsDriver(serviceUrl, capabilities); - setImplicitWaitTimeout(implicitWaitSeconds, TimeUnit.SECONDS); + setImplicitWaitTimeout(Duration.ofSeconds(implicitWaitSeconds)); } @Override @@ -31,10 +32,10 @@ public boolean isStarted() { } @Override - public void setImplicitWaitTimeout(long value, TimeUnit timeUnit) { - long valueInSeconds = TimeUnit.SECONDS.convert(value, timeUnit); + public void setImplicitWaitTimeout(Duration value) { + long valueInSeconds = value.getSeconds(); if (implicitWaitSeconds != valueInSeconds){ - driver.manage().timeouts().implicitlyWait(value, timeUnit); + driver.manage().timeouts().implicitlyWait(value.toMillis(), TimeUnit.MILLISECONDS); implicitWaitSeconds = valueInSeconds; } } diff --git a/src/test/java/tests/configurations/ConfigurationTests.java b/src/test/java/tests/configurations/ConfigurationTests.java index 80d1a9a..c074619 100644 --- a/src/test/java/tests/configurations/ConfigurationTests.java +++ b/src/test/java/tests/configurations/ConfigurationTests.java @@ -27,15 +27,15 @@ public void testShouldBePossibleToGetLanguage() { public void testShouldBePossibleToGetRetryConfiguration() { RetryConfiguration retryConfiguration = new RetryConfiguration(settingsFile); assertEquals(retryConfiguration.getNumber(), 2, "Number of retry attempts timeout should be got"); - assertEquals(retryConfiguration.getPollingInterval(), 300, "Polling interval of retrier should be got"); + assertEquals(retryConfiguration.getPollingInterval().toMillis(), 300, "Polling interval of retrier should be got"); } @Test public void testShouldBePossibleToGetTimeoutConfiguration() { TimeoutConfiguration timeoutConfiguration = new TimeoutConfiguration(settingsFile); - assertEquals(timeoutConfiguration.getCommand(), 60, "Command timeout should be got"); - assertEquals(timeoutConfiguration.getCondition(), 30, "Condition timeout should be got"); - assertEquals(timeoutConfiguration.getImplicit(), 0, "Implicit timeout should be got"); - assertEquals(timeoutConfiguration.getPollingInterval(), 300, "Polling interval should be got"); + assertEquals(timeoutConfiguration.getCommand().getSeconds(), 60, "Command timeout should be got"); + assertEquals(timeoutConfiguration.getCondition().getSeconds(), 30, "Condition timeout should be got"); + assertEquals(timeoutConfiguration.getImplicit().getSeconds(), 0, "Implicit timeout should be got"); + assertEquals(timeoutConfiguration.getPollingInterval().toMillis(), 300, "Polling interval should be got"); } } diff --git a/src/test/java/tests/configurations/EnvConfigurationTests.java b/src/test/java/tests/configurations/EnvConfigurationTests.java index 63dcf46..412e136 100644 --- a/src/test/java/tests/configurations/EnvConfigurationTests.java +++ b/src/test/java/tests/configurations/EnvConfigurationTests.java @@ -43,7 +43,7 @@ public void testShouldBePossibleToOverrideLanguageWithEnvVariable() { @Test public void testShouldBePossibleToOverrideTimeoutWithEnvVariable() { - long conditionTimeout = new TimeoutConfiguration(settingsFile).getCondition(); + long conditionTimeout = new TimeoutConfiguration(settingsFile).getCondition().getSeconds(); assertEquals(conditionTimeout, Long.parseLong(NEW_INT_VALUE), "Condition timeout should be overridden with env variable"); } diff --git a/src/test/java/tests/elements/ICachedElementTests.java b/src/test/java/tests/elements/ICachedElementTests.java index 933cc76..07349a6 100644 --- a/src/test/java/tests/elements/ICachedElementTests.java +++ b/src/test/java/tests/elements/ICachedElementTests.java @@ -3,12 +3,13 @@ import aquality.selenium.core.elements.interfaces.IElementStateProvider; import org.testng.annotations.DataProvider; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; public interface ICachedElementTests { - long ZERO_TIMEOUT = 0L; + Duration ZERO_TIMEOUT = Duration.ZERO; @DataProvider default Object[] stateFunctionsFalseWhenElementStale() { diff --git a/src/test/java/tests/elements/IElementFinderTests.java b/src/test/java/tests/elements/IElementFinderTests.java index c8c84c2..708969d 100644 --- a/src/test/java/tests/elements/IElementFinderTests.java +++ b/src/test/java/tests/elements/IElementFinderTests.java @@ -13,6 +13,8 @@ import tests.applications.windowsApp.AqualityServices; import tests.applications.windowsApp.CalculatorWindow; +import java.time.Duration; + public interface IElementFinderTests extends ITestWithApplication { IElementFinder getElementFinder(); @@ -29,12 +31,12 @@ default Object[] elementStates() { return ElementState.values(); } - default Long getCustomTimeout() { - return 10L; + default Duration getCustomTimeout() { + return Duration.ofSeconds(10L); } - default Long getSmallTimeout() { - return 1L; + default Duration getSmallTimeout() { + return Duration.ofSeconds(1L); } default By getAbsentLocator() { diff --git a/src/test/java/tests/elements/IWebElementStateProviderTests.java b/src/test/java/tests/elements/IWebElementStateProviderTests.java index 4614d56..d160fc9 100644 --- a/src/test/java/tests/elements/IWebElementStateProviderTests.java +++ b/src/test/java/tests/elements/IWebElementStateProviderTests.java @@ -12,6 +12,7 @@ import theinternet.DynamicLoadingForm; import theinternet.TheInternetPage; +import java.time.Duration; import java.util.function.Predicate; import static utils.TimeUtil.calculateDuration; @@ -19,7 +20,7 @@ public interface IWebElementStateProviderTests extends ITheInternetPageTest { double OPERATION_TIME = 5; - long CUSTOM_WAIT_TIME = 2L; + Duration CUSTOM_WAIT_TIME = Duration.ofSeconds(2L); By ABSENT_ELEMENT_LOCATOR = By.xpath("//div[@class='not exist element']"); default DynamicControlsForm getDynamicControlsForm() { @@ -32,34 +33,34 @@ default DynamicLoadingForm getDynamicLoadingForm() { IElementStateProvider state(By locator); - default long getConditionTimeout() { + default Duration getConditionTimeout() { return AqualityServices.get(ITimeoutConfiguration.class).getCondition(); } - default void checkWaitingTimeForInputState(Long waitTime, Predicate notExpectedCondition) { + default void checkWaitingTimeForInputState(Duration waitTime, Predicate notExpectedCondition) { long startTime = getCurrentTime(); boolean isConditionSatisfied = notExpectedCondition.test(getDynamicControlsForm().inputState()); double duration = calculateDuration(startTime); Assert.assertFalse(isConditionSatisfied); - Assert.assertTrue(duration >= waitTime && duration <= (waitTime + OPERATION_TIME)); + Assert.assertTrue(duration >= waitTime.getSeconds() && duration <= (waitTime.getSeconds() + OPERATION_TIME)); } @Test default void testElementShouldWaitForEnabledWithCustomTimeout() { - long waitTime = CUSTOM_WAIT_TIME; + Duration waitTime = CUSTOM_WAIT_TIME; checkWaitingTimeForInputState(waitTime, state -> state.waitForEnabled(waitTime)); } @Test default void testElementShouldWaitForEnabledWithDefaultTimeout() { - long waitTime = getConditionTimeout(); + Duration waitTime = getConditionTimeout(); checkWaitingTimeForInputState(waitTime, IElementStateProvider::waitForEnabled); } @Test default void testElementShouldWaitForNotEnabledWithCustomTimeout() { - long waitTime = CUSTOM_WAIT_TIME; + Duration waitTime = CUSTOM_WAIT_TIME; getDynamicControlsForm().clickEnable(); getDynamicControlsForm().inputState().waitForEnabled(); @@ -78,7 +79,7 @@ default void testNoSuchShouldBeThrownForWaitNotEnabledIfElementNotFound() { @Test default void testElementShouldWaitForNotEnabledWithDefaultTimeout() { - long waitTime = getConditionTimeout(); + Duration waitTime = getConditionTimeout(); getDynamicControlsForm().clickEnable(); getDynamicControlsForm().inputState().waitForEnabled(); @@ -120,7 +121,7 @@ default void testWaitForExist() { @Test default void testShouldBePossibleToWaitElementNotExistsCustomTime() { - long waitTime = CUSTOM_WAIT_TIME; + Duration waitTime = CUSTOM_WAIT_TIME; getDynamicControlsForm().clickRemove(); checkWaitingTimeForInputState(waitTime, inputState -> getDynamicControlsForm().checkboxState().waitForNotExist(waitTime)); @@ -128,7 +129,7 @@ default void testShouldBePossibleToWaitElementNotExistsCustomTime() { @Test default void testShouldBePossibleToWaitElementNotExists() { - long waitTime = getConditionTimeout(); + Duration waitTime = getConditionTimeout(); getDynamicControlsForm().clickRemove(); long startTime = getCurrentTime(); @@ -136,6 +137,6 @@ default void testShouldBePossibleToWaitElementNotExists() { double duration = calculateDuration(startTime); Assert.assertTrue(isMissed); - Assert.assertTrue(duration < waitTime); + Assert.assertTrue(duration < waitTime.getSeconds()); } } diff --git a/src/test/java/tests/elements/WebElementTests.java b/src/test/java/tests/elements/WebElementTests.java index 5aff7a2..59c94c9 100644 --- a/src/test/java/tests/elements/WebElementTests.java +++ b/src/test/java/tests/elements/WebElementTests.java @@ -14,6 +14,7 @@ import theinternet.InputsForm; import theinternet.TheInternetPage; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -60,7 +61,7 @@ public void testShouldBePossibleToGetElement() { @Test public void testShouldBePossibleToGetElementWithCustomTimeout() { getApplication().getDriver().navigate().to(TheInternetPage.DYNAMIC_CONTROLS.getAddress()); - RemoteWebElement element = DynamicControlsForm.getEnableButton().getElement(1L); + RemoteWebElement element = DynamicControlsForm.getEnableButton().getElement(Duration.ofSeconds(1L)); Assert.assertNotNull(element, "RemoteWebElement should not be null"); } diff --git a/src/test/java/tests/elements/WindowsElementTests.java b/src/test/java/tests/elements/WindowsElementTests.java index 649060e..4497397 100644 --- a/src/test/java/tests/elements/WindowsElementTests.java +++ b/src/test/java/tests/elements/WindowsElementTests.java @@ -12,6 +12,7 @@ import tests.applications.windowsApp.CalculatorWindow; import tests.elements.factory.CustomElement; +import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; @@ -56,7 +57,7 @@ public void testShouldBePossibleToGetElement() { @Test public void testShouldBePossibleToGetElementWithCustomTimeout() { - RemoteWebElement element = CalculatorWindow.getOneButton().getElement(1L); + RemoteWebElement element = CalculatorWindow.getOneButton().getElement(Duration.ofSeconds(1L)); Assert.assertNotNull(element, "RemoteWebElement should not be null"); } diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index 3faae3a..54ca965 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -23,7 +23,7 @@ public class ElementActionRetrierTests { private static final IRetryConfiguration RETRY_CONFIGURATION = AqualityServices.getServiceProvider().getInstance(IRetryConfiguration.class); private static final Logger LOGGER = AqualityServices.getServiceProvider().getInstance(Logger.class); private static final int RETRIES_COUNT = RETRY_CONFIGURATION.getNumber(); - private static final long POLLING_INTERVAL = RETRY_CONFIGURATION.getPollingInterval(); + private static final long POLLING_INTERVAL = RETRY_CONFIGURATION.getPollingInterval().toMillis(); private static final ElementActionRetrier ELEMENT_ACTION_RETRIER = new ElementActionRetrier(RETRY_CONFIGURATION); private static final long ACCURACY = 100; diff --git a/src/test/java/tests/waitings/BaseConditionalWaitTest.java b/src/test/java/tests/waitings/BaseConditionalWaitTest.java index cdd92af..552c2e0 100644 --- a/src/test/java/tests/waitings/BaseConditionalWaitTest.java +++ b/src/test/java/tests/waitings/BaseConditionalWaitTest.java @@ -8,14 +8,15 @@ import tests.applications.browser.AqualityServices; import utils.Timer; +import java.time.Duration; import java.util.Collection; import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; -class BaseConditionalWaitTest { - static final long waitForTimeoutCondition = 10; - static final long waitForTimeoutPolling = 150; +abstract class BaseConditionalWaitTest { + static final Duration waitForTimeoutCondition = Duration.ofSeconds(10); + static final Duration waitForTimeoutPolling = Duration.ofMillis(150); static final double accuracy = 2; static final Collection> ignoredExceptions = Collections.singleton(IllegalStateException.class); ThreadLocal timer = ThreadLocal.withInitial(Timer::new); diff --git a/src/test/java/tests/waitings/WaitForObjectTests.java b/src/test/java/tests/waitings/WaitForObjectTests.java index b3282da..949b7d4 100644 --- a/src/test/java/tests/waitings/WaitForObjectTests.java +++ b/src/test/java/tests/waitings/WaitForObjectTests.java @@ -8,6 +8,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.time.Duration; import java.util.Collections; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicBoolean; @@ -38,15 +39,15 @@ public Object[][] failWaitForAction() { } @Test(dataProvider = "failWaitForAction") - public void testShouldThrowTimeoutExceptionIfConditionIsNotMetAndTimeoutIsOver(Callable failedAction, long timeout, double pollingInterval) throws Exception { + public void testShouldThrowTimeoutExceptionIfConditionIsNotMetAndTimeoutIsOver(Callable failedAction, Duration timeout, Duration pollingInterval) throws Exception { timer.get().start(); try { failedAction.call(); Assert.fail("TimeoutException should be thrown but not"); } catch (TimeoutException e) { double duration = timer.get().stop(); - double interval = timeout + pollingInterval / 1000 + accuracy; - double accuracyTimeout = timeout - SELENIUM_ACCURACY; + double interval = timeout.getSeconds() + pollingInterval.getSeconds() + accuracy; + double accuracyTimeout = timeout.getSeconds() - 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, accuracyTimeout, interval)); @@ -59,11 +60,11 @@ public Object[][] successWaitForAction() { } @Test(dataProvider = "successWaitForAction") - public void testShouldReturnAnObjectIfConditionIsMetAndTimeoutIsNotOver(Callable successAction, long timeout, double pollingInterval) throws Exception { + public void testShouldReturnAnObjectIfConditionIsMetAndTimeoutIsNotOver(Callable successAction, Duration timeout, Duration pollingInterval) throws Exception { timer.get().start(); String result = successAction.call(); double duration = timer.get().stop(); - double accuracyPollingInterval = pollingInterval / 1000 + accuracy; + double accuracyPollingInterval = pollingInterval.getSeconds() + accuracy; assertTrue(duration < accuracyPollingInterval, String.format("Duration '%s' should be less than accuracy polling interval '%s'", duration, accuracyPollingInterval)); @@ -78,14 +79,14 @@ public Object[][] throwWaitForAction() { } @Test(dataProvider = "throwWaitForAction") - public void testShouldThrowException(Callable throwAction, long timeout, double pollingInterval) throws Exception { + public void testShouldThrowException(Callable throwAction, Duration timeout, Duration pollingInterval) throws Exception { try { timer.get().start(); throwAction.call(); Assert.fail("IllegalArgumentException should be thrown but not"); } catch (IllegalArgumentException e) { double duration = timer.get().stop(); - double accuracyPollingInterval = pollingInterval / 1000 + accuracy; + double accuracyPollingInterval = pollingInterval.getSeconds() + accuracy; assertTrue(duration < accuracyPollingInterval, String.format("Duration '%s' should be less than accuracy polling interval '%s'", duration, accuracyPollingInterval)); @@ -121,11 +122,11 @@ public void testShouldIgnoreExceptionWaitingWithCustomTimeout() { checkWaitForMethodForPassedCondition(actionWithAllParameters, waitForTimeoutPolling); } - private void checkWaitForMethodForPassedCondition(BooleanSupplier waitAction, double pollingInterval) { + private void checkWaitForMethodForPassedCondition(BooleanSupplier waitAction, Duration pollingInterval) { timer.get().start(); boolean result = waitAction.getAsBoolean(); double duration = timer.get().stop(); - double doubleAccuracyPollingInterval = 2 * pollingInterval / 1000 + accuracy; + double doubleAccuracyPollingInterval = 2 * pollingInterval.getSeconds() + accuracy; assertTrue(result, "waitFor should return true when condition is satisfied."); assertTrue(duration < doubleAccuracyPollingInterval, String.format("Duration '%s' should be less than double accuracy polling interval '%s'", diff --git a/src/test/java/tests/waitings/WaitForTests.java b/src/test/java/tests/waitings/WaitForTests.java index 5b634de..944bfc1 100644 --- a/src/test/java/tests/waitings/WaitForTests.java +++ b/src/test/java/tests/waitings/WaitForTests.java @@ -4,6 +4,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.time.Duration; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BooleanSupplier; @@ -19,15 +20,15 @@ public Object[][] falseWaitForAction() { } @Test(dataProvider = "falseWaitForAction") - public void testFalseShouldBeReturnedIfConditionIsNotMetAndTimeoutIsOver(BooleanSupplier waitAction, long timeout, double pollingInterval) { + public void testFalseShouldBeReturnedIfConditionIsNotMetAndTimeoutIsOver(BooleanSupplier waitAction, Duration timeout, Duration pollingInterval) { timer.get().start(); boolean result = waitAction.getAsBoolean(); double duration = timer.get().stop(); - double accuracyPollingInterval = timeout + pollingInterval / 1000 + accuracy; + double accuracyPollingInterval = timeout.getSeconds() + pollingInterval.getSeconds() + accuracy; assertFalse(result, "waitFor should return false when condition is not satisfied."); - assertTrue(duration >= timeout && duration < accuracyPollingInterval, + assertTrue(duration >= timeout.getSeconds() && duration < accuracyPollingInterval, String.format("Duration '%s' should be between '%s' and '%s' (timeout and (timeout + pollingInterval + accuracy)) when condition is not satisfied.", - duration, timeout, accuracyPollingInterval)); + duration, timeout.getSeconds(), accuracyPollingInterval)); } @DataProvider(name = "trueWaitForAction") @@ -36,8 +37,8 @@ public Object[][] trueWaitForAction() { } @Test(dataProvider = "trueWaitForAction") - public void testTrueShouldBeReturnedIfConditionIsMetAndTimeoutIsNotOver(BooleanSupplier waitAction, long timeout, double pollingInterval) { - double checkedTimeout = pollingInterval / 1000 + accuracy; + public void testTrueShouldBeReturnedIfConditionIsMetAndTimeoutIsNotOver(BooleanSupplier waitAction, Duration timeout, Duration pollingInterval) { + double checkedTimeout = pollingInterval.getSeconds() + accuracy; checkWaitForMethodForPassedCondition(waitAction, checkedTimeout); } @@ -45,7 +46,7 @@ public void testTrueShouldBeReturnedIfConditionIsMetAndTimeoutIsNotOver(BooleanS public void testShouldIgnoreExceptionForWaitingWithoutCustomParameters() { AtomicBoolean atomicBoolean = new AtomicBoolean(true); BooleanSupplier actionWithExceptions = () -> conditionalWait.waitFor(throwNewException(atomicBoolean), ignoredExceptions); - double checkedTimeout = (double) timeoutConfiguration.getPollingInterval() * 2 / 1000 + accuracy; + double checkedTimeout = (double) timeoutConfiguration.getPollingInterval().getSeconds() * 2 + accuracy; checkWaitForMethodForPassedCondition(actionWithExceptions, checkedTimeout); } @@ -53,7 +54,7 @@ public void testShouldIgnoreExceptionForWaitingWithoutCustomParameters() { public void testShouldIgnoreExceptionForWaitingWithDefaultTimeout() { AtomicBoolean atomicBoolean = new AtomicBoolean(true); BooleanSupplier actionWithMessageAndExceptions = () -> conditionalWait.waitFor(throwNewException(atomicBoolean), "Condition should be true", ignoredExceptions); - double checkedTimeout = (double) timeoutConfiguration.getPollingInterval() * 2 / 1000 + accuracy; + double checkedTimeout = (double) timeoutConfiguration.getPollingInterval().getSeconds() * 2 + accuracy; checkWaitForMethodForPassedCondition(actionWithMessageAndExceptions, checkedTimeout); } @@ -61,7 +62,7 @@ public void testShouldIgnoreExceptionForWaitingWithDefaultTimeout() { public void testShouldIgnoreExceptionWaitingWithCustomTimeoutAndException() { AtomicBoolean atomicBoolean = new AtomicBoolean(true); BooleanSupplier actionWithAllParameters = () -> conditionalWait.waitFor(throwNewException(atomicBoolean), waitForTimeoutCondition, waitForTimeoutPolling, ignoredExceptions); - double checkedTimeout = (double) waitForTimeoutPolling * 2 / 1000 + accuracy; + double checkedTimeout = (double) waitForTimeoutPolling.getSeconds() * 2 + accuracy; checkWaitForMethodForPassedCondition(actionWithAllParameters, checkedTimeout); } @@ -69,7 +70,7 @@ public void testShouldIgnoreExceptionWaitingWithCustomTimeoutAndException() { public void testShouldIgnoreExceptionWaitingWithCustomTimeout() { AtomicBoolean atomicBoolean = new AtomicBoolean(true); BooleanSupplier actionWithAllParameters = () -> conditionalWait.waitFor(throwNewException(atomicBoolean), waitForTimeoutCondition, waitForTimeoutPolling, "Condition should be true", ignoredExceptions); - double checkedTimeout = (double) waitForTimeoutPolling * 2 / 1000 + accuracy; + double checkedTimeout = (double) waitForTimeoutPolling.getSeconds() * 2 + accuracy; checkWaitForMethodForPassedCondition(actionWithAllParameters, checkedTimeout); } @@ -92,7 +93,7 @@ public Object[][] throwExceptionAction() { } @Test(dataProvider = "throwExceptionAction", expectedExceptions = StaleElementReferenceException.class) - public void testShouldThrowException(BooleanSupplier waitAction, long timeout, double pollingInterval) { + public void testShouldThrowException(BooleanSupplier waitAction, Duration timeout, Duration pollingInterval) { waitAction.getAsBoolean(); } diff --git a/src/test/java/tests/waitings/WaitForTrueTests.java b/src/test/java/tests/waitings/WaitForTrueTests.java index 0699f68..56c0f2e 100644 --- a/src/test/java/tests/waitings/WaitForTrueTests.java +++ b/src/test/java/tests/waitings/WaitForTrueTests.java @@ -5,6 +5,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.time.Duration; import java.util.Collections; import java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; @@ -21,15 +22,15 @@ public Object[][] falseWaitForAction() { } @Test(dataProvider = "falseWaitForTrueAction") - public void testTimeoutExceptionShouldBeThrownIfConditionIsMetAndTimeoutIsOver(Callable waitForTrueAction, long timeout, double pollingInterval) throws Exception { + public void testTimeoutExceptionShouldBeThrownIfConditionIsMetAndTimeoutIsOver(Callable waitForTrueAction, Duration timeout, Duration pollingInterval) throws Exception { timer.get().start(); try { waitForTrueAction.call(); Assert.fail("TimeoutException should be thrown but not"); } catch (TimeoutException e) { double duration = timer.get().stop(); - double accuracyPollingInterval = timeout + pollingInterval / 1000 + accuracy; - assertTrue(duration >= timeout && duration < accuracyPollingInterval, + double accuracyPollingInterval = timeout.getSeconds() + pollingInterval.getSeconds() + accuracy; + assertTrue(duration >= timeout.getSeconds() && duration < accuracyPollingInterval, String.format("Duration '%s' should be between '%s' and '%s' (timeout and (timeout + pollingInterval + accuracy)) when condition is not satisfied.", duration, timeout, accuracyPollingInterval)); } @@ -41,11 +42,11 @@ public Object[][] successWaitForAction() { } @Test(dataProvider = "successWaitForAction") - public void testTimeoutExceptionShouldNotBeThrownIfConditionIsMetAndTimeoutIsNotOver(Callable waitForTrueAction, long timeout, double pollingInterval) throws Exception { + public void testTimeoutExceptionShouldNotBeThrownIfConditionIsMetAndTimeoutIsNotOver(Callable waitForTrueAction, Duration timeout, Duration pollingInterval) throws Exception { timer.get().start(); waitForTrueAction.call(); double duration = timer.get().stop(); - double accuracyPollingInterval = pollingInterval / 1000 + accuracy; + double accuracyPollingInterval = pollingInterval.getSeconds() + accuracy; assertTrue(duration < accuracyPollingInterval, String.format("Duration '%s' should be less than accuracy polling interval '%s'", duration, accuracyPollingInterval)); } @@ -59,7 +60,7 @@ public Object[][] throwExceptionAction() { } @Test(dataProvider = "throwExceptionAction") - public void testCustomExceptionShouldBeThrown(Callable waitForTrueAction, long timeout, double pollingInterval) throws Exception { + public void testCustomExceptionShouldBeThrown(Callable waitForTrueAction, Duration timeout, Duration pollingInterval) throws Exception { try { timer.get().start(); @@ -67,7 +68,7 @@ public void testCustomExceptionShouldBeThrown(Callable waitForTrueAction, long t Assert.fail("StaleElementReferenceException should be thrown but not"); } catch (StaleElementReferenceException e) { double duration = timer.get().stop(); - double accuracyPollingInterval = pollingInterval / 1000 + accuracy; + double accuracyPollingInterval = pollingInterval.getSeconds() + accuracy; assertTrue(duration < accuracyPollingInterval, String.format("Duration '%s' should be less than accuracy polling interval '%s'", duration, accuracyPollingInterval)); } @@ -114,11 +115,11 @@ public void testCustomExceptionShouldBeIgnoredWithCustomTimeout() throws Excepti }, waitForTimeoutPolling); } - private void checkExceptionIsIgnored(Callable waitForTrueAction, double pollingInterval) throws Exception { + private void checkExceptionIsIgnored(Callable waitForTrueAction, Duration pollingInterval) throws Exception { timer.get().start(); waitForTrueAction.call(); double duration = timer.get().stop(); - double doubleAccuracyPollingInterval = 2 * pollingInterval / 1000 + accuracy; + double doubleAccuracyPollingInterval = 2 * pollingInterval.getSeconds() + accuracy; assertTrue(duration < doubleAccuracyPollingInterval, String.format("Duration '%s' should be less than double accuracy polling interval '%s'", duration, doubleAccuracyPollingInterval)); diff --git a/src/test/java/theinternet/DynamicLoadingForm.java b/src/test/java/theinternet/DynamicLoadingForm.java index c36c11e..aa903a5 100644 --- a/src/test/java/theinternet/DynamicLoadingForm.java +++ b/src/test/java/theinternet/DynamicLoadingForm.java @@ -6,13 +6,14 @@ import org.openqa.selenium.By; import tests.applications.browser.CachedLabel; +import java.time.Duration; import java.util.function.Function; import java.util.function.Supplier; public class DynamicLoadingForm extends BaseForm { - private static final long DEFAULT_LOADING_TIMEOUT = 5L; - private static final long SMALL_LOADING_TIMEOUT = 2L; + private static final Duration DEFAULT_LOADING_TIMEOUT = Duration.ofSeconds(5L); + private static final Duration SMALL_LOADING_TIMEOUT = Duration.ofSeconds(2L); private static final By LOADING_LABEL_LOCATOR = By.id("loading"); private static final By START_BUTTON_LOCATOR = By.xpath("//div[@id='start']/button"); @@ -28,11 +29,11 @@ public static CachedLabel getStartLabel() { return new CachedLabel(START_BUTTON_LOCATOR, ElementState.DISPLAYED); } - public long getTimeout() { + public Duration getTimeout() { return DEFAULT_LOADING_TIMEOUT; } - public long getSmallTimeout() { + public Duration getSmallTimeout() { return SMALL_LOADING_TIMEOUT; }