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 on chrome-based driver services #15154

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions dotnet/src/webdriver/Chrome/ChromeDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using OpenQA.Selenium.Internal;
using System.IO;

#nullable enable

namespace OpenQA.Selenium.Chrome
{
/// <summary>
Expand All @@ -36,7 +38,7 @@ public sealed class ChromeDriverService : ChromiumDriverService
/// <param name="executablePath">The full path to the ChromeDriver executable.</param>
/// <param name="executableFileName">The file name of the ChromeDriver executable.</param>
/// <param name="port">The port on which the ChromeDriver executable should listen.</param>
private ChromeDriverService(string executablePath, string executableFileName, int port)
private ChromeDriverService(string? executablePath, string? executableFileName, int port)
: base(executablePath, executableFileName, port)
{
}
Expand Down Expand Up @@ -67,7 +69,7 @@ public static ChromeDriverService CreateDefaultService(string driverPath)
if (File.Exists(driverPath))
{
fileName = Path.GetFileName(driverPath);
driverPath = Path.GetDirectoryName(driverPath);
driverPath = Path.GetDirectoryName(driverPath)!;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Chromium/ChromiumDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class ChromiumDriverService : DriverService
/// <param name="executablePath">The full path to the ChromeDriver executable.</param>
/// <param name="executableFileName">The file name of the ChromeDriver executable.</param>
/// <param name="port">The port on which the ChromeDriver executable should listen.</param>
protected ChromiumDriverService(string executablePath, string executableFileName, int port)
protected ChromiumDriverService(string? executablePath, string? executableFileName, int port)
: base(executablePath, port, executableFileName)
{
}
Expand Down
10 changes: 6 additions & 4 deletions dotnet/src/webdriver/Edge/EdgeDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using System;
using System.IO;

#nullable enable

namespace OpenQA.Selenium.Edge
{
/// <summary>
Expand All @@ -37,7 +39,7 @@ public sealed class EdgeDriverService : ChromiumDriverService
/// <param name="executablePath">The full path to the EdgeDriver executable.</param>
/// <param name="executableFileName">The file name of the EdgeDriver executable.</param>
/// <param name="port">The port on which the EdgeDriver executable should listen.</param>
private EdgeDriverService(string executablePath, string executableFileName, int port)
private EdgeDriverService(string? executablePath, string? executableFileName, int port)
: base(executablePath, executableFileName, port)
{
}
Expand All @@ -54,8 +56,8 @@ protected override DriverOptions GetDefaultDriverOptions()
[Obsolete("Use EnableVerboseLogging")]
public bool UseVerboseLogging
{
get { return this.EnableVerboseLogging; }
set { this.EnableVerboseLogging = value; }
get => this.EnableVerboseLogging;
set => this.EnableVerboseLogging = value;
}

/// <summary>
Expand All @@ -78,7 +80,7 @@ public static EdgeDriverService CreateDefaultService(string driverPath)
if (File.Exists(driverPath))
{
fileName = Path.GetFileName(driverPath);
driverPath = Path.GetDirectoryName(driverPath);
driverPath = Path.GetDirectoryName(driverPath)!;
}
else
{
Expand Down
97 changes: 36 additions & 61 deletions dotnet/src/webdriver/IE/InternetExplorerDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,24 @@
using System.IO;
using System.Text;

#nullable enable

namespace OpenQA.Selenium.IE
{
/// <summary>
/// Exposes the service provided by the native IEDriverServer executable.
/// Exposes the service provided by the native <c>IEDriverServer</c> executable.
/// </summary>
public sealed class InternetExplorerDriverService : DriverService
{
private const string InternetExplorerDriverServiceFileName = "IEDriverServer.exe";

private InternetExplorerDriverLogLevel loggingLevel = InternetExplorerDriverLogLevel.Fatal;
private string host = string.Empty;
private string logFile = string.Empty;
private string libraryExtractionPath = string.Empty;
private string whitelistedIpAddresses = string.Empty;

/// <summary>
/// Initializes a new instance of the <see cref="InternetExplorerDriverService"/> class.
/// </summary>
/// <param name="executablePath">The full path to the IEDriverServer executable.</param>
/// <param name="executableFileName">The file name of the IEDriverServer executable.</param>
/// <param name="port">The port on which the IEDriverServer executable should listen.</param>
private InternetExplorerDriverService(string executablePath, string executableFileName, int port)
/// <param name="executablePath">The full path to the <c>IEDriverServer</c> executable.</param>
/// <param name="executableFileName">The file name of the <c>IEDriverServer</c> executable.</param>
/// <param name="port">The port on which the <c>IEDriverServer</c> executable should listen.</param>
private InternetExplorerDriverService(string? executablePath, string? executableFileName, int port)
: base(executablePath, port, executableFileName)
{
}
Expand All @@ -55,57 +51,36 @@ protected override DriverOptions GetDefaultDriverOptions()
}

/// <summary>
/// Gets or sets the value of the host adapter on which the IEDriverServer should listen for connections.
/// Gets or sets the value of the host adapter on which the <c>IEDriverServer</c> should listen for connections.
/// </summary>
public string Host
{
get { return this.host; }
set { this.host = value; }
}
public string? Host { get; set; }

/// <summary>
/// Gets or sets the location of the log file written to by the IEDriverServer.
/// Gets or sets the location of the log file written to by the <c>IEDriverServer</c>.
/// </summary>
public string LogFile
{
get { return this.logFile; }
set { this.logFile = value; }
}
public string? LogFile { get; set; }

/// <summary>
/// Gets or sets the logging level used by the IEDriverServer.
/// Gets or sets the logging level used by the <c>IEDriverServer</c>. Defaults to <see cref="InternetExplorerDriverLogLevel.Fatal"/>.
/// </summary>
public InternetExplorerDriverLogLevel LoggingLevel
{
get { return this.loggingLevel; }
set { this.loggingLevel = value; }
}
public InternetExplorerDriverLogLevel LoggingLevel { get; set; } = InternetExplorerDriverLogLevel.Fatal;

/// <summary>
/// Gets or sets the path to which the supporting library of the IEDriverServer.exe is extracted.
/// Defaults to the temp directory if this property is not set.
/// Gets or sets the path to which the supporting library of the <c>IEDriverServer.exe</c> is extracted.
/// Defaults to the temp directory if this property is <see langword="null"/> or <see cref="string.Empty"/>.
/// </summary>
/// <remarks>
/// The IEDriverServer.exe requires extraction of a supporting library to perform some of its functions. Setting
/// The <c>IEDriverServer.exe</c> requires extraction of a supporting library to perform some of its functions. Setting
/// This library is extracted to the temp directory if this property is not set. If the property is set, it must
/// be set to a valid directory.
/// </remarks>
public string LibraryExtractionPath
{
get { return this.libraryExtractionPath; }
set { this.libraryExtractionPath = value; }
}
public string? LibraryExtractionPath { get; set; }

/// <summary>
/// Gets or sets the comma-delimited list of IP addresses that are approved to
/// connect to this instance of the IEDriverServer. Defaults to an empty string,
/// which means only the local loopback address can connect.
/// <para>Gets or sets the comma-delimited list of IP addresses that are approved to connect to this instance of the <c>IEDriverServer</c>.</para>
/// <para>If <see langword="null"/> or <see cref="string.Empty"/>, only the local loopback address can connect.</para>
/// </summary>
public string WhitelistedIPAddresses
{
get { return this.whitelistedIpAddresses; }
set { this.whitelistedIpAddresses = value; }
}
public string? WhitelistedIPAddresses { get; set; }

/// <summary>
/// Gets the command-line arguments for the driver service.
Expand All @@ -115,29 +90,29 @@ protected override string CommandLineArguments
get
{
StringBuilder argsBuilder = new StringBuilder(base.CommandLineArguments);
if (!string.IsNullOrEmpty(this.host))
if (!string.IsNullOrEmpty(this.Host))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -host={0}", this.host));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -host={0}", this.Host));
}

if (!string.IsNullOrEmpty(this.logFile))
if (!string.IsNullOrEmpty(this.LogFile))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-file=\"{0}\"", this.logFile));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-file=\"{0}\"", this.LogFile));
}

