Skip to content

Commit 7b0f681

Browse files
Merge branch 'trunk' into webelement-nullable-2
2 parents d895b6b + 9b0ccf1 commit 7b0f681

File tree

19 files changed

+234
-31
lines changed

19 files changed

+234
-31
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>

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 }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
const network = require('../bidi/network')
18+
const { Network: getNetwork } = require('../bidi/network')
1919
const { InterceptPhase } = require('../bidi/interceptPhase')
2020
const { AddInterceptParameters } = require('../bidi/addInterceptParameters')
2121

@@ -39,7 +39,7 @@ class Network {
3939
if (this.#network !== undefined) {
4040
return
4141
}
42-
this.#network = await network(this.#driver)
42+
this.#network = await getNetwork(this.#driver)
4343

4444
await this.#network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
4545

javascript/node/selenium-webdriver/test/bidi/add_intercept_parameters_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const assert = require('node:assert')
2121
const { Browser } = require('selenium-webdriver')
2222
const { suite } = require('../../lib/test')
23-
const Network = require('selenium-webdriver/bidi/network')
23+
const { Network } = require('selenium-webdriver/bidi/network')
2424
const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')
2525
const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')
2626
const { UrlPattern } = require('selenium-webdriver/bidi/urlPattern')

javascript/node/selenium-webdriver/test/bidi/network_commands_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const assert = require('node:assert')
2121
const { Browser, By } = require('selenium-webdriver')
2222
const { Pages, suite } = require('../../lib/test')
23-
const Network = require('selenium-webdriver/bidi/network')
23+
const { Network } = require('selenium-webdriver/bidi/network')
2424
const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')
2525
const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')
2626
const { until } = require('selenium-webdriver/index')

0 commit comments

Comments
 (0)