Skip to content

Commit b8a85db

Browse files
RenderMichaelsandeepsuryaprasad
authored andcommitted
[dotnet] Annotate nullability for DriverService and chromium/safari services (SeleniumHQ#15101)
* [dotnet] Annotate nullability for `DriverService` and some derived types * Default values to `null` instead of sentinel values.
1 parent b4d9163 commit b8a85db

File tree

3 files changed

+85
-160
lines changed

3 files changed

+85
-160
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();

0 commit comments

Comments
 (0)