Skip to content
Merged
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
88 changes: 29 additions & 59 deletions dotnet/src/webdriver/Firefox/FirefoxDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using System.IO;
using System.Text;

#nullable enable

namespace OpenQA.Selenium.Firefox
{
/// <summary>
Expand All @@ -32,21 +34,13 @@ public sealed class FirefoxDriverService : DriverService
{
private const string DefaultFirefoxDriverServiceFileName = "geckodriver";

private bool connectToRunningBrowser;
private bool openBrowserToolbox;
private int browserCommunicationPort = -1;
private string browserBinaryPath = string.Empty;
private string host = string.Empty;
private string browserCommunicationHost = string.Empty;
private FirefoxDriverLogLevel loggingLevel = FirefoxDriverLogLevel.Default;

/// <summary>
/// Initializes a new instance of the <see cref="FirefoxDriverService"/> class.
/// </summary>
/// <param name="executablePath">The full path to the Firefox driver executable.</param>
/// <param name="executableFileName">The file name of the Firefox driver executable.</param>
/// <param name="port">The port on which the Firefox driver executable should listen.</param>
private FirefoxDriverService(string executablePath, string executableFileName, int port)
private FirefoxDriverService(string? executablePath, string? executableFileName, int port)
: base(executablePath, port, executableFileName)
{
}
Expand All @@ -60,60 +54,40 @@ protected override DriverOptions GetDefaultDriverOptions()
/// <summary>
/// Gets or sets the location of the Firefox binary executable.
/// </summary>
public string FirefoxBinaryPath
{
get { return this.browserBinaryPath; }
set { this.browserBinaryPath = value; }
}
/// <remarks> A <see langword="null"/> or <see cref="string.Empty"/> value indicates no binary executable path to specify.</remarks>
public string? FirefoxBinaryPath { get; set; }

/// <summary>
/// Gets or sets the port used by the driver executable to communicate with the browser.
/// </summary>
public int BrowserCommunicationPort
{
get { return this.browserCommunicationPort; }
set { this.browserCommunicationPort = value; }
}
/// <remarks>A negative or zero value indicates no port value to specify.</remarks>
public int BrowserCommunicationPort { get; set; } = -1;

/// <summary>
/// Gets or sets the value of the IP address of the host adapter used by the driver
/// executable to communicate with the browser.
/// </summary>
public string BrowserCommunicationHost
{
get { return this.browserCommunicationHost; }
set { this.browserCommunicationHost = value; }
}
/// <remarks> A <see langword="null"/> or <see cref="string.Empty"/> value indicates no marionette host adapter to specify.</remarks>
public string? BrowserCommunicationHost { get; set; }

/// <summary>
/// Gets or sets the value of the IP address of the host adapter on which the
/// service should listen for connections.
/// </summary>
public string Host
{
get { return this.host; }
set { this.host = value; }
}
/// <remarks> A <see langword="null"/> or <see cref="string.Empty"/> value indicates no host to specify.</remarks>
public string? Host { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to connect to an already-running
/// instance of Firefox.
/// </summary>
public bool ConnectToRunningBrowser
{
get { return this.connectToRunningBrowser; }
set { this.connectToRunningBrowser = value; }
}
public bool ConnectToRunningBrowser { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to open the Firefox Browser Toolbox
/// when Firefox is launched.
/// </summary>
public bool OpenBrowserToolbox
{
get { return this.openBrowserToolbox; }
set { this.openBrowserToolbox = value; }
}
public bool OpenBrowserToolbox { get; set; }

/// <summary>
/// Gets or sets the level at which log output is displayed.
Expand All @@ -124,11 +98,7 @@ public bool OpenBrowserToolbox
/// when the browser is launched, meaning that initial driver logging before
/// initiation of a session can be controlled.
/// </remarks>
public FirefoxDriverLogLevel LogLevel
{
get { return this.loggingLevel; }
set { this.loggingLevel = value; }
}
public FirefoxDriverLogLevel LogLevel { get; set; } = FirefoxDriverLogLevel.Default;

/// <summary>
/// Gets a value indicating the time to wait for the service to terminate before forcing it to terminate.
Expand All @@ -139,7 +109,7 @@ protected override TimeSpan TerminationTimeout
// because the executable does not have a clean shutdown command,
// which means we have to kill the process. Using a short timeout
// gets us to the termination point much faster.
get { return TimeSpan.FromMilliseconds(100); }
get => TimeSpan.FromMilliseconds(100);
}

/// <summary>
Expand All @@ -150,7 +120,7 @@ protected override bool HasShutdown
{
// The Firefox driver executable does not have a clean shutdown command,
// which means we have to kill the process.
get { return false; }
get => false;
}

/// <summary>
Expand All @@ -161,7 +131,7 @@ protected override string CommandLineArguments
get
{
StringBuilder argsBuilder = new StringBuilder();
if (this.connectToRunningBrowser)
if (this.ConnectToRunningBrowser)
{
argsBuilder.Append(" --connect-existing");
}
Expand All @@ -170,37 +140,37 @@ protected override string CommandLineArguments
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " --websocket-port {0}", PortUtilities.FindFreePort()));
}

if (this.browserCommunicationPort > 0)
if (this.BrowserCommunicationPort > 0)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --marionette-port {0}", this.browserCommunicationPort);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --marionette-port {0}", this.BrowserCommunicationPort);
}

if (!string.IsNullOrEmpty(this.browserCommunicationHost))
if (!string.IsNullOrEmpty(this.BrowserCommunicationHost))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --marionette-host \"{0}\"", this.browserCommunicationHost);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --marionette-host \"{0}\"", this.BrowserCommunicationHost);
}

if (this.Port > 0)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port {0}", this.Port);
}

if (!string.IsNullOrEmpty(this.browserBinaryPath))
if (!string.IsNullOrEmpty(this.FirefoxBinaryPath))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --binary \"{0}\"", this.browserBinaryPath);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --binary \"{0}\"", this.FirefoxBinaryPath);
}

if (!string.IsNullOrEmpty(this.host))
if (!string.IsNullOrEmpty(this.Host))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --host \"{0}\"", this.host);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --host \"{0}\"", this.Host);
}

if (this.loggingLevel != FirefoxDriverLogLevel.Default)
if (this.LogLevel != FirefoxDriverLogLevel.Default)
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " --log {0}", this.loggingLevel.ToString().ToLowerInvariant()));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " --log {0}", this.LogLevel.ToString().ToLowerInvariant()));
}

if (this.openBrowserToolbox)
if (this.OpenBrowserToolbox)
{
argsBuilder.Append(" --jsdebugger");
}
Expand Down Expand Up @@ -230,7 +200,7 @@ public static FirefoxDriverService CreateDefaultService(string driverPath)
if (File.Exists(driverPath))
{
fileName = Path.GetFileName(driverPath);
driverPath = Path.GetDirectoryName(driverPath);
driverPath = Path.GetDirectoryName(driverPath) ?? throw new ArgumentException("Driver file exists but parent directory is unreachable", nameof(driverPath));
}
else
{
Expand Down
Loading