Skip to content

Commit 2c94fad

Browse files
authored
Merge branch 'trunk' into pyo3
2 parents e43ec44 + 77796f4 commit 2c94fad

18 files changed

+258
-408
lines changed

dotnet/src/webdriver/Chromium/ChromiumDriverService.cs

+38-75
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using System.Globalization;
2222
using System.Text;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.Chromium
2527
{
2628
/// <summary>
@@ -30,15 +32,6 @@ public abstract class ChromiumDriverService : DriverService
3032
{
3133
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";
3234

33-
private string logPath = string.Empty;
34-
private string urlPathPrefix = string.Empty;
35-
private string portServerAddress = string.Empty;
36-
private string allowedIPAddresses = string.Empty;
37-
private int adbPort = -1;
38-
private bool disableBuildCheck;
39-
private bool enableVerboseLogging;
40-
private bool enableAppendLog;
41-
4235
/// <summary>
4336
/// Initializes a new instance of the <see cref="ChromiumDriverService"/> class.
4437
/// </summary>
@@ -51,94 +44,64 @@ protected ChromiumDriverService(string executablePath, string executableFileName
5144
}
5245

5346
/// <summary>
54-
/// Gets or sets the location of the log file written to by the ChromeDriver executable.
47+
/// <para>Gets or sets the location of the log file written to by the ChromeDriver executable.</para>
48+
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no log path.</para>
5549
/// </summary>
56-
public string LogPath
57-
{
58-
get { return this.logPath; }
59-
set { this.logPath = value; }
60-
}
50+
public string? LogPath { get; set; }
6151

6252
/// <summary>
63-
/// Gets or sets the base URL path prefix for commands (e.g., "wd/url").
53+
/// <para>Gets or sets the base URL path prefix for commands (e.g., "wd/url").</para>
54+
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no prefix.</para>
6455
/// </summary>
65-
public string UrlPathPrefix
66-
{
67-
get { return this.urlPathPrefix; }
68-
set { this.urlPathPrefix = value; }
69-
}
56+
public string? UrlPathPrefix { get; set; }
7057

7158
/// <summary>
72-
/// Gets or sets the address of a server to contact for reserving a port.
59+
/// <para>Gets or sets the address of a server to contact for reserving a port.</para>
60+
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no port server.</para>
7361
/// </summary>
74-
public string PortServerAddress
75-
{
76-
get { return this.portServerAddress; }
77-
set { this.portServerAddress = value; }
78-
}
62+
public string? PortServerAddress { get; set; }
7963

8064
/// <summary>
81-
/// Gets or sets the port on which the Android Debug Bridge is listening for commands.
65+
/// <para>Gets or sets the port on which the Android Debug Bridge is listening for commands.</para>
66+
/// <para>A value less than or equal to 0, or <see langword="null"/>, indicates no Android Debug Bridge specified.</para>
8267
/// </summary>
83-
public int AndroidDebugBridgePort
84-
{
85-
get { return this.adbPort; }
86-
set { this.adbPort = value; }
87-
}
68+
public int? AndroidDebugBridgePort { get; set; }
8869

8970
/// <summary>
9071
/// Gets or sets a value indicating whether to skip version compatibility check
9172
/// between the driver and the browser.
9273
/// Defaults to <see langword="false"/>.
9374
/// </summary>
94-
public bool DisableBuildCheck
95-
{
96-
get { return this.disableBuildCheck; }
97-
set { this.disableBuildCheck = value; }
98-
}
75+
public bool DisableBuildCheck { get; set; }
9976

10077
/// <summary>
10178
/// Gets or sets a value indicating whether to enable verbose logging for the ChromeDriver executable.
10279
/// Defaults to <see langword="false"/>.
10380
/// </summary>
104-
public bool EnableVerboseLogging
105-
{
106-
get { return this.enableVerboseLogging; }
107-
set { this.enableVerboseLogging = value; }
108-
}
81+
public bool EnableVerboseLogging { get; set; }
10982

11083
/// <summary>
11184
/// Gets or sets a value indicating whether to enable appending to an existing ChromeDriver log file.
11285
/// Defaults to <see langword="false"/>.
11386
/// </summary>
114-
public bool EnableAppendLog
115-
{
116-
get { return this.enableAppendLog; }
117-
set { this.enableAppendLog = value; }
118-
}
87+
public bool EnableAppendLog { get; set; }
11988

12089
/// <summary>
121-
/// Gets or sets the comma-delimited list of IP addresses that are approved to
122-
/// connect to this instance of the Chrome driver. Defaults to an empty string,
123-
/// which means only the local loopback address can connect.
90+
/// <para>Gets or sets the comma-delimited list of IP addresses that are approved to connect to this instance of the Chrome driver.</para>
91+
/// <para>A value of <see langword="null"/> or <see cref="string.Empty"/> means only the local loopback address can connect.</para>
12492
/// </summary>
12593
[Obsolete($"Use {nameof(AllowedIPAddresses)}")]
126-
public string WhitelistedIPAddresses
94+
public string? WhitelistedIPAddresses
12795
{
128-
get { return this.allowedIPAddresses; }
129-
set { this.allowedIPAddresses = value; }
96+
get => this.AllowedIPAddresses;
97+
set => this.AllowedIPAddresses = value;
13098
}
13199

132100
/// <summary>
133-
/// Gets or sets the comma-delimited list of IP addresses that are approved to
134-
/// connect to this instance of the Chrome driver. Defaults to an empty string,
135-
/// which means only the local loopback address can connect.
101+
/// <para>Gets or sets the comma-delimited list of IP addresses that are approved to connect to this instance of the Chrome driver.</para>
102+
/// <para>A value of <see langword="null"/> or <see cref="string.Empty"/> means only the local loopback address can connect.</para>
136103
/// </summary>
137-
public string AllowedIPAddresses
138-
{
139-
get => this.allowedIPAddresses;
140-
set => this.allowedIPAddresses = value;
141-
}
104+
public string? AllowedIPAddresses { get; set; }
142105

143106
/// <summary>
144107
/// Gets the command-line arguments for the driver service.
@@ -148,49 +111,49 @@ protected override string CommandLineArguments
148111
get
149112
{
150113
StringBuilder argsBuilder = new StringBuilder(base.CommandLineArguments);
151-
if (this.adbPort > 0)
114+
if (this.AndroidDebugBridgePort is int adb && adb > 0)
152115
{
153-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", this.adbPort);
116+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", adb);
154117
}
155118

156119
if (this.SuppressInitialDiagnosticInformation)
157120
{
158121
argsBuilder.Append(" --silent");
159122
}
160123

161-
if (this.disableBuildCheck)
124+
if (this.DisableBuildCheck)
162125
{
163126
argsBuilder.Append(" --disable-build-check");
164127
}
165128

166-
if (this.enableVerboseLogging)
129+
if (this.EnableVerboseLogging)
167130
{
168131
argsBuilder.Append(" --verbose");
169132
}
170133

171-
if (this.enableAppendLog)
134+
if (this.EnableAppendLog)
172135
{
173136
argsBuilder.Append(" --append-log");
174137
}
175138

176-
if (!string.IsNullOrEmpty(this.logPath))
139+
if (!string.IsNullOrEmpty(this.LogPath))
177140
{
178-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.logPath);
141+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.LogPath);
179142
}
180143

181-
if (!string.IsNullOrEmpty(this.urlPathPrefix))
144+
if (!string.IsNullOrEmpty(this.UrlPathPrefix))
182145
{
183-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.urlPathPrefix);
146+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.UrlPathPrefix);
184147
}
185148

