Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/MiscTest.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.testing.drivers.Browser.ALL;
22
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
23
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
24
import static org.openqa.selenium.testing.drivers.Browser.IE;
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.NotYetImplemented;
31
32
class MiscTest extends JupiterTestBase {
33
34
@Test
35
void testShouldReturnTitleOfPageIfSet() {
36
driver.get(pages.xhtmlTestPage);
37
assertThat(driver.getTitle()).isEqualTo(("XHTML Test Page"));
38
39
driver.get(pages.simpleTestPage);
40
assertThat(driver.getTitle()).isEqualTo("Hello WebDriver");
41
}
42
43
@Test
44
void testShouldReportTheCurrentUrlCorrectly() {
45
driver.get(pages.simpleTestPage);
46
assertThat(driver.getCurrentUrl()).isEqualToIgnoringCase(pages.simpleTestPage);
47
48
driver.get(pages.javascriptPage);
49
assertThat(driver.getCurrentUrl()).isEqualToIgnoringCase(pages.javascriptPage);
50
}
51
52
@Test
53
void shouldReturnTagName() {
54
driver.get(pages.formPage);
55
WebElement selectBox = driver.findElement(By.id("cheese"));
56
assertThat(selectBox.getTagName()).isEqualToIgnoringCase("input");
57
}
58
59
@Test
60
void testShouldReturnTheSourceOfAPage() {
61
driver.get(pages.simpleTestPage);
62
63
String source = driver.getPageSource().toLowerCase();
64
65
assertThat(source)
66
.contains(
67
"<html",
68
"</html",
69
"an inline element",
70
"<p id=",
71
"lotsofspaces",
72
"with document.write and with document.write again");
73
}
74
75
@Test
76
@Ignore(value = CHROME, reason = "returns XML content formatted for display as HTML document")
77
@Ignore(value = EDGE, reason = "returns XML content formatted for display as HTML document")
78
@NotYetImplemented(
79
value = SAFARI,
80
reason = "returns XML content formatted for display as HTML document")
81
@Ignore(IE)
82
public void testShouldBeAbleToGetTheSourceOfAnXmlDocument() {
83
driver.get(pages.simpleXmlDocument);
84
String source = driver.getPageSource().toLowerCase();
85
assertThat(source).isEqualToIgnoringWhitespace("<xml><foo><bar>baz</bar></foo></xml>");
86
}
87
88
@Test
89
@Ignore(value = ALL, reason = "issue 2282")
90
public void testStimulatesStrangeOnloadInteractionInFirefox() {
91
driver.get(pages.documentWrite);
92
93
// If this command succeeds, then all is well.
94
driver.findElement(By.xpath("//body"));
95
96
driver.get(pages.simpleTestPage);
97
driver.findElement(By.id("links"));
98
}
99
100
@Test
101
void testClickingShouldNotTrampleWOrHInGlobalScope() {
102
driver.get(appServer.whereIs("globalscope.html"));
103
String[] vars = new String[] {"w", "h"};
104
for (String var : vars) {
105
assertThat(getGlobalVar(driver, var)).isEqualTo(var);
106
}
107
driver.findElement(By.id("toclick")).click();
108
for (String var : vars) {
109
assertThat(getGlobalVar(driver, var)).isEqualTo(var);
110
}
111
}
112
113
private String getGlobalVar(WebDriver driver, String var) {
114
Object val = ((JavascriptExecutor) driver).executeScript("return window." + var + ";");
115
return val == null ? "null" : val.toString();
116
}
117
}
118
119