Skip to content

Commit 8105e74

Browse files
authored
Merge branch 'trunk' into mfest
2 parents b149a63 + 4a0d05e commit 8105e74

30 files changed

+319
-414
lines changed

dotnet/src/webdriver/Command.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,27 @@ private static Dictionary<string, object> ConvertParametersFromJson(string value
157157
// Selenium WebDriver types
158158
[JsonSerializable(typeof(char[]))]
159159
[JsonSerializable(typeof(byte[]))]
160-
[JsonSerializable(typeof(Dictionary<string, object>))]
161160
[JsonSerializable(typeof(Cookie))]
162161
[JsonSerializable(typeof(ReturnedCookie))]
163162
[JsonSerializable(typeof(Proxy))]
164-
internal partial class CommandJsonSerializerContext : JsonSerializerContext
165-
{
166163

167-
}
164+
// Selenium Dictionaries, primarily used in Capabilities
165+
[JsonSerializable(typeof(Dictionary<string, object>))]
166+
167+
[JsonSerializable(typeof(Dictionary<string, bool>))]
168+
[JsonSerializable(typeof(Dictionary<string, byte>))]
169+
[JsonSerializable(typeof(Dictionary<string, sbyte>))]
170+
[JsonSerializable(typeof(Dictionary<string, char>))]
171+
[JsonSerializable(typeof(Dictionary<string, decimal>))]
172+
[JsonSerializable(typeof(Dictionary<string, double>))]
173+
[JsonSerializable(typeof(Dictionary<string, float>))]
174+
[JsonSerializable(typeof(Dictionary<string, int>))]
175+
[JsonSerializable(typeof(Dictionary<string, uint>))]
176+
[JsonSerializable(typeof(Dictionary<string, nint>))]
177+
[JsonSerializable(typeof(Dictionary<string, nuint>))]
178+
[JsonSerializable(typeof(Dictionary<string, long>))]
179+
[JsonSerializable(typeof(Dictionary<string, ulong>))]
180+
[JsonSerializable(typeof(Dictionary<string, short>))]
181+
[JsonSerializable(typeof(Dictionary<string, ushort>))]
182+
internal partial class CommandJsonSerializerContext : JsonSerializerContext;
168183
}