if (!string.IsNullOrEmpty(this.libraryExtractionPath))
if (!string.IsNullOrEmpty(this.LibraryExtractionPath))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -extract-path=\"{0}\"", this.libraryExtractionPath));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -extract-path=\"{0}\"", this.LibraryExtractionPath));
}

if (this.loggingLevel != InternetExplorerDriverLogLevel.Fatal)
if (this.LoggingLevel != InternetExplorerDriverLogLevel.Fatal)
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-level={0}", this.loggingLevel.ToString().ToUpperInvariant()));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -log-level={0}", this.LoggingLevel.ToString().ToUpperInvariant()));
}

if (!string.IsNullOrEmpty(this.whitelistedIpAddresses))
if (!string.IsNullOrEmpty(this.WhitelistedIPAddresses))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -whitelisted-ips={0}", this.whitelistedIpAddresses));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -whitelisted-ips={0}", this.WhitelistedIPAddresses));
}

if (this.SuppressInitialDiagnosticInformation)
Expand All @@ -159,17 +134,17 @@ public static InternetExplorerDriverService CreateDefaultService()
}

/// <summary>
/// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable.
/// Creates a default instance of the InternetExplorerDriverService using a specified path to the <c>IEDriverServer</c> executable.
/// </summary>
/// <param name="driverPath">The path to the executable or the directory containing the IEDriverServer executable.</param>
/// <param name="driverPath">The path to the executable or the directory containing the <c>IEDriverServer</c> executable.</param>
/// <returns>A InternetExplorerDriverService using a random port.</returns>
public static InternetExplorerDriverService CreateDefaultService(string driverPath)
{
string fileName;
if (File.Exists(driverPath))
{
fileName = Path.GetFileName(driverPath);
driverPath = Path.GetDirectoryName(driverPath);
driverPath = Path.GetDirectoryName(driverPath)!;
}
else
{
Expand All @@ -180,10 +155,10 @@ public static InternetExplorerDriverService CreateDefaultService(string driverPa
}

/// <summary>
/// Creates a default instance of the InternetExplorerDriverService using a specified path to the IEDriverServer executable with the given name.
/// Creates a default instance of the InternetExplorerDriverService using a specified path to the <c>IEDriverServer</c> executable with the given name.
/// </summary>
/// <param name="driverPath">The directory containing the IEDriverServer executable.</param>
/// <param name="driverExecutableFileName">The name of the IEDriverServer executable file.</param>
/// <param name="driverPath">The directory containing the <c>IEDriverServer</c> executable.</param>
/// <param name="driverExecutableFileName">The name of the <c>IEDriverServer</c> executable file.</param>
/// <returns>A InternetExplorerDriverService using a random port.</returns>
public static InternetExplorerDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
{
Expand Down