Skip to content

Commit

Permalink
Merge branch 'master' of github.com:serenity-bdd/serenity-core
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/test/resources/static-site/index.html
  • Loading branch information
wakaleo committed Mar 17, 2015
2 parents e7235f7 + ac3de4e commit 7f611da
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public List<WebElementFacade> thenFindAll(

public <T extends WebElementFacade> T waitUntilEnabled();

public <T extends WebElementFacade> T waitUntilClickable();

public <T extends WebElementFacade> T waitUntilDisabled();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,21 @@ public Boolean apply(WebDriver driver) {
private ExpectedCondition<Boolean> elementIsEnabled() {
return new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((getElement() != null) && (!isDisabledField(getElement())));
WebElement element = getElement();
return ((element != null) && (!isDisabledField(element)));
}
};
}
private ExpectedCondition<Boolean> elementIsClickable() {

return new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
WebElement element = getElement();
return ((element != null) && (element.isDisplayed()) && element.isEnabled());
}
};
}


private boolean isDisabledField(WebElement webElement) {
return (isAFormElement(webElement) && (!webElement.isEnabled()));
Expand Down Expand Up @@ -877,6 +888,20 @@ public WebElementFacade waitUntilEnabled() {
}
}

@Override
public WebElementFacade waitUntilClickable() {
if (driverIsDisabled()) {
return this;
}

try {
waitForCondition().until(elementIsClickable());
return this;
} catch (TimeoutException timeout) {
throw new ElementShouldBeEnabledException("Expected enabled element was not enabled", timeout);
}
}

@Override
public WebElementFacade waitUntilDisabled() {
if (driverIsDisabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,11 @@ public String getText() {
return "";
}

@Override
public <T extends WebElementFacade> T waitUntilClickable() {
return null;
}

@Override
public WebElementFacade waitUntilEnabled() {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.thucydides.core.webdriver.exceptions.ElementShouldBeEnabledException
import net.thucydides.core.webdriver.exceptions.ElementShouldBeInvisibleException
import org.openqa.selenium.By
import org.openqa.selenium.NoSuchElementException
import org.openqa.selenium.TimeoutException
import spock.lang.Specification
import spock.lang.Unroll

Expand Down Expand Up @@ -302,6 +303,24 @@ class WhenManagingWebdriverTimeouts extends Specification {
!cityIsDisplayed
}
def "The withTimeoutOf() method can be used to wait until a button is clickable"() {
given:
page = openTestPageUsing(defaultBrowser)
when:
page.initiallyDisabled.withTimeoutOf(5, SECONDS).waitUntilClickable().click()
then:
noExceptionThrown()
}
def "The withTimeoutOf() method can be used to wait until a button is clickable and will fail if it waits too long"() {
given:
page = openTestPageUsing(defaultBrowser)
when:
page.initiallyDisabled.withTimeoutOf(50, MILLISECONDS).waitUntilClickable().click()
then:
thrown(TimeoutException)
}
def "The withTimeoutOf() method can be used to override the global webdriver.wait.for.timeout value (positive case)"() {
given:
page = openTestPageUsing(defaultBrowser)
Expand Down
7 changes: 3 additions & 4 deletions core/src/test/resources/static-site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@
}

function displayFieldsAfterDelay() {
setTimeout("loadElementsSelect()", 2000);
setTimeout("displayCityField()", 2000);
setTimeout("displayCountryField()", 2000);
setTimeout("loadElementsSelect()", 1500);
setTimeout("displayCityField()", 1500);
setTimeout("displayCountryField()", 1500);
setTimeout("displaySlowLoaderField()", 4000);
setTimeout("displayVerySlowLoadingField()", 60000);
setTimeout("hideLocationTitle()", 2000);
setTimeout("activateDisabledButton()", 2000);
setTimeout("deactivateEnabledButton()", 2000);
setTimeout("removeDisappearingText()", 2000);

}

function focusOn(field) {
Expand Down

0 comments on commit 7f611da

Please sign in to comment.