Skip to content

Commit a38f56c

Browse files
authored
Merge branch 'trunk' into overall-docstring-cleanup
2 parents 2bc99b1 + 7719d5f commit a38f56c

39 files changed

+1296
-534
lines changed
Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
<html>
1+
<html lang="en">
32
<head>
43
<title>Relative Locators</title>
54
<style>
@@ -10,57 +9,101 @@
109
td {
1110
border: solid;
1211
}
13-
.small-rectangle {
12+
#center {
13+
width: 100px;
14+
}
15+
#rectangles {
16+
position: relative;
17+
}
18+
#rectangles div {
19+
position: absolute;
20+
border: 1px solid black;
21+
height: 50px;
22+
width: 50px;
23+
}
24+
#a {
25+
left: 25px;
26+
top: 0;
27+
}
28+
#b {
29+
left: 78px;
30+
top: 30px;
31+
}
32+
#c {
33+
left: 131px;
34+
top: 60px;
35+
}
36+
#d {
37+
left: 0;
38+
top: 53px;
39+
}
40+
#e {
41+
left: 53px;
42+
top: 83px;
43+
}
44+
#f {
45+
left: 106px;
46+
top: 113px;
47+
}
48+
#proximity .small {
1449
border: 1px solid black;
1550
width: 100px;
1651
height: 50px;
1752
margin: 5px 25px;
1853
}
19-
.big-rectangle {
54+
#proximity .big {
2055
border: 1px solid black;
2156
width: 150px;
22-
height: 400px;
57+
height: 400px;
58+
}
59+
#rect3 {
60+
margin: 60px 25px;
2361
}
2462
</style>
2563
</head>
2664
<body>
2765
<h1>Relative Locator Tests</h1>
28-
<p id="above">This text is above.
29-
<p id="mid">This is a paragraph of text in the middle.
30-
<p id="below">This text is below.
31-
66+
<section id="paragraphs">
67+
<p id="above">This text is above.</p>
68+
<p id="mid">This is a paragraph of text in the middle.</p>
69+
<p id="below">This text is below.</p>
70+
</section>
3271

3372
<table>
3473
<tr>
35-
<td id="first">1</td>
36-
<td id="second" style="width: 100px">2</td>
37-
<td id="third">3</td>
74+
<td id="topLeft">1</td>
75+
<td id="top">2</td>
76+
<td id="topRight">3</td>
3877
</tr>
3978
<tr>
40-
<td id="fourth">4</td>
79+
<td id="left">4</td>
4180
<td id="center">5</td>
42-
<td id="sixth">6</td>
81+
<td id="right">6</td>
4382
</tr>
4483
<tr>
45-
<td id="seventh">7</td>
46-
<td id="eighth">8</td>
47-
<td id="ninth">9</td>
84+
<td id="bottomLeft">7</td>
85+
<td id="bottom">8</td>
86+
<td id="bottomRight">9</td>
4887
</tr>
4988
</table>
5089

51-
<div class="small-rectangle" id="rect1">
52-
Rectangle 1
53-
</div>
54-
<div class="big-rectangle" id="rect2">
55-
Rectangle 2, which is near Rectangle 1
56-
</div>
90+
<section id="rectangles">
91+
<div id="a">El-A</div>
92+
<div id="b">El-B</div>
93+
<div id="c">El-C</div>
94+
<div id="d">El-D</div>
95+
<div id="e">El-E</div>
96+
<div id="f">El-F</div>
97+
</section>
5798

58-
<div class="small-rectangle" style="margin:60px 25px" id="rect3">
59-
Rectangle 3
60-
</div>
61-
<div class="big-rectangle" id="rect4">
62-
Rectangle 4, which is not near Rectangle 2 because it is more than 50 px away
63-
</div>
99+
<section id="proximity">
100+
<div class="small" id="rect1">Rectangle 1</div>
101+
<div class="big" id="rect2">Rectangle 2, which is near Rectangle 1</div>
102+
<div class="small" id="rect3">Rectangle 3</div>
103+
<div class="big" id="rect4">
104+
Rectangle 4, which is not near Rectangle 2 because it is more than 50 px away
105+
</div>
106+
</section>
64107

