Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/HistoryNavigationTest.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import static org.assertj.core.api.Assertions.assertThat;
21
import static org.openqa.selenium.WaitingConditions.windowToBeSwitchedToWithName;
22
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
23
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
24
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
25
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
26
27
import org.junit.jupiter.api.Test;
28
import org.openqa.selenium.testing.Ignore;
29
import org.openqa.selenium.testing.JupiterTestBase;
30
import org.openqa.selenium.testing.NeedsFreshDriver;
31
32
public class HistoryNavigationTest extends JupiterTestBase {
33
34
@NeedsFreshDriver
35
@Test
36
@Ignore(value = SAFARI, reason = "Hanging")
37
public void testShouldDoNothingIfThereIsNothingToGoBackTo() {
38
((JavascriptExecutor) driver).executeScript("window.open('', 'newWindow')");
39
wait.until(windowToBeSwitchedToWithName("newWindow"));
40
driver.get(pages.formPage);
41
wait.until(titleIs("We Leave From Here"));
42
String originalTitle = driver.getTitle();
43
driver.get(pages.blankPage);
44
wait.until(not(titleIs(originalTitle)));
45
driver.navigate().back();
46
wait.until(titleIs(originalTitle));
47
driver.navigate().back(); // Nothing to go back to, must stay.
48
assertThat(driver.getTitle()).isEqualTo(originalTitle);
49
}
50
51
@Test
52
@Ignore(SAFARI)
53
public void testShouldBeAbleToNavigateBackInTheBrowserHistory() {
54
driver.get(pages.formPage);
55
56
wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();
57
wait.until(titleIs("We Arrive Here"));
58
59
driver.navigate().back();
60
wait.until(titleIs("We Leave From Here"));
61
}
62
63
@Test
64
void testShouldBeAbleToNavigateBackInTheBrowserHistoryInPresenceOfIframes() {
65
driver.get(pages.xhtmlTestPage);
66
67
wait.until(visibilityOfElementLocated(By.name("sameWindow"))).click();
68
wait.until(titleIs("This page has iframes"));
69
70
driver.navigate().back();
71
wait.until(titleIs("XHTML Test Page"));
72
}
73
74
@Test
75
void testShouldBeAbleToNavigateForwardsInTheBrowserHistory() {
76
driver.get(pages.formPage);
77
78
wait.until(visibilityOfElementLocated(By.id("imageButton"))).submit();
79
wait.until(titleIs("We Arrive Here"));
80
81
driver.navigate().back();
82
wait.until(titleIs("We Leave From Here"));
83
84
driver.navigate().forward();
85
wait.until(titleIs("We Arrive Here"));
86
}
87
}
88
89