diff --git a/core/src/main/java/net/serenitybdd/core/pages/WebElementFacade.java b/core/src/main/java/net/serenitybdd/core/pages/WebElementFacade.java index ab51547051..2333ed2839 100644 --- a/core/src/main/java/net/serenitybdd/core/pages/WebElementFacade.java +++ b/core/src/main/java/net/serenitybdd/core/pages/WebElementFacade.java @@ -118,6 +118,4 @@ public List thenFindAll( public void shouldContainElements(String xpathOrCssSelector); - - } diff --git a/core/src/main/java/net/thucydides/core/annotations/locators/SmartAjaxElementLocator.java b/core/src/main/java/net/thucydides/core/annotations/locators/SmartAjaxElementLocator.java index 36e50c00c2..147b9e208e 100644 --- a/core/src/main/java/net/thucydides/core/annotations/locators/SmartAjaxElementLocator.java +++ b/core/src/main/java/net/thucydides/core/annotations/locators/SmartAjaxElementLocator.java @@ -28,7 +28,7 @@ public class SmartAjaxElementLocator extends SmartElementLocator implements WithConfigurableTimeout { public static final Duration ZERO_SECONDS = new Duration(0, TimeUnit.SECONDS); protected int timeOutInSeconds; - protected Optional annotatedTimeoutInSecondes; + protected Optional annotatedTimeoutInSeconds; private final Clock clock; private final Field field; @@ -50,18 +50,17 @@ public SmartAjaxElementLocator(SearchContext searchContext, Field field, MobileP public SmartAjaxElementLocator(Clock clock, SearchContext searchContext, Field field, MobilePlatform platform, Integer defaultTimeoutInSeconds) { super(searchContext, field, platform); this.timeOutInSeconds = defaultTimeoutInSeconds; - this.annotatedTimeoutInSecondes = timeoutFrom(field); + this.annotatedTimeoutInSeconds = timeoutFrom(field); this.clock = clock; this.field = field; - if ((searchContext instanceof WebDriverFacade) || (searchContext instanceof WebElementFacade)) { - this.searchContext = searchContext; + if (searchContext instanceof WebDriverFacade){ + this.searchContext = ((WebDriverFacade) searchContext) + .withTimeoutOf(new Duration(annotatedTimeoutInSeconds.or(defaultTimeoutInSeconds), TimeUnit.SECONDS)); } else if (searchContext instanceof WebDriver) { this.searchContext = WebdriverProxyFactory.getFactory().proxyFor((WebDriver) searchContext); } else { this.searchContext = searchContext; } - - this.platform = platform; } @@ -114,16 +113,16 @@ protected boolean isElementUsable(WebElement element) { * Will poll the interface on a regular basis until the element is present. */ public WebElement ajaxFindElement() { - SlowLoadingElement loadingElement = new SlowLoadingElement(clock, annotatedTimeoutInSecondes.or(timeOutInSeconds)); + SlowLoadingElement loadingElement = new SlowLoadingElement(clock, annotatedTimeoutInSeconds.or(timeOutInSeconds)); try { return loadingElement.get().getElement(); } catch (ElementNotVisibleAfterTimeoutError notVisible) { throw new ElementNotVisibleException( - String.format("Timed out after %d seconds. %s", annotatedTimeoutInSecondes.or(timeOutInSeconds), notVisible.getMessage()), + String.format("Timed out after %d seconds. %s", annotatedTimeoutInSeconds.or(timeOutInSeconds), notVisible.getMessage()), notVisible.getCause()); } catch (Error e) { throw new NoSuchElementException( - String.format("Timed out after %d seconds. %s", annotatedTimeoutInSecondes.or(timeOutInSeconds), e.getMessage()), + String.format("Timed out after %d seconds. %s", annotatedTimeoutInSeconds.or(timeOutInSeconds), e.getMessage()), e.getCause()); } } @@ -137,12 +136,12 @@ public List findElements() { if (aPreviousStepHasFailed()) { return EMPTY_LIST_OF_WEBELEMENTS; } - SlowLoadingElementList list = new SlowLoadingElementList(clock, annotatedTimeoutInSecondes.or(timeOutInSeconds)); + SlowLoadingElementList list = new SlowLoadingElementList(clock, annotatedTimeoutInSeconds.or(timeOutInSeconds)); try { return list.get().getElements(); } catch (Error e) { throw new NoSuchElementException( - String.format("Timed out after %d seconds. %s", annotatedTimeoutInSecondes.or(timeOutInSeconds), e.getMessage()), + String.format("Timed out after %d seconds. %s", annotatedTimeoutInSeconds.or(timeOutInSeconds), e.getMessage()), e.getCause()); } } diff --git a/core/src/test/groovy/net/serenitybdd/core/pages/integration/WhenManagingWebdriverTimeouts.groovy b/core/src/test/groovy/net/serenitybdd/core/pages/integration/WhenManagingWebdriverTimeouts.groovy index 1cb334073b..7da69021bf 100644 --- a/core/src/test/groovy/net/serenitybdd/core/pages/integration/WhenManagingWebdriverTimeouts.groovy +++ b/core/src/test/groovy/net/serenitybdd/core/pages/integration/WhenManagingWebdriverTimeouts.groovy @@ -16,6 +16,8 @@ import org.openqa.selenium.TimeoutException import spock.lang.Specification import spock.lang.Unroll +import java.util.concurrent.TimeUnit + import static java.util.concurrent.TimeUnit.MILLISECONDS import static java.util.concurrent.TimeUnit.SECONDS @@ -418,4 +420,31 @@ class WhenManagingWebdriverTimeouts extends Specification { page.country.isCurrentlyVisible() } + def "You can check whether a child element is present using a By selector"() { + when: + environmentVariables.setProperty("webdriver.timeouts.implicitlywait","0") + page = openTestPageUsing(defaultBrowser) + then: + page.clients.shouldContainElements(By.cssSelector(".color")) + and: + page.clients.shouldContainElements(".color") + } + + def "You can check whether a child element is present"() { + when: + environmentVariables.setProperty("webdriver.timeouts.implicitlywait","0") + page = openTestPageUsing(defaultBrowser) + then: + page.clients.containsElements(By.cssSelector(".color")) + and: + !page.clients.containsElements(By.cssSelector(".flavor")) + } + + def "You can check whether a child element is present with waits"() { + when: + page = openTestPageUsing(defaultBrowser) + then: + page.clients.withTimeoutOf(0, TimeUnit.SECONDS).containsElements(By.cssSelector(".color")) + } + } diff --git a/core/src/test/java/net/thucydides/core/pages/integration/StaticSitePage.java b/core/src/test/java/net/thucydides/core/pages/integration/StaticSitePage.java index 95a100911f..07ec95810a 100644 --- a/core/src/test/java/net/thucydides/core/pages/integration/StaticSitePage.java +++ b/core/src/test/java/net/thucydides/core/pages/integration/StaticSitePage.java @@ -86,7 +86,7 @@ public class StaticSitePage extends PageObject { public WebElement focusmessage; - public WebElement clients; + public WebElementFacade clients; public WebElement clients_with_no_headings;