65108
</body>
66109
</html>

dotnet/test/common/RelativeLocatorTest.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ public void ShouldBeAbleToFindElementsAboveAnotherWithXpath()
4747
{
4848
driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("relative_locators.html"));
4949

50-
IWebElement lowest = driver.FindElement(By.Id("seventh"));
50+
IWebElement lowest = driver.FindElement(By.Id("bottomLeft"));
5151

5252
var elements = driver.FindElements(RelativeBy.WithLocator(By.XPath("//td[1]")).Above(lowest));
5353

5454
var values = elements.Select(element => element.GetDomAttribute("id"));
55-
Assert.That(values, Is.EquivalentTo(new List<string> { "fourth", "first" }));
55+
Assert.That(values, Is.EquivalentTo(new List<string> { "left", "topLeft" }));
5656
}
5757

5858
[Test]
@@ -73,10 +73,10 @@ public void ShouldBeAbleToCombineFilters()
7373
{
7474
driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("relative_locators.html"));
7575

76-
ReadOnlyCollection<IWebElement> seen = driver.FindElements(RelativeBy.WithLocator(By.TagName("td")).Above(By.Id("center")).RightOf(By.Id("second")));
76+
ReadOnlyCollection<IWebElement> seen = driver.FindElements(RelativeBy.WithLocator(By.TagName("td")).Above(By.Id("center")).RightOf(By.Id("top")));
7777

7878
var elementIds = seen.Select(element => element.GetDomAttribute("id"));
79-
Assert.That(elementIds, Is.EquivalentTo(new List<string>() { "third" }));
79+
Assert.That(elementIds, Is.EquivalentTo(new List<string>() { "topRight" }));
8080
}
8181

8282

@@ -85,10 +85,10 @@ public void ShouldBeAbleToCombineFiltersWithXpath()
8585
{
8686
driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("relative_locators.html"));
8787

88-
ReadOnlyCollection<IWebElement> seen = driver.FindElements(RelativeBy.WithLocator(By.XPath("//td[1]")).Below(By.Id("second")).Above(By.Id("seventh")));
88+
ReadOnlyCollection<IWebElement> seen = driver.FindElements(RelativeBy.WithLocator(By.XPath("//td[1]")).Below(By.Id("top")).Above(By.Id("bottomLeft")));
8989

9090
var values = seen.Select(element => element.GetDomAttribute("id"));
91-
Assert.That(values, Is.EquivalentTo(new List<string> { "fourth" }));
91+
Assert.That(values, Is.EquivalentTo(new List<string> { "left" }));
9292
}
9393

9494
[Test]
@@ -97,10 +97,10 @@ public void ShouldBeAbleToCombineFiltersWithCssSelector()
9797
driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("relative_locators.html"));
9898

9999
ReadOnlyCollection<IWebElement> seen = driver.FindElements(
100-
RelativeBy.WithLocator(By.CssSelector("td")).Above(By.Id("center")).RightOf(By.Id("second")));
100+
RelativeBy.WithLocator(By.CssSelector("td")).Above(By.Id("center")).RightOf(By.Id("top")));
101101

102102
var values = seen.Select(element => element.GetDomAttribute("id"));
103-
Assert.That(values, Is.EquivalentTo(new List<string> { "third" }));
103+
Assert.That(values, Is.EquivalentTo(new List<string> { "topRight" }));
104104
}
105105

106106
[Test]
@@ -120,7 +120,7 @@ public void ExerciseNearLocatorWithTagName()
120120
// 5-8. Diagonally close (pythagoras sorting, with top row first
121121
// because of DOM insertion order)
122122
var values = seen.Select(element => element.GetDomAttribute("id"));
123-
Assert.That(values, Is.EquivalentTo(new List<string> { "second", "eighth", "fourth", "sixth", "first", "third", "seventh", "ninth" }));
123+
Assert.That(values, Is.EquivalentTo(new List<string> { "top", "bottom", "left", "right", "topLeft", "topRight", "bottomLeft", "bottomRight" }));
124124
}
125125

