Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Annotate nullability for DriverService and chromium/safari services #15101

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 33 additions & 68 deletions dotnet/src/webdriver/Chromium/ChromiumDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Globalization;
using System.Text;

#nullable enable

namespace OpenQA.Selenium.Chromium
{
/// <summary>
Expand All @@ -30,15 +32,6 @@ public abstract class ChromiumDriverService : DriverService
{
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";

private string logPath = string.Empty;
private string urlPathPrefix = string.Empty;
private string portServerAddress = string.Empty;
private string allowedIPAddresses = string.Empty;
private int adbPort = -1;
private bool disableBuildCheck;
private bool enableVerboseLogging;
private bool enableAppendLog;

/// <summary>
/// Initializes a new instance of the <see cref="ChromiumDriverService"/> class.
/// </summary>
Expand All @@ -51,71 +44,47 @@ protected ChromiumDriverService(string executablePath, string executableFileName
}

/// <summary>
/// Gets or sets the location of the log file written to by the ChromeDriver executable.
/// <para>Gets or sets the location of the log file written to by the ChromeDriver executable.</para>
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no log path.</para>
/// </summary>
public string LogPath
{
get { return this.logPath; }
set { this.logPath = value; }
}
public string? LogPath { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the base URL path prefix for commands (e.g., "wd/url").
/// <para>Gets or sets the base URL path prefix for commands (e.g., "wd/url").</para>
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no prefix.</para>
/// </summary>
public string UrlPathPrefix
{
get { return this.urlPathPrefix; }
set { this.urlPathPrefix = value; }
}
public string? UrlPathPrefix { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the address of a server to contact for reserving a port.
/// <para>Gets or sets the address of a server to contact for reserving a port.</para>
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no port server.</para>
/// </summary>
public string PortServerAddress
{
get { return this.portServerAddress; }
set { this.portServerAddress = value; }
}
public string PortServerAddress { get; set; } = string.Empty;

/// <summary>
/// Gets or sets the port on which the Android Debug Bridge is listening for commands.
/// <para>Gets or sets the port on which the Android Debug Bridge is listening for commands.</para>
/// <para>A value less than or equal to 0 indicates no Android Debug Bridge specified.</para>
/// </summary>
public int AndroidDebugBridgePort
{
get { return this.adbPort; }
set { this.adbPort = value; }
}
public int AndroidDebugBridgePort { get; set; } = -1;

/// <summary>
/// Gets or sets a value indicating whether to skip version compatibility check
/// between the driver and the browser.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool DisableBuildCheck
{
get { return this.disableBuildCheck; }
set { this.disableBuildCheck = value; }
}
public bool DisableBuildCheck { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable verbose logging for the ChromeDriver executable.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool EnableVerboseLogging
{
get { return this.enableVerboseLogging; }
set { this.enableVerboseLogging = value; }
}
public bool EnableVerboseLogging { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable appending to an existing ChromeDriver log file.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool EnableAppendLog
{
get { return this.enableAppendLog; }
set { this.enableAppendLog = value; }
}
public bool EnableAppendLog { get; set; }

/// <summary>
/// Gets or sets the comma-delimited list of IP addresses that are approved to
Expand All @@ -125,20 +94,16 @@ public bool EnableAppendLog
[Obsolete($"Use {nameof(AllowedIPAddresses)}")]
public string WhitelistedIPAddresses
{
get { return this.allowedIPAddresses; }
set { this.allowedIPAddresses = value; }
get => this.AllowedIPAddresses;
set => this.AllowedIPAddresses = value;
}

/// <summary>
/// Gets or sets the comma-delimited list of IP addresses that are approved to
/// connect to this instance of the Chrome driver. Defaults to an empty string,
/// which means only the local loopback address can connect.
/// </summary>
public string AllowedIPAddresses
{
get => this.allowedIPAddresses;
set => this.allowedIPAddresses = value;
}
public string AllowedIPAddresses { get; set; } = string.Empty;

/// <summary>
/// Gets the command-line arguments for the driver service.
Expand All @@ -148,49 +113,49 @@ protected override string CommandLineArguments
get
{
StringBuilder argsBuilder = new StringBuilder(base.CommandLineArguments);
if (this.adbPort > 0)
if (this.AndroidDebugBridgePort > 0)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", this.adbPort);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", this.AndroidDebugBridgePort);
}

if (this.SuppressInitialDiagnosticInformation)
{
argsBuilder.Append(" --silent");
}

if (this.disableBuildCheck)
if (this.DisableBuildCheck)
{
argsBuilder.Append(" --disable-build-check");
}

if (this.enableVerboseLogging)
if (this.EnableVerboseLogging)
{
argsBuilder.Append(" --verbose");
}

if (this.enableAppendLog)
if (this.EnableAppendLog)
{
argsBuilder.Append(" --append-log");
}

if (!string.IsNullOrEmpty(this.logPath))
if (!string.IsNullOrEmpty(this.LogPath))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.logPath);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.LogPath);
}

if (!string.IsNullOrEmpty(this.urlPathPrefix))
if (!string.IsNullOrEmpty(this.UrlPathPrefix))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.urlPathPrefix);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.UrlPathPrefix);
}

if (!string.IsNullOrEmpty(this.portServerAddress))
if (!string.IsNullOrEmpty(this.PortServerAddress))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.portServerAddress);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.PortServerAddress);
}

if (!string.IsNullOrEmpty(this.allowedIPAddresses))
if (!string.IsNullOrEmpty(this.AllowedIPAddresses))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.allowedIPAddresses));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.AllowedIPAddresses));
}

return argsBuilder.ToString();
Expand Down
Loading
Loading