Skip to content

Commit

Permalink
Use a capability to switch engines for .NET EdgeOptions/EdgeDriverSer…
Browse files Browse the repository at this point in the history
…vice.

Signed-off-by: Jim Evans <[email protected]>
  • Loading branch information
bwalderman authored and jimevans committed Mar 16, 2020
1 parent 3842544 commit 13d830b
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 240 deletions.
10 changes: 10 additions & 0 deletions dotnet/src/webdriver/Chromium/ChromiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ public ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, Ti
this.AddCustomChromeCommand(SendChromeCommandWithResult, CommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
}

/// <summary>
/// Initializes a new instance of the <see cref="ChromiumDriver"/> class
/// </summary>
/// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
protected ChromiumDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
: base(commandExecutor, desiredCapabilities)
{
}

/// <summary>
/// Gets or sets the <see cref="IFileDetector"/> responsible for detecting
/// sequences of keystrokes representing file paths and names.
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 @@ -172,7 +172,7 @@ protected override string CommandLineArguments
/// <summary>
/// Returns the Chromium driver filename for the currently running platform
/// </summary>
/// <param name="fileName">The name of the Chromium executable. Defaulit is "chromedriver".</param>
/// <param name="fileName">The name of the Chromium executable. Default is "chromedriver".</param>
/// <returns>The file name of the Chromium driver service executable.</returns>
protected static string ChromiumDriverServiceFileName(string fileName = DefaultChromeDriverServiceExecutableName)
{
Expand Down
4 changes: 4 additions & 0 deletions dotnet/src/webdriver/Chromium/ChromiumOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ public override ICapabilities ToCapabilities()
IWritableCapabilities capabilities = this.GenerateDesiredCapabilities(false);
capabilities.SetCapability(this.CapabilityName, chromeOptions);

AddVendorSpecificChromiumCapabilities(capabilities);

Dictionary<string, object> loggingPreferences = this.GenerateLoggingPreferencesDictionary();
if (loggingPreferences != null)
{
Expand All @@ -570,6 +572,8 @@ public override ICapabilities ToCapabilities()
return capabilities.AsReadOnly();
}

protected virtual void AddVendorSpecificChromiumCapabilities(IWritableCapabilities capabilities) { }

private Dictionary<string, object> BuildChromeOptionsDictionary()
{
Dictionary<string, object> chromeOptions = new Dictionary<string, object>();
Expand Down
41 changes: 31 additions & 10 deletions dotnet/src/webdriver/Edge/EdgeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public EdgeDriver()
/// </summary>
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
public EdgeDriver(EdgeOptions options)
: this(EdgeDriverService.CreateDefaultService(), options)
: this(EdgeDriverService.CreateDefaultServiceFromOptions(options), options)
{
}

Expand All @@ -49,25 +49,25 @@ public EdgeDriver(EdgeOptions options)
/// </summary>
/// <param name="service">The <see cref="EdgeDriverService"/> used to initialize the driver.</param>
public EdgeDriver(EdgeDriverService service)
: this(service, new EdgeOptions())
: this(service, new EdgeOptions() { UseChromium = service.UsingChromium })
{
}

/// <summary>
/// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified path
/// to the directory containing EdgeDriver.exe.
/// to the directory containing the WebDriver executable.
/// </summary>
/// <param name="edgeDriverDirectory">The full path to the directory containing EdgeDriver.exe.</param>
/// <param name="edgeDriverDirectory">The full path to the directory containing the WebDriver executable.</param>
public EdgeDriver(string edgeDriverDirectory)
: this(edgeDriverDirectory, new EdgeOptions())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified path
/// to the directory containing EdgeDriver.exe and options.
/// to the directory containing the WebDriver executable and options.
/// </summary>
/// <param name="edgeDriverDirectory">The full path to the directory containing EdgeDriver.exe.</param>
/// <param name="edgeDriverDirectory">The full path to the directory containing the WebDriver executable.</param>
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
public EdgeDriver(string edgeDriverDirectory, EdgeOptions options)
: this(edgeDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout)
Expand All @@ -76,13 +76,13 @@ public EdgeDriver(string edgeDriverDirectory, EdgeOptions options)

/// <summary>
/// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified path
/// to the directory containing EdgeDriver.exe, options, and command timeout.
/// to the directory containing the WebDriver executable, options, and command timeout.
/// </summary>
/// <param name="edgeDriverDirectory">The full path to the directory containing EdgeDriver.exe.</param>
/// <param name="edgeDriverDirectory">The full path to the directory containing the WebDriver executable.</param>
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public EdgeDriver(string edgeDriverDirectory, EdgeOptions options, TimeSpan commandTimeout)
: this(EdgeDriverService.CreateDefaultService(edgeDriverDirectory), options, commandTimeout)
: this(EdgeDriverService.CreateDefaultServiceFromOptions(edgeDriverDirectory, options), options, commandTimeout)
{
}

Expand All @@ -104,9 +104,30 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options)
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
: base(service, options, commandTimeout)
: base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options, service.UsingChromium))
{
}

private static ICapabilities ConvertOptionsToCapabilities(EdgeOptions options, bool serviceUsingChromium)
{
if (options == null)
{
throw new ArgumentNullException("options", "options must not be null");
}

if (serviceUsingChromium != options.UseChromium)
{
if (serviceUsingChromium)
{
throw new WebDriverException("options.UseChromium must be set to true when using an Edge Chromium driver service.");
}
else
{
throw new WebDriverException("options.UseChromium must be set to false when using an Edge Legacy driver service.");
}
}

return options.ToCapabilities();
}
}
}
Loading

0 comments on commit 13d830b

Please sign in to comment.