186-
if (!string.IsNullOrEmpty(this.portServerAddress))
149+
if (!string.IsNullOrEmpty(this.PortServerAddress))
187150
{
188-
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.portServerAddress);
151+
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.PortServerAddress);
189152
}
190153

191-
if (!string.IsNullOrEmpty(this.allowedIPAddresses))
154+
if (!string.IsNullOrEmpty(this.AllowedIPAddresses))
192155
{
193-
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.allowedIPAddresses));
156+
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.AllowedIPAddresses));
194157
}
195158

196159
return argsBuilder.ToString();

dotnet/src/webdriver/Command.cs

+18-31
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,21 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.Internal;
21+
using System;
2122
using System.Collections.Generic;
2223
using System.Text.Json;
2324
using System.Text.Json.Serialization;
2425
using System.Text.Json.Serialization.Metadata;
2526

27+
#nullable enable
28+
2629
namespace OpenQA.Selenium
2730
{
2831
/// <summary>
2932
/// Provides a way to send commands to the remote server
3033
/// </summary>
3134
public class Command
3235
{
33-
private SessionId commandSessionId;
34-
private string commandName;
35-
private Dictionary<string, object> commandParameters = new Dictionary<string, object>();
36-
3736
private readonly static JsonSerializerOptions s_jsonSerializerOptions = new()
3837
{
3938
TypeInfoResolver = JsonTypeInfoResolver.Combine(CommandJsonSerializerContext.Default, new DefaultJsonTypeInfoResolver()),
@@ -56,43 +55,30 @@ public Command(string name, string jsonParameters)
5655
/// <param name="sessionId">Session ID the driver is using</param>
5756
/// <param name="name">Name of the command</param>
5857
/// <param name="parameters">Parameters for that command</param>
59-
public Command(SessionId sessionId, string name, Dictionary<string, object> parameters)
58+
public Command(SessionId? sessionId, string name, Dictionary<string, object>? parameters)
6059
{
61-
this.commandSessionId = sessionId;
62-
if (parameters != null)
63-
{
64-
this.commandParameters = parameters;
65-
}
66-
67-
this.commandName = name;
60+
this.SessionId = sessionId;
61+
this.Parameters = parameters ?? new Dictionary<string, object>();
62+
this.Name = name;
6863
}
6964

7065
/// <summary>
7166
/// Gets the SessionID of the command
7267
/// </summary>
7368
[JsonPropertyName("sessionId")]
74-
public SessionId SessionId
75-
{
76-
get { return this.commandSessionId; }
77-
}
69+
public SessionId? SessionId { get; }
7870

7971
/// <summary>
8072
/// Gets the command name
8173
/// </summary>
8274
[JsonPropertyName("name")]
83-
public string Name
84-
{
85-
get { return this.commandName; }
86-
}
75+
public string Name { get; }
8776

8877
/// <summary>
8978
/// Gets the parameters of the command
9079
/// </summary>
9180
[JsonPropertyName("parameters")]
92-
public Dictionary<string, object> Parameters
93-
{
94-
get { return this.commandParameters; }
95-
}
81+
public Dictionary<string, object> Parameters { get; }
9682

9783
/// <summary>
9884
/// Gets the parameters of the command as a JSON-encoded string.
@@ -101,13 +87,12 @@ public string ParametersAsJsonString
10187
{
10288
get
10389
{
104-
string parametersString = string.Empty;
105-
if (this.commandParameters != null && this.commandParameters.Count > 0)
90+
string parametersString;
91+
if (this.Parameters != null && this.Parameters.Count > 0)
10692
{
107-
parametersString = JsonSerializer.Serialize(this.commandParameters, s_jsonSerializerOptions);
93+
parametersString = JsonSerializer.Serialize(this.Parameters, s_jsonSerializerOptions);
10894
}
109-
110-
if (string.IsNullOrEmpty(parametersString))
95+
else
11196
{
11297
parametersString = "{}";
11398
}
@@ -130,9 +115,11 @@ public override string ToString()
130115
/// </summary>
131116
/// <param name="value">The JSON-encoded string representing the command parameters.</param>
132117
/// <returns>A <see cref="Dictionary{K, V}"/> with a string keys, and an object value. </returns>
133-
private static Dictionary<string, object> ConvertParametersFromJson(string value)
118+
/// <exception cref="JsonException">If <paramref name="value"/> is not a JSON object.</exception>
119+
/// <exception cref="ArgumentNullException">If <paramref name="value"/> is <see langword="null"/>.</exception>
120+
private static Dictionary<string, object>? ConvertParametersFromJson(string value)
134121
{
135-
Dictionary<string, object> parameters = JsonSerializer.Deserialize<Dictionary<string, object>>(value, s_jsonSerializerOptions);
122+
Dictionary<string, object>? parameters = JsonSerializer.Deserialize<Dictionary<string, object>>(value, s_jsonSerializerOptions);
136123
return parameters;
137124
}
138125
}

dotnet/src/webdriver/Cookie.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
277277
{
278278
if (rawCookie == null)
279279
{
280-
throw new ArgumentNullException(nameof(rawCookie), "Dictionary cannot be null");
280+
throw new ArgumentNullException(nameof(rawCookie));
281281
}
282282

283283
string name = rawCookie["name"].ToString();

dotnet/src/webdriver/CookieJar.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void DeleteAllCookies()
127127
{
128128
var rawCookie = driver.InternalExecute(DriverCommand.GetCookie, new() { { "name", name } }).Value;
129129

130-
return Cookie.FromDictionary((Dictionary<string, object>)rawCookie);
130+
return Cookie.FromDictionary((Dictionary<string, object>)rawCookie!);
131131
}
132132
catch (NoSuchCookieException)
133133
{

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
125125
private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
126126
{
127127
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
128-
{
129-
BrowserContextId = e.TargetInfo.BrowserContextId,
130-
IsAttached = e.TargetInfo.Attached,
131-
OpenerId = e.TargetInfo.OpenerId,
132-
TargetId = e.TargetInfo.TargetId,
133-
Title = e.TargetInfo.Title,
134-
Type = e.TargetInfo.Type,
135-
Url = e.TargetInfo.Url
128+
{
129+
BrowserContextId = e.TargetInfo.BrowserContextId,
130+
IsAttached = e.TargetInfo.Attached,
131+
OpenerId = e.TargetInfo.OpenerId,
132+
TargetId = e.TargetInfo.TargetId,
133+
Title = e.TargetInfo.Title,
134+
Type = e.TargetInfo.Type,
135+
Url = e.TargetInfo.Url
136136
};
137137

138138
this.OnTargetAttached(new TargetAttachedEventArgs

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
125125
private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
126126
{
127127
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
128-
{
129-
BrowserContextId = e.TargetInfo.BrowserContextId,
130-
IsAttached = e.TargetInfo.Attached,
131-
OpenerId = e.TargetInfo.OpenerId,
132-
TargetId = e.TargetInfo.TargetId,
133-
Title = e.TargetInfo.Title,
134-
Type = e.TargetInfo.Type,
135-
Url = e.TargetInfo.Url
128+
{
129+
BrowserContextId = e.TargetInfo.BrowserContextId,
130+
IsAttached = e.TargetInfo.Attached,
131+
OpenerId = e.TargetInfo.OpenerId,
132+
TargetId = e.TargetInfo.TargetId,
133+
Title = e.TargetInfo.Title,
134+
Type = e.TargetInfo.Type,
135+
Url = e.TargetInfo.Url
136136
};
137137

138138
this.OnTargetAttached(new TargetAttachedEventArgs

0 commit comments

Comments
 (0)