From 169dba6ad4dd1cfefdbc388a3ca36a1a24f7604e Mon Sep 17 00:00:00 2001 From: Seva Lotoshnikov Date: Mon, 24 Feb 2014 19:45:59 -0800 Subject: [PATCH] Cleaning up testShouldDoNothingIfThereIsNothingToGoBackTo Signed-off-by: Luke Inman-Semerau --- .../org/openqa/selenium/PageLoadingTest.java | 55 ++++++------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/java/client/test/org/openqa/selenium/PageLoadingTest.java b/java/client/test/org/openqa/selenium/PageLoadingTest.java index cb6ee830e4f3f..afbef83c45105 100644 --- a/java/client/test/org/openqa/selenium/PageLoadingTest.java +++ b/java/client/test/org/openqa/selenium/PageLoadingTest.java @@ -32,7 +32,9 @@ import static org.junit.Assume.assumeTrue; import static org.openqa.selenium.WaitingConditions.elementTextToContain; import static org.openqa.selenium.WaitingConditions.elementTextToEqual; +import static org.openqa.selenium.WaitingConditions.newWindowIsOpened; import static org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS; +import static org.openqa.selenium.support.ui.ExpectedConditions.not; import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs; import static org.openqa.selenium.testing.Ignore.Driver.ANDROID; @@ -47,7 +49,6 @@ import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS; import static org.openqa.selenium.testing.Ignore.Driver.SAFARI; import static org.openqa.selenium.testing.TestUtilities.isFirefox; -import static org.openqa.selenium.testing.TestUtilities.isInternetExplorer; import static org.openqa.selenium.testing.TestUtilities.isLocal; import static org.openqa.selenium.testing.TestUtilities.isNativeEventsEnabled; @@ -55,7 +56,6 @@ import org.junit.Test; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.testing.Ignore; import org.openqa.selenium.testing.JUnit4TestBase; @@ -64,6 +64,8 @@ import org.openqa.selenium.testing.drivers.SauceDriver; import org.openqa.selenium.testing.drivers.WebDriverBuilder; +import java.util.Set; + public class PageLoadingTest extends JUnit4TestBase { private WebDriver localDriver; @@ -251,48 +253,23 @@ public void testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoad } @Ignore(value = {IPHONE, SAFARI}, issues = {3771}) + @JavascriptEnabled @NeedsFreshDriver + @NoDriverAfterTest @Test public void testShouldDoNothingIfThereIsNothingToGoBackTo() { - if (SauceDriver.shouldUseSauce() && isInternetExplorer(driver)) { - // Sauce opens about:blank after the browser loads, which IE doesn't include in history - // Navigate back past it, so when we do the next navigation back, there is nothing to go - // back to, rather than skipping past about:blank (whose title we will get as originalTitle) - // to whatever as before (the WebDriver placeholder page). - driver.navigate().back(); - } - + Set currentWindowHandles = driver.getWindowHandles(); + ((JavascriptExecutor) driver).executeScript( + "window.open('" + pages.formPage + "', 'newWindow')"); + wait.until(newWindowIsOpened(currentWindowHandles)); + driver.switchTo().window("newWindow"); String originalTitle = driver.getTitle(); - driver.get(pages.formPage); - + driver.get(pages.blankPage); + wait.until(not(titleIs(originalTitle))); driver.navigate().back(); - // We may have returned to the browser's home page - wait.until(either(titleIs(originalTitle), titleIs("We Leave From Here"))); - } - - /** - * A logical OR of the two given conditions. - * TODO: Move to ExpectedConditions: generalize to N conditions, unit test. - */ - public static ExpectedCondition either( - final ExpectedCondition one, - final ExpectedCondition two) { - return new ExpectedCondition() { - @Override - public Object apply(WebDriver driver) { - Object result = one.apply(driver); - if (result != null && !Boolean.FALSE.equals(result)) { - return result; - } else { - return two.apply(driver); - } - } - - @Override - public String toString() { - return "either of the conditions to be valid: " + one + ", " + two; - } - }; + wait.until(titleIs(originalTitle)); + driver.navigate().back(); // Nothing to go back to, must stay. + assertThat(driver.getTitle(), equalTo(originalTitle)); } @Ignore(value = {ANDROID, SAFARI, MARIONETTE}, issues = {3771})