Skip to content

Commit 257f8ff

Browse files
Merge branch 'trunk' into webdriver-nullable-1
2 parents 4c1f3be + 9b0ccf1 commit 257f8ff

File tree

24 files changed

+366
-37
lines changed

24 files changed

+366
-37
lines changed

dotnet/src/webdriver/DevTools/DevToolsDomains.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public abstract class DevToolsDomains
8282
/// Initializes the supplied DevTools session's domains for the specified browser version.
8383
/// </summary>
8484
/// <param name="protocolVersion">The version of the DevTools Protocol to use.</param>
85-
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialiize the domains.</param>
85+
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialize the domains.</param>
8686
/// <returns>The <see cref="DevToolsDomains"/> object containing the version-specific domains.</returns>
8787
/// <exception cref="ArgumentException">If <paramref name="protocolVersion"/> is negative.</exception>
8888
/// <exception cref="WebDriverException">If the desired protocol version is not supported.</exception>
@@ -95,7 +95,7 @@ public static DevToolsDomains InitializeDomains(int protocolVersion, DevToolsSes
9595
/// Initializes the supplied DevTools session's domains for the specified browser version within the specified number of versions.
9696
/// </summary>
9797
/// <param name="protocolVersion">The version of the DevTools Protocol to use.</param>
98-
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialiize the domains.</param>
98+
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialize the domains.</param>
9999
/// <param name="versionRange">The range of versions within which to match the provided version number. Defaults to 5 versions.</param>
100100
/// <returns>The <see cref="DevToolsDomains"/> object containing the version-specific domains.</returns>
101101
/// <exception cref="ArgumentException">If <paramref name="protocolVersion"/> is negative.</exception>

dotnet/src/webdriver/DevTools/v130/V130Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V130
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 130 of the DevTools Protocol.
2428
/// </summary>
2529
public class V130Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V130Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V130Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/DevTools/v131/V131Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V131
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 131 of the DevTools Protocol.
2428
/// </summary>
2529
public class V131Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V131Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V131Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/DevTools/v132/V132Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V132
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 132 of the DevTools Protocol.
2428
/// </summary>
2529
public class V132Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V132Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V132Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/DevTools/v85/V85Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V85
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 86 of the DevTools Protocol.
2428
/// </summary>
2529
public class V85Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V85Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V85Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/Response.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.Internal;
2121
using System;
2222
using System.Collections.Generic;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Globalization;
2425
using System.Text.Json;
2526
using System.Text.Json.Serialization;
@@ -215,6 +216,21 @@ public string ToJson()
215216
return JsonSerializer.Serialize(this);
216217
}
217218

219+
/// <summary>
220+
/// Throws if <see cref="Value"/> is <see langword="null"/>.
221+
/// </summary>
222+
/// <exception cref="WebDriverException">If <see cref="Value"/> is <see langword="null"/>.</exception>
223+
[MemberNotNull(nameof(Value))]
224+
internal Response EnsureValueIsNotNull()
225+
{
226+
if (Value is null)
227+
{
228+
throw new WebDriverException("Response from remote end doesn't have $.Value property");
229+
}
230+
231+
return this;
232+
}
233+
218234
/// <summary>
219235
/// Returns the object as a string.
220236
/// </summary>

