Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Jun 18, 2015
1 parent 54529c1 commit d377729
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.thucydides.core.webdriver.*;
import net.thucydides.core.webdriver.exceptions.ElementNotFoundAfterTimeoutError;
import net.thucydides.core.webdriver.exceptions.ElementNotVisibleAfterTimeoutError;
import net.thucydides.core.webdriver.stubs.WebElementFacadeStub;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.Clock;
Expand Down Expand Up @@ -84,7 +85,9 @@ private Optional<Integer> timeoutFrom(Field field) {

@Override
public WebElement findElement() {
if (shouldFindElementImmediately()) {
if (aPreviousStepHasFailed()) {
return new WebElementFacadeStub();
} else if (shouldFindElementImmediately()) {
return findElementImmediately();
} else {
return ajaxFindElement();
Expand All @@ -96,7 +99,7 @@ public void setTimeOutInSeconds(int timeOutInSeconds) {
}

private boolean shouldFindElementImmediately() {
return aPreviousStepHasFailed() || (MethodTiming.forThisThread().isInQuickMethod());
return /*aPreviousStepHasFailed() ||*/ (MethodTiming.forThisThread().isInQuickMethod());
}

public WebElement findElementImmediately() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package net.serenitybdd.core.pages.integration
import net.serenitybdd.core.pages.WebElementFacade
import net.thucydides.core.ThucydidesSystemProperty
import net.thucydides.core.pages.integration.StaticSitePage
import net.thucydides.core.steps.ExecutedStepDescription
import net.thucydides.core.steps.StepEventBus
import net.thucydides.core.steps.StepFailure
import net.thucydides.core.util.EnvironmentVariables
import net.thucydides.core.util.MockEnvironmentVariables
import net.thucydides.core.webdriver.StaticTestSite
Expand Down Expand Up @@ -45,6 +48,7 @@ class WhenManagingWebdriverTimeouts extends Specification {
if (phantomJSPath) {
environmentVariables.setProperty("phantomjs.binary.path", phantomJSPath)
}
StepEventBus.eventBus.clear()
}

def cleanup() {
Expand Down Expand Up @@ -74,6 +78,21 @@ class WhenManagingWebdriverTimeouts extends Specification {
thrown(org.openqa.selenium.ElementNotVisibleException)
}

@Timeout(2)
def "Slow loading fields should not wait once a step has failed"() {
given: "The #slow-loader field takes 4 seconds to load"
and: "A step has failed"
def stepFailure = Mock(StepFailure)
StepEventBus.getEventBus().testStarted("a test")
StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step"))
StepEventBus.getEventBus().stepFailed(stepFailure);
when: "We access the field"
page = openTestPageUsing(defaultBrowser)
page.verySlowLoadingField.isDisplayed()
then: "Not error should not be thrown"
notThrown(org.openqa.selenium.ElementNotVisibleException)
}

def "The default implicit wait is set to 2 seconds"() {
given: "The #city field takes 500 ms to load"
page = openTestPageUsing(defaultBrowser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public void should_find_element_immediately_if_a_previous_step_has_failed() {
public void should_wait_for_find_element_immediately_if_no_previous_step_has_failed() {

expectedException.expect(ElementNotVisibleException.class);
expectedException.expectMessage(containsString("Timed out after 2 second"));

SmartAjaxElementLocator locator = new SmartAjaxElementLocator(driver, field, MobilePlatform.NONE);
locator.findElement();
}
Expand Down

0 comments on commit d377729

Please sign in to comment.