126126
[Test]
@@ -140,7 +140,7 @@ public void ExerciseNearLocatorWithXpath()
140140
// 5-8. Diagonally close (pythagoras sorting, with top row first
141141
// because of DOM insertion order)
142142
var values = seen.Select(element => element.GetDomAttribute("id"));
143-
Assert.That(values, Is.EquivalentTo(new List<string> { "second", "eighth", "fourth", "sixth", "first", "third", "seventh", "ninth" }));
143+
Assert.That(values, Is.EquivalentTo(new List<string> { "top", "bottom", "left", "right", "topLeft", "topRight", "bottomLeft", "bottomRight" }));
144144
}
145145

146146
[Test]
@@ -160,7 +160,7 @@ public void ExerciseNearLocatorWithCssSelector()
160160
// 5-8. Diagonally close (pythagoras sorting, with top row first
161161
// because of DOM insertion order)
162162
var values = seen.Select(element => element.GetDomAttribute("id"));
163-
Assert.That(values, Is.EquivalentTo(new List<string> { "second", "eighth", "fourth", "sixth", "first", "third", "seventh", "ninth" }));
163+
Assert.That(values, Is.EquivalentTo(new List<string> { "top", "bottom", "left", "right", "topLeft", "topRight", "bottomLeft", "bottomRight" }));
164164
}
165165

166166
[Test]
@@ -218,11 +218,11 @@ public void NearLocatorShouldNotFindFarElements()
218218
{
219219
driver.Url = (EnvironmentManager.Instance.UrlBuilder.WhereIs("relative_locators.html"));
220220

221-
var rect3 = driver.FindElement(By.Id("rect3"));
221+
var rect = driver.FindElement(By.Id("rect1"));
222222

223223
Assert.That(() =>
224224
{
225-
var rect2 = driver.FindElement(RelativeBy.WithLocator(By.Id("rect4")).Near(rect3));
225+
var rect2 = driver.FindElement(RelativeBy.WithLocator(By.Id("rect4")).Near(rect));
226226

227227
}, Throws.TypeOf<NoSuchElementException>().With.Message.EqualTo("Unable to find element; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception"));
228228
}

java/src/org/openqa/selenium/Proxy.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Optional;
2727
import java.util.function.Consumer;
2828
import java.util.stream.Collectors;
29+
import org.jspecify.annotations.NullMarked;
30+
import org.jspecify.annotations.Nullable;
2931

