Skip to content

Commit

Permalink
Fixed #87
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jun 30, 2015
1 parent 6086f27 commit 6f1628b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,18 @@ public PageObject waitForTextToAppear(final WebElement element,
return this;
}

private boolean driverIsDisabled() {
return StepEventBus.getEventBus().webdriverCallsAreSuspended();
}

/**
* Waits for a given text to disappear from the element.
*/
public PageObject waitForTextToDisappear(final WebElement element,
final String expectedText) {
waitForCondition().until(elementDoesNotContain(element, expectedText));
if (!driverIsDisabled()) {
waitForCondition().until(elementDoesNotContain(element, expectedText));
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.serenitybdd.core.time.Stopwatch;
import net.thucydides.core.scheduling.NormalFluentWait;
import net.thucydides.core.scheduling.ThucydidesFluentWait;
import net.thucydides.core.steps.StepEventBus;
import net.thucydides.core.webdriver.ConfigurableTimeouts;
import net.thucydides.core.webdriver.WebDriverFacade;
import org.openqa.selenium.*;
Expand Down Expand Up @@ -54,6 +55,10 @@ public RenderedPageObjectView(final WebDriver driver, final PageObject pageObjec
this.timeoutCanBeOverriden = timeoutCanBeOverriden;
}

private boolean driverIsDisabled() {
return StepEventBus.getEventBus().webdriverCallsAreSuspended();
}

public ThucydidesFluentWait<WebDriver> waitForCondition() {
return new NormalFluentWait<>(driver, webdriverClock, sleeper)
.withTimeout(waitForTimeout.in(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -85,7 +90,9 @@ public String toString() {
* This method will wait until an element is present and visible on the screen.
*/
public void waitFor(final By byElementCriteria) {
waitForCondition().until(elementDisplayed(byElementCriteria));
if (!driverIsDisabled()) {
waitForCondition().until(elementDisplayed(byElementCriteria));
}
}

public void waitFor(final ExpectedCondition expectedCondition) {
Expand All @@ -108,12 +115,16 @@ public List<WebElementFacade> waitFor(final List<WebElementFacade> webElements)
}

private WebElementFacade waitForElement(final WebElementFacade webElement) {
waitForCondition().until(elementIsDisplayed(webElement));
if (!driverIsDisabled()) {
waitForCondition().until(elementIsDisplayed(webElement));
}
return webElement;
}

private List<WebElementFacade> waitForElements(final List<WebElementFacade> elements) {
waitForCondition().until(elementsAreDisplayed(elements));
if (!driverIsDisabled()) {
waitForCondition().until(elementsAreDisplayed(elements));
}
return elements;
}

Expand Down Expand Up @@ -225,7 +236,9 @@ public String toString() {
}

public void waitForText(final String expectedText) {
waitForCondition().until(textPresent(expectedText));
if (!driverIsDisabled()) {
waitForCondition().until(textPresent(expectedText));
}
}

private ExpectedCondition<Boolean> textPresentInElement(final WebElement element, final String expectedText) {
Expand All @@ -242,7 +255,9 @@ public String toString() {
}

public void waitForText(final WebElement element, final String expectedText) {
waitForCondition().until(textPresentInElement(element, expectedText));
if (!driverIsDisabled()) {
waitForCondition().until(textPresentInElement(element, expectedText));
}
}

private ExpectedCondition<Boolean> titlePresent(final String expectedTitle) {
Expand All @@ -258,7 +273,9 @@ public String toString() {
}

public void waitForTitle(final String expectedTitle) {
waitForCondition().until(titlePresent(expectedTitle));
if (!driverIsDisabled()) {
waitForCondition().until(titlePresent(expectedTitle));
}
}

private boolean titleIs(final String expectedTitle) {
Expand Down Expand Up @@ -287,15 +304,19 @@ public String toString() {
}

public void waitForTextToDisappear(final String expectedText, final long timeout) {
waitForCondition()
.withTimeout(timeout, TimeUnit.MILLISECONDS)
.until(textNotPresent(expectedText));
if (!driverIsDisabled()) {
waitForCondition()
.withTimeout(timeout, TimeUnit.MILLISECONDS)
.until(textNotPresent(expectedText));
}
}

public void waitForTextToAppear(final String expectedText, final long timeout) {
waitForCondition()
.withTimeout(timeout, TimeUnit.MILLISECONDS)
.until(textPresent(expectedText));
if (!driverIsDisabled()) {
waitForCondition()
.withTimeout(timeout, TimeUnit.MILLISECONDS)
.until(textPresent(expectedText));
}
}

private ExpectedCondition<Boolean> titleNotPresent(final String expectedTitle) {
Expand All @@ -311,7 +332,9 @@ public String toString() {
}

public void waitForTitleToDisappear(final String expectedTitle) {
waitForCondition().until(titleNotPresent(expectedTitle));
if (!driverIsDisabled()) {
waitForCondition().until(titleNotPresent(expectedTitle));
}
}

private ExpectedCondition<Boolean> anyTextPresent(final String... expectedTexts) {
Expand All @@ -323,7 +346,9 @@ public Boolean apply(WebDriver driver) {
}

public void waitForAnyTextToAppear(final String... expectedTexts) {
waitForCondition().until(anyTextPresent(expectedTexts));
if (!driverIsDisabled()) {
waitForCondition().until(anyTextPresent(expectedTexts));
}
}

private ExpectedCondition<Boolean> anyTextPresentInElement(final WebElement element, final String... expectedTexts) {
Expand All @@ -341,7 +366,9 @@ public String toString() {
}

public void waitForAnyTextToAppear(final WebElement element, final String... expectedTexts) {
waitForCondition().until(anyTextPresentInElement(element, expectedTexts));
if (!driverIsDisabled()) {
waitForCondition().until(anyTextPresentInElement(element, expectedTexts));
}
}


Expand Down Expand Up @@ -386,7 +413,9 @@ public String toString() {
}

public void waitForAllTextToAppear(final String... expectedTexts) {
waitForCondition().until(allTextPresent(expectedTexts));
if (!driverIsDisabled()) {
waitForCondition().until(allTextPresent(expectedTexts));
}
}

private ExpectedCondition<Boolean> elementNotDisplayed(final By byElementCriteria) {
Expand All @@ -402,7 +431,9 @@ public String toString() {
}

public void waitForElementsToDisappear(final By byElementCriteria) {
waitForCondition().until(elementNotDisplayed(byElementCriteria));
if (!driverIsDisabled()) {
waitForCondition().until(elementNotDisplayed(byElementCriteria));
}
}

private ExpectedCondition<Boolean> anyElementPresent(final By... expectedElements) {
Expand All @@ -422,7 +453,9 @@ public String toString() {
};
}
public void waitForAnyRenderedElementOf(final By[] expectedElements) {
waitForCondition().until(anyElementPresent(expectedElements));
if (!driverIsDisabled()) {
waitForCondition().until(anyElementPresent(expectedElements));
}
}

// public void setWaitForTimeoutInMilliseconds(long waitForTimeoutInMilliseconds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ private void failWithMessage(String errorMessage) {

private void checkPresenceOfWebElement() {
try {
waitForCondition().until(elementIsDisplayed());
if (!driverIsDisabled()) {
waitForCondition().until(elementIsDisplayed());
}
} catch (Throwable error) {
if (webElement != null) {
throwShouldBeVisibleErrorWithCauseIfPresent(error, error.getMessage());
Expand All @@ -716,12 +718,10 @@ private void checkPresenceOfWebElement() {

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

try {
waitForCondition().until(elementIsDisplayed());
if (!driverIsDisabled()) {
waitForCondition().until(elementIsDisplayed());
}
} catch (Throwable error) {
if (webElement != null) {
throwShouldBeVisibleErrorWithCauseIfPresent(error, error.getMessage());
Expand All @@ -734,12 +734,10 @@ public WebElementFacade waitUntilVisible() {

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

try {
waitForCondition().until(elementIsPresent());
if (!driverIsDisabled()) {
waitForCondition().until(elementIsPresent());
}
} catch (TimeoutException timeout) {
throwShouldBePresentErrorWithCauseIfPresent(timeout, timeout.getMessage());
}
Expand Down Expand Up @@ -867,12 +865,10 @@ private Wait<WebDriver> waitBriefly() {

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

try {
waitForCondition().until(elementIsNotDisplayed());
if (!driverIsDisabled()) {
waitForCondition().until(elementIsNotDisplayed());
}
} catch (TimeoutException timeout) {
throwShouldBeInvisibleErrorWithCauseIfPresent(timeout, "Expected hidden element was displayed");
}
Expand All @@ -881,7 +877,6 @@ public WebElementFacade waitUntilNotVisible() {

@Override
public String getValue() {
// waitUntilVisible();
checkPresenceOfWebElement();
return getElement().getAttribute("value");
}
Expand All @@ -901,44 +896,38 @@ public String getText() {

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

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

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

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

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

try {
waitForCondition().until(elementIsNotEnabled());
return this;
if (!driverIsDisabled()) {
waitForCondition().until(elementIsNotEnabled());
}
} catch (TimeoutException timeout) {
throw new ElementShouldBeDisabledException("Expected disabled element was not disabled", timeout);
}
return this;
}

@Override
Expand Down

0 comments on commit 6f1628b

Please sign in to comment.