|
32 | 32 | import static org.junit.Assume.assumeTrue; |
33 | 33 | import static org.openqa.selenium.WaitingConditions.elementTextToContain; |
34 | 34 | import static org.openqa.selenium.WaitingConditions.elementTextToEqual; |
| 35 | +import static org.openqa.selenium.WaitingConditions.newWindowIsOpened; |
35 | 36 | import static org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS; |
| 37 | +import static org.openqa.selenium.support.ui.ExpectedConditions.not; |
36 | 38 | import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; |
37 | 39 | import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs; |
38 | 40 | import static org.openqa.selenium.testing.Ignore.Driver.ANDROID; |
|
47 | 49 | import static org.openqa.selenium.testing.Ignore.Driver.PHANTOMJS; |
48 | 50 | import static org.openqa.selenium.testing.Ignore.Driver.SAFARI; |
49 | 51 | import static org.openqa.selenium.testing.TestUtilities.isFirefox; |
50 | | -import static org.openqa.selenium.testing.TestUtilities.isInternetExplorer; |
51 | 52 | import static org.openqa.selenium.testing.TestUtilities.isLocal; |
52 | 53 | import static org.openqa.selenium.testing.TestUtilities.isNativeEventsEnabled; |
53 | 54 |
|
54 | 55 | import org.junit.After; |
55 | 56 | import org.junit.Test; |
56 | 57 | import org.openqa.selenium.remote.CapabilityType; |
57 | 58 | import org.openqa.selenium.remote.DesiredCapabilities; |
58 | | -import org.openqa.selenium.support.ui.ExpectedCondition; |
59 | 59 | import org.openqa.selenium.support.ui.WebDriverWait; |
60 | 60 | import org.openqa.selenium.testing.Ignore; |
61 | 61 | import org.openqa.selenium.testing.JUnit4TestBase; |
|
64 | 64 | import org.openqa.selenium.testing.drivers.SauceDriver; |
65 | 65 | import org.openqa.selenium.testing.drivers.WebDriverBuilder; |
66 | 66 |
|
| 67 | +import java.util.Set; |
| 68 | + |
67 | 69 | public class PageLoadingTest extends JUnit4TestBase { |
68 | 70 |
|
69 | 71 | private WebDriver localDriver; |
@@ -251,48 +253,23 @@ public void testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoad |
251 | 253 | } |
252 | 254 |
|
253 | 255 | @Ignore(value = {IPHONE, SAFARI}, issues = {3771}) |
| 256 | + @JavascriptEnabled |
254 | 257 | @NeedsFreshDriver |
| 258 | + @NoDriverAfterTest |
255 | 259 | @Test |
256 | 260 | 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"); |
265 | 266 | String originalTitle = driver.getTitle(); |
266 | | - driver.get(pages.formPage); |
267 | | - |
| 267 | + driver.get(pages.blankPage); |
| 268 | + wait.until(not(titleIs(originalTitle))); |
268 | 269 | 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)); |
296 | 273 | } |
297 | 274 |
|
298 | 275 | @Ignore(value = {ANDROID, SAFARI, MARIONETTE}, issues = {3771}) |
|
0 commit comments