Path: blob/trunk/java/test/org/openqa/selenium/HistoryNavigationTest.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import static org.assertj.core.api.Assertions.assertThat;20import static org.openqa.selenium.WaitingConditions.windowToBeSwitchedToWithName;21import static org.openqa.selenium.support.ui.ExpectedConditions.not;22import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;23import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;24import static org.openqa.selenium.testing.drivers.Browser.SAFARI;2526import org.junit.jupiter.api.Test;27import org.openqa.selenium.testing.Ignore;28import org.openqa.selenium.testing.JupiterTestBase;29import org.openqa.selenium.testing.NeedsFreshDriver;3031public class HistoryNavigationTest extends JupiterTestBase {3233@NeedsFreshDriver34@Test35@Ignore(value = SAFARI, reason = "Hanging")36public void testShouldDoNothingIfThereIsNothingToGoBackTo() {37((JavascriptExecutor) driver).executeScript("window.open('', 'newWindow')");38wait.until(windowToBeSwitchedToWithName("newWindow"));39driver.get(pages.formPage);40wait.until(titleIs("We Leave From Here"));41String originalTitle = driver.getTitle();42driver.get(pages.blankPage);43wait.until(not(titleIs(originalTitle)));44driver.navigate().back();45wait.until(titleIs(originalTitle));46driver.navigate().back(); // Nothing to go back to, must stay.47assertThat(driver.getTitle()).isEqualTo(originalTitle);48}4950@Test51@Ignore(SAFARI)52public void testShouldBeAbleToNavigateBackInTheBrowserHistory() {53driver.get(pages.formPage);5455wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();56wait.until(titleIs("We Arrive Here"));5758driver.navigate().back();59wait.until(titleIs("We Leave From Here"));60}6162@Test63void testShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes() {64driver.get(pages.xhtmlTestPage);6566wait.until(visibilityOfElementLocated(By.name("sameWindow"))).click();67wait.until(titleIs("This page has iframes"));6869driver.navigate().back();70wait.until(titleIs("XHTML Test Page"));71}7273@Test74void testShouldBeAbleToNavigateForwardsInTheBrowserHistory() {75driver.get(pages.formPage);7677wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();78wait.until(titleIs("We Arrive Here"));7980driver.navigate().back();81wait.until(titleIs("We Leave From Here"));8283driver.navigate().forward();84wait.until(titleIs("We Arrive Here"));85}86}878889