Skip to content

Commit

Permalink
[dotnet] Update Chromium-based browsers to correclty inherit Options
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jun 4, 2021
1 parent 70af0d6 commit b754461
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Chrome/ChromeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ChromeOptions : ChromiumOptions
/// <summary>
/// Initializes a new instance of the <see cref="ChromeOptions"/> class.
/// </summary>
public ChromeOptions()
public ChromeOptions() : base()
{
this.BrowserName = BrowserNameValue;
}
Expand Down
24 changes: 1 addition & 23 deletions dotnet/src/webdriver/Edge/EdgeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,8 @@ 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(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options, service.UsingChromium))
: base(service, options, commandTimeout)
{
}

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();
}
}
}
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/Edge/EdgeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class EdgeOptions : ChromiumOptions
/// <summary>
/// Initializes a new instance of the <see cref="EdgeOptions"/> class.
/// </summary>
public EdgeOptions()
public EdgeOptions() : base()
{
this.BrowserName = DefaultBrowserNameValue;
this.AddKnownCapabilityName(UseChromiumCapability, "UseChromium property");
Expand Down
52 changes: 52 additions & 0 deletions dotnet/test/common/CustomDriverConfigs/StableChannelEdgeDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenQA.Selenium.Edge
{
public class StableChannelEdgeDriver : EdgeDriver
{
private static string servicePath = string.Empty;

public StableChannelEdgeDriver()
: this(DefaultService, DefaultOptions)
{
}

public StableChannelEdgeDriver(EdgeDriverService service, EdgeOptions options)
: base(service, options)
{
}

public static EdgeOptions DefaultOptions
{
get {
// The below path to the Edge Developer Channel executable is obviously hard-coded.
// On non-Windows OSes, and for custom install locations, you will need to add a
// property to the below options: BinaryLocation = <path to MSEdge.exe>
return new EdgeOptions()
{
UseChromium = true,
BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
};
}
}

public static EdgeDriverService DefaultService
{
get
{
EdgeDriverService service = EdgeDriverService.CreateChromiumService(ServicePath);
return service;
}
}

public static string ServicePath
{
get { return servicePath; }
set { servicePath = value; }
}
}
}
7 changes: 7 additions & 0 deletions dotnet/test/common/appconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
},

"Edge": {
"DriverTypeName": "OpenQA.Selenium.Edge.StableChannelEdgeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Edge",
"RemoteCapabilities": "MicrosoftEdge"
},

"EdgeDev": {
"DriverTypeName": "OpenQA.Selenium.Edge.DevChannelEdgeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Edge",
Expand Down

0 comments on commit b754461

Please sign in to comment.