Skip to content

Commit 13d830b

Browse files
bwaldermanjimevans
authored andcommitted
Use a capability to switch engines for .NET EdgeOptions/EdgeDriverService.
Signed-off-by: Jim Evans <[email protected]>
1 parent 3842544 commit 13d830b

File tree

7 files changed

+247
-240
lines changed

7 files changed

+247
-240
lines changed

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ public ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, Ti
7373
this.AddCustomChromeCommand(SendChromeCommandWithResult, CommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
7474
}
7575

76+
/// <summary>
77+
/// Initializes a new instance of the <see cref="ChromiumDriver"/> class
78+
/// </summary>
79+
/// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
80+
/// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
81+
protected ChromiumDriver(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
82+
: base(commandExecutor, desiredCapabilities)
83+
{
84+
}
85+
7686
/// <summary>
7787
/// Gets or sets the <see cref="IFileDetector"/> responsible for detecting
7888
/// sequences of keystrokes representing file paths and names.

dotnet/src/webdriver/Chromium/ChromiumDriverService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected override string CommandLineArguments
172172
/// <summary>
173173
/// Returns the Chromium driver filename for the currently running platform
174174
/// </summary>
175-
/// <param name="fileName">The name of the Chromium executable. Defaulit is "chromedriver".</param>
175+
/// <param name="fileName">The name of the Chromium executable. Default is "chromedriver".</param>
176176
/// <returns>The file name of the Chromium driver service executable.</returns>
177177
protected static string ChromiumDriverServiceFileName(string fileName = DefaultChromeDriverServiceExecutableName)
178178
{

dotnet/src/webdriver/Chromium/ChromiumOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ public override ICapabilities ToCapabilities()
561561
IWritableCapabilities capabilities = this.GenerateDesiredCapabilities(false);
562562
capabilities.SetCapability(this.CapabilityName, chromeOptions);
563563

564+
AddVendorSpecificChromiumCapabilities(capabilities);
565+
564566
Dictionary<string, object> loggingPreferences = this.GenerateLoggingPreferencesDictionary();
565567
if (loggingPreferences != null)
566568
{
@@ -570,6 +572,8 @@ public override ICapabilities ToCapabilities()
570572
return capabilities.AsReadOnly();
571573
}
572574

575+
protected virtual void AddVendorSpecificChromiumCapabilities(IWritableCapabilities capabilities) { }
576+
573577
private Dictionary<string, object> BuildChromeOptionsDictionary()
574578
{
575579
Dictionary<string, object> chromeOptions = new Dictionary<string, object>();

dotnet/src/webdriver/Edge/EdgeDriver.cs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public EdgeDriver()
4040
/// </summary>
4141
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
4242
public EdgeDriver(EdgeOptions options)
43-
: this(EdgeDriverService.CreateDefaultService(), options)
43+
: this(EdgeDriverService.CreateDefaultServiceFromOptions(options), options)
4444
{
4545
}
4646

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

5656
/// <summary>
5757
/// Initializes a new instance of the <see cref="EdgeDriver"/> class using the specified path
58-
/// to the directory containing EdgeDriver.exe.
58+
/// to the directory containing the WebDriver executable.
5959
/// </summary>
60-
/// <param name="edgeDriverDirectory">The full path to the directory containing EdgeDriver.exe.</param>
60+
/// <param name="edgeDriverDirectory">The full path to the directory containing the WebDriver executable.</param>
6161
public EdgeDriver(string edgeDriverDirectory)
6262
: this(edgeDriverDirectory, new EdgeOptions())
6363
{
6464
}
6565

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

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

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

111+
private static ICapabilities ConvertOptionsToCapabilities(EdgeOptions options, bool serviceUsingChromium)
112+
{
113+
if (options == null)
114+
{
115+
throw new ArgumentNullException("options", "options must not be null");
116+
}
117+
118+
if (serviceUsingChromium != options.UseChromium)
119+
{
120+
if (serviceUsingChromium)
121+
{
122+
throw new WebDriverException("options.UseChromium must be set to true when using an Edge Chromium driver service.");
123+
}
124+
else
125+
{
126+
throw new WebDriverException("options.UseChromium must be set to false when using an Edge Legacy driver service.");
127+
}
128+
}
129+
130+
return options.ToCapabilities();
131+
}
111132
}
112133
}

0 commit comments

Comments
 (0)