Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/PageLoadingTest.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.assertj.core.api.Assertions.assertThatCode;
22
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
23
import static org.openqa.selenium.WaitingConditions.elementTextToContain;
24
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
25
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
26
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
27
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
28
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
29
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
30
import static org.openqa.selenium.testing.drivers.Browser.IE;
31
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
32
33
import java.time.Duration;
34
import org.junit.jupiter.api.Test;
35
import org.openqa.selenium.remote.CapabilityType;
36
import org.openqa.selenium.testing.Ignore;
37
import org.openqa.selenium.testing.JupiterTestBase;
38
import org.openqa.selenium.testing.NeedsFreshDriver;
39
import org.openqa.selenium.testing.NeedsSecureServer;
40
import org.openqa.selenium.testing.NoDriverAfterTest;
41
import org.openqa.selenium.testing.NotYetImplemented;
42
import org.openqa.selenium.testing.SwitchToTopAfterTest;
43
44
@NeedsSecureServer
45
class PageLoadingTest extends JupiterTestBase {
46
47
@Test
48
@NeedsFreshDriver
49
public void shouldSetAndGetPageLoadTimeout() {
50
Duration timeout = driver.manage().timeouts().getPageLoadTimeout();
51
assertThat(timeout).hasMillis(300000);
52
driver.manage().timeouts().pageLoadTimeout(Duration.ofMillis(3000));
53
Duration timeout2 = driver.manage().timeouts().getPageLoadTimeout();
54
assertThat(timeout2).hasMillis(3000);
55
}
56
57
@Test
58
void testShouldFollowRedirectsSentInTheHttpResponseHeaders() {
59
driver.get(pages.redirectPage);
60
assertThat(driver.getTitle()).isEqualTo("We Arrive Here");
61
}
62
63
@Test
64
void testShouldFollowMetaRedirects() {
65
driver.get(pages.metaRedirectPage);
66
wait.until(titleIs("We Arrive Here"));
67
}
68
69
@Test
70
void testShouldBeAbleToGetAFragmentOnTheCurrentPage() {
71
driver.get(pages.xhtmlTestPage);
72
driver.get(pages.xhtmlTestPage + "#text");
73
wait.until(presenceOfElementLocated(By.id("id1")));
74
}
75
76
@Test
77
@NotYetImplemented(CHROME)
78
@NotYetImplemented(EDGE)
79
@NotYetImplemented(FIREFOX)
80
public void testShouldReturnWhenGettingAUrlThatDoesNotResolve() {
81
assertThatCode(() -> driver.get("http://www.thisurldoesnotexist.comx/"))
82
.doesNotThrowAnyException();
83
}
84
85
@Test
86
void testShouldThrowIfUrlIsMalformed() {
87
assertThatExceptionOfType(WebDriverException.class)
88
.isThrownBy(() -> driver.get("www.test.com"));
89
}
90
91
@Test
92
@NotYetImplemented(value = SAFARI)
93
public void testShouldThrowIfUrlIsMalformedInPortPart() {
94
assertThatExceptionOfType(WebDriverException.class)
95
.isThrownBy(() -> driver.get("http://localhost:3001bla"));
96
}
97
98
@Test
99
@NotYetImplemented(CHROME)
100
@NotYetImplemented(EDGE)
101
@NotYetImplemented(FIREFOX)
102
public void testShouldReturnWhenGettingAUrlThatDoesNotConnect() {
103
// Here's hoping that there's nothing here. There shouldn't be
104
driver.get("http://localhost:3001");
105
}
106
107
@Test
108
void testShouldReturnURLOnNotExistedPage() {
109
String url = appServer.whereIs("not_existed_page.html");
110
driver.get(url);
111
assertThat(driver.getCurrentUrl()).isEqualTo(url);
112
}
113
114
@SwitchToTopAfterTest
115
@Test
116
@NotYetImplemented(SAFARI)
117
public void testShouldBeAbleToLoadAPageWithFramesetsAndWaitUntilAllFramesAreLoaded() {
118
driver.get(pages.framesetPage);
119
120
driver.switchTo().frame(0);
121
WebElement pageNumber = driver.findElement(By.xpath("//span[@id='pageNumber']"));
122
assertThat(pageNumber.getText().trim()).isEqualTo("1");
123
124
driver.switchTo().defaultContent().switchTo().frame(1);
125
pageNumber = driver.findElement(By.xpath("//span[@id='pageNumber']"));
126
assertThat(pageNumber.getText().trim()).isEqualTo("2");
127
}
128
129
@Test
130
@Ignore(IE)
131
@NotYetImplemented(value = SAFARI, reason = "does not support insecure SSL")
132
public void testShouldBeAbleToAccessPagesWithAnInsecureSslCertificate() {
133
createNewDriver(new ImmutableCapabilities(CapabilityType.ACCEPT_INSECURE_CERTS, Boolean.TRUE));
134
driver.get(appServer.whereIsSecure("simpleTest.html"));
135
136
shortWait.until(titleIs("Hello WebDriver"));
137
}
138
139
@Test
140
void testShouldBeAbleToRefreshAPage() {
141
driver.get(pages.xhtmlTestPage);
142
143
driver.navigate().refresh();
144
145
assertThat(driver.getTitle()).isEqualTo("XHTML Test Page");
146
}
147
148
/**
149
* See https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/208
150
*
151
* <p>This test often causes the subsequent test to fail, in Firefox, on Linux, so we need a new
152
* driver after it. See
153
* https://github.com/SeleniumHQ/selenium-google-code-issue-archive/issues/2282
154
*/
155
@NoDriverAfterTest
156
@Test
157
@Ignore(IE)
158
@Ignore(FIREFOX)
159
public void testShouldNotHangIfDocumentOpenCallIsNeverFollowedByDocumentCloseCall() {
160
driver.get(pages.documentWrite);
161
162
// If this command succeeds, then all is well.
163
WebElement body = wait.until(visibilityOfElementLocated(By.tagName("body")));
164
wait.until(elementTextToContain(body, "world"));
165
}
166
}
167
168