Skip to content

Commit

Permalink
Cleaning up testShouldDoNothingIfThereIsNothingToGoBackTo
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
  • Loading branch information
sevaseva authored and lukeis committed Feb 26, 2014
1 parent fa76f9a commit 169dba6
Showing 1 changed file with 16 additions and 39 deletions.
55 changes: 16 additions & 39 deletions java/client/test/org/openqa/selenium/PageLoadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,15 +49,13 @@
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;

import org.junit.After;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> 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<Object> either(
final ExpectedCondition<?> one,
final ExpectedCondition<?> two) {
return new ExpectedCondition<Object>() {
@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})
Expand Down

0 comments on commit 169dba6

Please sign in to comment.