java/src/org/openqa/selenium/By.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static By cssSelector(String cssSelector) {
121121
public WebElement findElement(SearchContext context) {
122122
List<WebElement> allElements = findElements(context);
123123
if (allElements == null || allElements.isEmpty()) {
124-
throw new NoSuchElementException("Cannot locate an element using " + toString());
124+
throw new NoSuchElementException("Cannot locate an element using " + this);
125125
}
126126
return allElements.get(0);
127127
}

java/src/org/openqa/selenium/JavascriptExecutor.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium;
1919

20-
import java.util.Collections;
2120
import java.util.Set;
2221
import java.util.stream.Collectors;
2322
import org.jspecify.annotations.NullMarked;
@@ -177,10 +176,9 @@ default void unpin(ScriptKey key) {
177176
* @return The {@link ScriptKey}s of all currently pinned scripts.
178177
*/
179178
default Set<ScriptKey> getPinnedScripts() {
180-
return Collections.unmodifiableSet(
181-
UnpinnedScriptKey.getPinnedScripts(this).stream()
182-
.map(key -> (ScriptKey) key)
183-
.collect(Collectors.toSet()));
179+
return UnpinnedScriptKey.getPinnedScripts(this).stream()
180+
.map(key -> (ScriptKey) key)
181+
.collect(Collectors.toUnmodifiableSet());
184182
}
185183

186184
/**

java/src/org/openqa/selenium/WebElement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ public interface WebElement extends SearchContext, TakesScreenshot {
165165
*
166166
* @param name The name of the attribute.
167167
* @return The attribute/property's current value or null if the value is not set.
168+
* @deprecated This method is deprecated. Use {@link #getDomProperty(String)} or {@link
169+
* #getDomAttribute(String)} for more precise attribute retrieval.
168170
*/
171+
@Deprecated
169172
@Nullable String getAttribute(String name);
170173

171174
/**

java/src/org/openqa/selenium/grid/node/ForwardWebDriverCommand.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
package org.openqa.selenium.grid.node;
1919

20-
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
20+
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
2121
import static org.openqa.selenium.remote.HttpSessionId.getSessionId;
2222
import static org.openqa.selenium.remote.http.Contents.asJson;
2323

24-
import com.google.common.collect.ImmutableMap;
24+
import java.util.Map;
2525
import org.openqa.selenium.internal.Require;
2626
import org.openqa.selenium.remote.SessionId;
2727
import org.openqa.selenium.remote.http.HttpHandler;
@@ -48,10 +48,16 @@ public HttpResponse execute(HttpRequest req) {
4848
return node.executeWebDriverCommand(req);
4949
}
5050
return new HttpResponse()
51-
.setStatus(HTTP_INTERNAL_ERROR)
51+
.setStatus(HTTP_NOT_FOUND)
5252
.setContent(
5353
asJson(
54-
ImmutableMap.of(
55-
"error", String.format("Session not found in node %s", node.getId()))));
54+
Map.of(
55+
"value",
56+
Map.of(
57+
"error", "invalid session id",
58+
"message",
59+
"Cannot find session with id: "
60+
+ getSessionId(req.getUri()).orElse(null),
61+
"stacktrace", ""))));
5662
}
5763
}

java/src/org/openqa/selenium/grid/node/Node.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,7 @@ protected Node(
154154
combine(
155155
// "getSessionId" is aggressive about finding session ids, so this needs to be the last
156156
// route that is checked.
157-
matching(
158-
req ->
159-
getSessionId(req.getUri())
160-
.map(SessionId::new)
161-
.map(sessionId -> this.getSession(sessionId) != null)
162-
.orElse(false))
157+
matching(req -> getSessionId(req.getUri()).map(SessionId::new).isPresent())
163158
.to(() -> new ForwardWebDriverCommand(this))
164159
.with(spanDecorator("node.forward_command")),
165160
new CustomLocatorHandler(this, registrationSecret, customLocators),

java/src/org/openqa/selenium/support/pagefactory/ByAll.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public WebElement findElement(SearchContext context) {
5454
return elements.get(0);
5555
}
5656
}
57-
throw new NoSuchElementException("Cannot locate an element using " + toString());
57+
throw new NoSuchElementException("Cannot locate an element using " + this);
5858
}
5959

6060
@Override

java/src/org/openqa/selenium/support/pagefactory/ByChained.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ByChained(By... bys) {
5252
public WebElement findElement(SearchContext context) {
5353
List<WebElement> elements = findElements(context);
5454
if (elements.isEmpty())
55-
throw new NoSuchElementException("Cannot locate an element using " + toString());
55+
throw new NoSuchElementException("Cannot locate an element using " + this);
5656
return elements.get(0);
5757
}
5858

java/test/org/openqa/selenium/WebNetworkTest.java

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,34 @@
2222

2323
import java.net.URI;
2424
import java.util.function.Predicate;
25-
import org.junit.jupiter.api.AfterEach;
26-
import org.junit.jupiter.api.BeforeEach;
2725
import org.junit.jupiter.api.Test;
28-
import org.openqa.selenium.environment.webserver.AppServer;
29-
import org.openqa.selenium.environment.webserver.NettyAppServer;
3026
import org.openqa.selenium.remote.RemoteWebDriver;
3127
import org.openqa.selenium.testing.Ignore;
3228
import org.openqa.selenium.testing.JupiterTestBase;
29+
import org.openqa.selenium.testing.NeedsFreshDriver;
3330
import org.openqa.selenium.testing.drivers.Browser;
3431

3532
class WebNetworkTest extends JupiterTestBase {
3633

3734
private String page;
38-
private AppServer server;
39-
40-
@BeforeEach
41-
public void setUp() {
42-
server = new NettyAppServer();
43-
server.start();
44-
}
45-
46-
@AfterEach
47-
public void cleanUp() {
48-
driver.quit();
49-
}
5035

5136
@Test
37+
@NeedsFreshDriver
5238
@Ignore(Browser.CHROME)
5339
@Ignore(Browser.EDGE)
5440
void canAddAuthenticationHandler() {
5541
((RemoteWebDriver) driver)
5642
.network()
5743
.addAuthenticationHandler(new UsernameAndPassword("test", "test"));
5844

59-
page = server.whereIs("basicAuth");
45+
page = appServer.whereIs("basicAuth");
6046
driver.get(page);
6147

6248
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
6349
}
6450

6551
@Test
52+
@NeedsFreshDriver
6653
@Ignore(Browser.CHROME)
6754
@Ignore(Browser.EDGE)
6855
void canAddAuthenticationHandlerWithFilter() {
@@ -72,13 +59,14 @@ void canAddAuthenticationHandlerWithFilter() {
7259
.network()
7360
.addAuthenticationHandler(filter, new UsernameAndPassword("test", "test"));
7461

75-
page = server.whereIs("basicAuth");
62+
page = appServer.whereIs("basicAuth");
7663
driver.get(page);
7764

7865
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
7966
}
8067

8168
@Test
69+
@NeedsFreshDriver
8270
@Ignore(Browser.CHROME)
8371
@Ignore(Browser.EDGE)
8472
void canAddMultipleAuthenticationHandlersWithFilter() {
@@ -92,13 +80,14 @@ void canAddMultipleAuthenticationHandlersWithFilter() {
9280
.addAuthenticationHandler(
9381
uri -> uri.getPath().contains("test"), new UsernameAndPassword("test1", "test1"));
9482

95-
page = server.whereIs("basicAuth");
83+
page = appServer.whereIs("basicAuth");
9684
driver.get(page);
9785

9886
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
9987
}
10088

10189
@Test
90+
@NeedsFreshDriver
10291
@Ignore(Browser.CHROME)
10392
@Ignore(Browser.EDGE)
10493
void canAddMultipleAuthenticationHandlersWithTheSameFilter() {
@@ -112,13 +101,14 @@ void canAddMultipleAuthenticationHandlersWithTheSameFilter() {
112101
.addAuthenticationHandler(
113102
uri -> uri.getPath().contains("basicAuth"), new UsernameAndPassword("test", "test"));
114103

115-
page = server.whereIs("basicAuth");
104+
page = appServer.whereIs("basicAuth");
116105
driver.get(page);
117106

118107
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
119108
}
120109

121110
@Test
111+
@NeedsFreshDriver
122112
@Ignore(Browser.CHROME)
123113
@Ignore(Browser.EDGE)
124114
void canRemoveAuthenticationHandler() {
@@ -128,26 +118,28 @@ void canRemoveAuthenticationHandler() {
128118
.addAuthenticationHandler(new UsernameAndPassword("test", "test"));
129119

130120
((RemoteWebDriver) driver).network().removeAuthenticationHandler(id);
131-
page = server.whereIs("basicAuth");
121+
page = appServer.whereIs("basicAuth");
132122
driver.get(page);
133123

134124
assertThatExceptionOfType(UnhandledAlertException.class)
135125
.isThrownBy(() -> driver.findElement(By.tagName("h1")));
136126
}
137127

138128
@Test
129+
@NeedsFreshDriver
139130
@Ignore(Browser.CHROME)
140131
@Ignore(Browser.EDGE)
141132
void canRemoveAuthenticationHandlerThatDoesNotExist() {
142133
((RemoteWebDriver) driver).network().removeAuthenticationHandler(5);
143-
page = server.whereIs("basicAuth");
134+
page = appServer.whereIs("basicAuth");
144135
driver.get(page);
145136

146137
assertThatExceptionOfType(UnhandledAlertException.class)
147138
.isThrownBy(() -> driver.findElement(By.tagName("h1")));
148139
}
149140

150141
@Test
142+
@NeedsFreshDriver
151143
@Ignore(Browser.CHROME)
152144
@Ignore(Browser.EDGE)
153145
void canClearAuthenticationHandlers() {
@@ -165,7 +157,7 @@ void canClearAuthenticationHandlers() {
165157
.addAuthenticationHandler(new UsernameAndPassword("test1", "test1"));
166158

167159
((RemoteWebDriver) driver).network().clearAuthenticationHandlers();
168-
page = server.whereIs("basicAuth");
160+
page = appServer.whereIs("basicAuth");
169161
driver.get(page);
170162

171163
assertThatExceptionOfType(UnhandledAlertException.class)

0 commit comments

Comments
 (0)