3032
/**
3133
* Configuration parameters for using proxies in WebDriver. Generally you should pass an object of
@@ -34,6 +36,7 @@
3436
* configuration. That is, it is an error to set an <code>httpProxy</code> manually and then turn on
3537
* proxy autodetect.
3638
*/
39+
@NullMarked
3740
public class Proxy {
3841

3942
public enum ProxyType {
@@ -77,15 +80,15 @@ public String toString() {
7780

7881
private ProxyType proxyType = ProxyType.UNSPECIFIED;
7982
private boolean autodetect = false;
80-
private String ftpProxy;
81-
private String httpProxy;
82-
private String noProxy;
83-
private String sslProxy;
84-
private String socksProxy;
85-
private Integer socksVersion;
86-
private String socksUsername;
87-
private String socksPassword;
88-
private String proxyAutoconfigUrl;
83+
private @Nullable String ftpProxy;
84+
private @Nullable String httpProxy;
85+
private @Nullable String noProxy;
86+
private @Nullable String sslProxy;
87+
private @Nullable String socksProxy;
88+
private @Nullable Integer socksVersion;
89+
private @Nullable String socksUsername;
90+
private @Nullable String socksPassword;
91+
private @Nullable String proxyAutoconfigUrl;
8992

9093
public Proxy() {
9194
// Empty default constructor
@@ -120,7 +123,7 @@ public Proxy(Map<String, ?> raw) {
120123
setters.put(AUTODETECT, value -> setAutodetect((Boolean) value));
121124
raw.forEach(
122125
(key, value) -> {
123-
if (key != null && value != null) {
126+
if (key != null && value != null && setters.containsKey(key)) {
124127
setters.get(key).accept(value);
125128
}
126129
});
@@ -223,7 +226,7 @@ public Proxy setAutodetect(boolean autodetect) {
223226
*
224227
* @return the FTP proxy hostname if present, or null if not set
225228
*/
226-
public String getFtpProxy() {
229+
public @Nullable String getFtpProxy() {
227230
return ftpProxy;
228231
}
229232

@@ -245,7 +248,7 @@ public Proxy setFtpProxy(String ftpProxy) {
245248
*
246249
* @return the HTTP proxy hostname if present, or null if not set
247250
*/
248-
public String getHttpProxy() {
251+
public @Nullable String getHttpProxy() {
249252
return httpProxy;
250253
}
251254

@@ -267,7 +270,7 @@ public Proxy setHttpProxy(String httpProxy) {
267270
*
268271
* @return The proxy bypass (noproxy) addresses
269272
*/
270-
public String getNoProxy() {
273+
public @Nullable String getNoProxy() {
271274
return noProxy;
272275
}
273276

@@ -289,7 +292,7 @@ public Proxy setNoProxy(String noProxy) {
289292
*
290293
* @return the SSL tunnel proxy hostname if present, null otherwise
291294
*/
292-
public String getSslProxy() {
295+
public @Nullable String getSslProxy() {
293296
return sslProxy;
294297
}
295298

@@ -311,7 +314,7 @@ public Proxy setSslProxy(String sslProxy) {
311314
*
312315
* @return the SOCKS proxy if present, null otherwise
313316
*/
314-
public String getSocksProxy() {
317+
public @Nullable String getSocksProxy() {
315318
return socksProxy;
316319
}
317320

@@ -333,7 +336,7 @@ public Proxy setSocksProxy(String socksProxy) {
333336
*
334337
* @return the SOCKS version if present, null otherwise
335338
*/
336-
public Integer getSocksVersion() {
339+
public @Nullable Integer getSocksVersion() {
337340
return socksVersion;
338341
}
339342

@@ -355,7 +358,7 @@ public Proxy setSocksVersion(Integer socksVersion) {
355358
*
356359
* @return the SOCKS proxy's username
357360
*/
358-
public String getSocksUsername() {
361+
public @Nullable String getSocksUsername() {
359362
return socksUsername;
360363
}
361364

@@ -377,7 +380,7 @@ public Proxy setSocksUsername(String username) {
377380
*
378381
* @return the SOCKS proxy's password
379382
*/
380-
public String getSocksPassword() {
383+
public @Nullable String getSocksPassword() {
381384
return socksPassword;
382385
}
383386

@@ -399,7 +402,7 @@ public Proxy setSocksPassword(String password) {
399402
*
400403
* @return the proxy auto-configuration URL
401404
*/
402-
public String getProxyAutoconfigUrl() {
405+
public @Nullable String getProxyAutoconfigUrl() {
403406
return proxyAutoconfigUrl;
404407
}
405408

@@ -428,7 +431,7 @@ private void verifyProxyTypeCompatibility(ProxyType compatibleProxy) {
428431
}
429432

430433
@SuppressWarnings({"unchecked"})
431-
public static Proxy extractFrom(Capabilities capabilities) {
434+
public static @Nullable Proxy extractFrom(Capabilities capabilities) {
432435
Object rawProxy = capabilities.getCapability("proxy");
433436
Proxy proxy = null;
434437
if (rawProxy != null) {
@@ -472,7 +475,7 @@ public String toString() {
472475
}
473476

474477
@Override
475-
public boolean equals(Object o) {
478+
public boolean equals(@Nullable Object o) {
476479
if (this == o) {
477480
return true;
478481
}

java/src/org/openqa/selenium/print/PageMargin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import org.jspecify.annotations.NullMarked;
2223

24+
@NullMarked
2325
public class PageMargin {
2426
private final double top;
2527
private final double bottom;

0 commit comments

Comments
 (0)