Skip to content

Commit fd9d556

Browse files
committed
Adding option for .NET EdgeDriverService to use W3C protocol dialect
The Microsoft Edge driver specifies the use of the W3C WebDriver Specification dialect of the JSON wire protocol via a command-line switch. This commit exposes that behavior in the form of a property on the EdgeDriverService object. Note that this command-line switch is only valid for versions of the driver executable for Windows 10 versions later than the 2018 Fall Creators Update version (this is the code-named "Redstone 4", or "RS4" builds). Attempting to use this property with versions of MicrosoftWebDriver.exe before RS4 will result in errors, as the driver executable will not start properly with an unknown command-line switch. This commit also makes use of the fact that in RS4 and beyond, the driver executable is a feature that is installed in the OS, not a separate download, so the test projects have been updated to reflect this.
1 parent cc40e51 commit fd9d556

File tree

4 files changed

+96
-9
lines changed

4 files changed

+96
-9
lines changed

dotnet/src/webdriver/Edge/EdgeDriverService.cs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="EdgeDriverService.cs" company="Microsoft">
1+
// <copyright file="EdgeDriverService.cs" company="Microsoft">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -33,6 +33,7 @@ public sealed class EdgeDriverService : DriverService
3333
private string host;
3434
private string package;
3535
private bool useVerboseLogging;
36+
private bool useSpecCompliantProtocol;
3637

3738
/// <summary>
3839
/// Initializes a new instance of the <see cref="EdgeDriverService"/> class.
@@ -72,6 +73,60 @@ public bool UseVerboseLogging
7273
set { this.useVerboseLogging = value; }
7374
}
7475

76+
/// <summary>
77+
/// Gets or sets a value indicating whether the <see cref="EdgeDriverService"/> instance
78+
/// should use the a protocol dialect compliant with the W3C WebDriver Specification.
79+
/// </summary>
80+
/// <remarks>
81+
/// Setting this property for driver executables matched to versions of
82+
/// Windows before the 2018 Fall Creators Update will result in a the
83+
/// driver executable shutting down without execution, and all commands
84+
/// will fail. Do not set this property unless you are certain your version
85+
/// of the MicrosoftWebDriver.exe supports the --w3c command-line argument.
86+
/// </remarks>
87+
public bool UseSpecCompliantProtocol
88+
{
89+
get { return this.useSpecCompliantProtocol; }
90+
set { this.useSpecCompliantProtocol = value; }
91+
}
92+
93+
/// <summary>
94+
/// Gets a value indicating whether the service has a shutdown API that can be called to terminate
95+
/// it gracefully before forcing a termination.
96+
/// </summary>
97+
protected override bool HasShutdown
98+
{
99+
get
100+
{
101+
if (this.useSpecCompliantProtocol)
102+
{
103+
return false;
104+
}
105+
106+
return base.HasShutdown;
107+
}
108+
}
109+
110+
/// <summary>
111+
/// Gets a value indicating the time to wait for the service to terminate before forcing it to terminate.
112+
/// </summary>
113+
protected override TimeSpan TerminationTimeout
114+
{
115+
// Use a very small timeout for terminating the Firefox driver,
116+
// because the executable does not have a clean shutdown command,
117+
// which means we have to kill the process. Using a short timeout
118+
// gets us to the termination point much faster.
119+
get
120+
{
121+
if (this.useSpecCompliantProtocol)
122+
{
123+
return TimeSpan.FromMilliseconds(100);
124+
}
125+
126+
return base.TerminationTimeout;
127+
}
128+
}
129+
75130
/// <summary>
76131
/// Gets the command-line arguments for the driver service.
77132
/// </summary>
@@ -95,6 +150,16 @@ protected override string CommandLineArguments
95150
argsBuilder.Append(" --verbose");
96151
}
97152

153+
if (this.SuppressInitialDiagnosticInformation)
154+
{
155+
argsBuilder.Append(" --silent");
156+
}
157+
158+
if (this.useSpecCompliantProtocol)
159+
{
160+
argsBuilder.Append(" --w3c");
161+
}
162+
98163
return argsBuilder.ToString();
99164
}
100165
}

dotnet/test/common/Environment/DriverFactory.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ public IWebDriver CreateDriver(Type driverType)
5353
return (IWebDriver)ctorInfo.Invoke(new object[] { service });
5454
}
5555

56-
if (typeof(EdgeDriver).IsAssignableFrom(driverType))
57-
{
58-
EdgeDriverService service = EdgeDriverService.CreateDefaultService(this.driverPath);
59-
constructorArgTypeList.Add(typeof(EdgeDriverService));
60-
ConstructorInfo ctorInfo = driverType.GetConstructor(constructorArgTypeList.ToArray());
61-
return (IWebDriver)ctorInfo.Invoke(new object[] { service });
62-
}
63-
6456
if (typeof(FirefoxDriver).IsAssignableFrom(driverType))
6557
{
6658
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(this.driverPath);

dotnet/test/common/appconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
"RemoteCapabilities": "MicrosoftEdge"
4141
},
4242

43+
"EdgeSpec": {
44+
"DriverTypeName": "OpenQA.Selenium.Edge.SpecCompliantEdgeDriver",
45+
"AssemblyName": "WebDriver.Edge.Tests",
46+
"BrowserValue": "Edge",
47+
"RemoteCapabilities": "MicrosoftEdge"
48+
},
49+
4350
"Firefox": {
4451
"DriverTypeName": "OpenQA.Selenium.Firefox.ReleaseFirefoxWebDriver",
4552
"AssemblyName": "WebDriver.Firefox.Tests",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace OpenQA.Selenium.Edge
8+
{
9+
public class SpecCompliantEdgeDriver : EdgeDriver
10+
{
11+
public SpecCompliantEdgeDriver() :
12+
base(CreateSpecCompliantEdgeDriverService(), new EdgeOptions())
13+
{
14+
}
15+
16+
private static EdgeDriverService CreateSpecCompliantEdgeDriverService()
17+
{
18+
EdgeDriverService service = EdgeDriverService.CreateDefaultService();
19+
service.UseSpecCompliantProtocol = true;
20+
return service;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)