Skip to content

Commit 169dba6

Browse files
sevasevalukeis
authored andcommitted
Cleaning up testShouldDoNothingIfThereIsNothingToGoBackTo
Signed-off-by: Luke Inman-Semerau <luke.semerau@gmail.com>
1 parent fa76f9a commit 169dba6

File tree

1 file changed

+16
-39
lines changed

1 file changed

+16
-39
lines changed

java/client/test/org/openqa/selenium/PageLoadingTest.java

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
import static org.junit.Assume.assumeTrue;
3333
import static org.openqa.selenium.WaitingConditions.elementTextToContain;
3434
import static org.openqa.selenium.WaitingConditions.elementTextToEqual;
35+
import static org.openqa.selenium.WaitingConditions.newWindowIsOpened;
3536
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS;
37+
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
3638
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
3739
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
3840
import static org.openqa.selenium.testing.Ignore.Driver.ANDROID;
@@ -47,15 +49,13 @@
4749
import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS;
4850
import static org.openqa.selenium.testing.Ignore.Driver.SAFARI;
4951
import static org.openqa.selenium.testing.TestUtilities.isFirefox;
50-
import static org.openqa.selenium.testing.TestUtilities.isInternetExplorer;
5152
import static org.openqa.selenium.testing.TestUtilities.isLocal;
5253
import static org.openqa.selenium.testing.TestUtilities.isNativeEventsEnabled;
5354

5455
import org.junit.After;
5556
import org.junit.Test;
5657
import org.openqa.selenium.remote.CapabilityType;
5758
import org.openqa.selenium.remote.DesiredCapabilities;
58-
import org.openqa.selenium.support.ui.ExpectedCondition;
5959
import org.openqa.selenium.support.ui.WebDriverWait;
6060
import org.openqa.selenium.testing.Ignore;
6161
import org.openqa.selenium.testing.JUnit4TestBase;
@@ -64,6 +64,8 @@
6464
import org.openqa.selenium.testing.drivers.SauceDriver;
6565
import org.openqa.selenium.testing.drivers.WebDriverBuilder;
6666

67+
import java.util.Set;
68+
6769
public class PageLoadingTest extends JUnit4TestBase {
6870

6971
private WebDriver localDriver;
@@ -251,48 +253,23 @@ public void testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoad
251253
}
252254

253255
@Ignore(value = {IPHONE, SAFARI}, issues = {3771})
256+
@JavascriptEnabled
254257
@NeedsFreshDriver
258+
@NoDriverAfterTest
255259
@Test
256260
public void testShouldDoNothingIfThereIsNothingToGoBackTo() {
257-
if (SauceDriver.shouldUseSauce() && isInternetExplorer(driver)) {
258-
// Sauce opens about:blank after the browser loads, which IE doesn't include in history
259-
// Navigate back past it, so when we do the next navigation back, there is nothing to go
260-
// back to, rather than skipping past about:blank (whose title we will get as originalTitle)
261-
// to whatever as before (the WebDriver placeholder page).
262-
driver.navigate().back();
263-
}
264-
261+
Set<String> currentWindowHandles = driver.getWindowHandles();
262+
((JavascriptExecutor) driver).executeScript(
263+
"window.open('" + pages.formPage + "', 'newWindow')");
264+
wait.until(newWindowIsOpened(currentWindowHandles));
265+
driver.switchTo().window("newWindow");
265266
String originalTitle = driver.getTitle();
266-
driver.get(pages.formPage);
267-
267+
driver.get(pages.blankPage);
268+
wait.until(not(titleIs(originalTitle)));
268269
driver.navigate().back();
269-
// We may have returned to the browser's home page
270-
wait.until(either(titleIs(originalTitle), titleIs("We Leave From Here")));
271-
}
272-
273-
/**
274-
* A logical OR of the two given conditions.
275-
* TODO: Move to ExpectedConditions: generalize to N conditions, unit test.
276-
*/
277-
public static ExpectedCondition<Object> either(
278-
final ExpectedCondition<?> one,
279-
final ExpectedCondition<?> two) {
280-
return new ExpectedCondition<Object>() {
281-
@Override
282-
public Object apply(WebDriver driver) {
283-
Object result = one.apply(driver);
284-
if (result != null && !Boolean.FALSE.equals(result)) {
285-
return result;
286-
} else {
287-
return two.apply(driver);
288-
}
289-
}
290-
291-
@Override
292-
public String toString() {
293-
return "either of the conditions to be valid: " + one + ", " + two;
294-
}
295-
};
270+
wait.until(titleIs(originalTitle));
271+
driver.navigate().back(); // Nothing to go back to, must stay.
272+
assertThat(driver.getTitle(), equalTo(originalTitle));
296273
}
297274

298275
@Ignore(value = {ANDROID, SAFARI, MARIONETTE}, issues = {3771})

0 commit comments

Comments
 (0)