java/src/org/openqa/selenium/grid/data/NodeStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static NodeStatus fromJson(JsonInput input) {
7676
Set<Slot> slots = null;
7777
Availability availability = null;
7878
Duration heartbeatPeriod = null;
79-
Duration sessionTimeout = null;
79+
Duration sessionTimeout = Duration.ofSeconds(300);
8080
String version = null;
8181
Map<String, String> osInfo = null;
8282

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,28 @@ public void close() {
511511
if (this.client == null) {
512512
return;
513513
}
514-
this.client = null;
514+
515515
for (WebSocket websocket : websockets) {
516516
try {
517517
websocket.close();
518518
} catch (Exception e) {
519519
LOG.log(Level.WARNING, "failed to close the websocket: " + websocket, e);
520520
}
521521
}
522-
executorService.shutdownNow();
522+
523+
if (this.client instanceof AutoCloseable) {
524+
AutoCloseable closeable = (AutoCloseable) this.client;
525+
executorService.submit(
526+
() -> {
527+
try {
528+
closeable.close();
529+
} catch (Exception e) {
530+
LOG.log(Level.WARNING, "failed to close the http client: " + closeable, e);
531+
}
532+
});
533+
}
534+
this.client = null;
535+
executorService.shutdown();
523536
}
524537

525538
@AutoService(HttpClient.Factory.class)

java/test/org/openqa/selenium/grid/data/NodeStatusTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,79 @@ void ensureRoundTripWorks() throws URISyntaxException {
7272

7373
assertThat(seen).isEqualTo(status);
7474
}
75+
76+
@Test
77+
void withoutSessionTimeoutInJsonStatus() throws URISyntaxException {
78+
String source =
79+
"{\n"
80+
+ " \"availability\": \"UP\",\n"
81+
+ " \"externalUri\": \"http:\\u002f\\u002f192.168.1.101:5555\",\n"
82+
+ " \"heartbeatPeriod\": 60000,\n"
83+
+ " \"maxSessions\": 1,\n"
84+
+ " \"nodeId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
85+
+ " \"osInfo\": {\n"
86+
+ " \"arch\": \"aarch64\",\n"
87+
+ " \"name\": \"Mac OS X\",\n"
88+
+ " \"version\": \"15.3\"\n"
89+
+ " },\n"
90+
+ " \"slots\": [\n"
91+
+ " {\n"
92+
+ " \"id\": {\n"
93+
+ " \"hostId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
94+
+ " \"id\": \"965e8cb4-7b48-4638-8bc8-6889c6319682\"\n"
95+
+ " },\n"
96+
+ " \"lastStarted\": \"1970-01-01T00:00:00Z\",\n"
97+
+ " \"session\": null,\n"
98+
+ " \"stereotype\": {\n"
99+
+ " \"browserName\": \"chrome\",\n"
100+
+ " \"platformName\": \"mac\"\n"
101+
+ " }\n"
102+
+ " }\n"
103+
+ " ],\n"
104+
+ " \"version\": \"4.17.0 (revision unknown*)\"\n"
105+
+ " }";
106+
107+
Json json = new Json();
108+
NodeStatus nodeStatus = json.toType(source, NodeStatus.class);
109+
110+
assertThat(nodeStatus.getSessionTimeout()).isEqualTo(Duration.ofSeconds(300));
111+
}
112+
113+
@Test
114+
void withSessionTimeoutInJsonStatus() throws URISyntaxException {
115+
String source =
116+
"{\n"
117+
+ " \"availability\": \"UP\",\n"
118+
+ " \"externalUri\": \"http:\\u002f\\u002f192.168.1.101:5555\",\n"
119+
+ " \"heartbeatPeriod\": 60000,\n"
120+
+ " \"maxSessions\": 1,\n"
121+
+ " \"sessionTimeout\": 600000,\n"
122+
+ " \"nodeId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
123+
+ " \"osInfo\": {\n"
124+
+ " \"arch\": \"aarch64\",\n"
125+
+ " \"name\": \"Mac OS X\",\n"
126+
+ " \"version\": \"15.3\"\n"
127+
+ " },\n"
128+
+ " \"slots\": [\n"
129+
+ " {\n"
130+
+ " \"id\": {\n"
131+
+ " \"hostId\": \"d136dd9b-6497-4049-9371-42f89b14ea2b\",\n"
132+
+ " \"id\": \"965e8cb4-7b48-4638-8bc8-6889c6319682\"\n"
133+
+ " },\n"
134+
+ " \"lastStarted\": \"1970-01-01T00:00:00Z\",\n"
135+
+ " \"session\": null,\n"
136+
+ " \"stereotype\": {\n"
137+
+ " \"browserName\": \"chrome\",\n"
138+
+ " \"platformName\": \"mac\"\n"
139+
+ " }\n"
140+
+ " }\n"
141+
+ " ],\n"
142+
+ " \"version\": \"4.17.0 (revision unknown*)\"\n"
143+
+ " }";
144+
145+
Json json = new Json();
146+
NodeStatus nodeStatus = json.toType(source, NodeStatus.class);
147+
148+
assertThat(nodeStatus.getSessionTimeout()).isEqualTo(Duration.ofSeconds(600));
149+
}
75150
}

javascript/node/selenium-webdriver/bidi/network.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const NetworkEvent = {
2929
FETCH_ERROR: 'network.fetchError',
3030
}
3131

32+
const CacheBehavior = Object.freeze({
33+
DEFAULT: 'default',
34+
BYPASS: 'bypass',
35+
})
36+
3237
/**
3338
* Represents all commands and events of Network module.
3439
* Described in https://w3c.github.io/webdriver-bidi/#module-network.
@@ -355,6 +360,40 @@ class Network {
355360
await this.bidi.send(command)
356361
}
357362

363+
/**
364+
* Sets the cache behavior for network requests.
365+
*
366+
* @param {string} behavior - The cache behavior ("default" or "bypass")
367+
* @param {Array<string>} [contexts] - Optional array of browsing context IDs
368+
* @returns {Promise<void>} A promise that resolves when the cache behavior is set
369+
* @throws {Error} If behavior is invalid or context IDs are invalid
370+
*/
371+
async setCacheBehavior(behavior, contexts = null) {
372+
if (!Object.values(CacheBehavior).includes(behavior)) {
373+
throw new Error(`Cache behavior must be either "${CacheBehavior.DEFAULT}" or "${CacheBehavior.BYPASS}"`)
374+
}
375+
376+
const command = {
377+
method: 'network.setCacheBehavior',
378+
params: {
379+
cacheBehavior: behavior,
380+
},
381+
}
382+
383+
if (contexts !== null) {
384+
if (
385+
!Array.isArray(contexts) ||
386+
contexts.length === 0 ||
387+
contexts.some((c) => typeof c !== 'string' || c.trim() === '')
388+
) {
389+
throw new Error('Contexts must be an array of non-empty strings')
390+
}
391+
command.params.contexts = contexts
392+
}
393+
394+
await this.bidi.send(command)
395+
}
396+
358397
/**
359398
* Unsubscribes from network events for all browsing contexts.
360399
* @returns {Promise<void>} A promise that resolves when the network connection is closed.
@@ -389,4 +428,4 @@ async function getNetworkInstance(driver, browsingContextIds = null) {
389428
return instance
390429
}
391430

392-
module.exports = getNetworkInstance
431+
module.exports = { Network: getNetworkInstance, CacheBehavior }

0 commit comments

Comments
 (0)