Skip to content

Commit f1fc244

Browse files
committed
Chrome and Edge are good
1 parent 912bc7e commit f1fc244

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

dotnet/src/webdriver/Chrome/ChromeDriver.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public ChromeDriver()
8383
/// </summary>
8484
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
8585
public ChromeDriver(ChromeOptions options)
86-
: this(ChromeDriverService.CreateDefaultService(), options, RemoteWebDriver.DefaultCommandTimeout)
86+
: this(ChromeDriverService.CreateDefaultService(), disposeService: true, options, RemoteWebDriver.DefaultCommandTimeout)
8787
{
8888
}
8989

@@ -125,7 +125,7 @@ public ChromeDriver(string chromeDriverDirectory, ChromeOptions options)
125125
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
126126
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
127127
public ChromeDriver(string chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)
128-
: this(ChromeDriverService.CreateDefaultService(chromeDriverDirectory), options, commandTimeout)
128+
: this(ChromeDriverService.CreateDefaultService(chromeDriverDirectory), disposeService: true, options, commandTimeout)
129129
{
130130
}
131131

@@ -147,7 +147,12 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options)
147147
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
148148
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
149149
public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
150-
: base(service, options, commandTimeout)
150+
: this(service, disposeService: false, options, commandTimeout)
151+
{
152+
}
153+
154+
private ChromeDriver(ChromeDriverService service, bool disposeService, ChromeOptions options, TimeSpan commandTimeout)
155+
: base(service, disposeService, options, commandTimeout)
151156
{
152157
this.AddCustomChromeCommands();
153158
}

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
107107
public static readonly string SetPermissionCommand = "setPermission";
108108

109109
private readonly ChromiumDriverService driverService;
110+
private readonly bool disposeDriverService;
110111
private readonly string optionsCapabilityName;
111112
private DevToolsSession devToolsSession;
112113

@@ -125,12 +126,14 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
125126
/// Initializes a new instance of the <see cref="ChromiumDriver"/> class using the specified <see cref="ChromiumDriverService"/>.
126127
/// </summary>
127128
/// <param name="service">The <see cref="ChromiumDriverService"/> to use.</param>
129+
/// <param name="disposeService">Wheter to dispose the original <paramref name="service"/>.</param>
128130
/// <param name="options">The <see cref="ChromiumOptions"/> to be used with the ChromiumDriver.</param>
129131
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
130-
protected ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
132+
protected ChromiumDriver(ChromiumDriverService service, bool disposeService, ChromiumOptions options, TimeSpan commandTimeout)
131133
: base(StartDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
132134
{
133135
this.driverService = service;
136+
this.disposeDriverService = disposeService;
134137
this.optionsCapabilityName = options.CapabilityName;
135138
}
136139

@@ -466,6 +469,11 @@ protected override void Dispose(bool disposing)
466469
this.devToolsSession.Dispose();
467470
this.devToolsSession = null;
468471
}
472+
473+
if (this.disposeDriverService)
474+
{
475+
this.driverService.Dispose();
476+
}
469477
}
470478

471479
base.Dispose(disposing);

dotnet/src/webdriver/Edge/EdgeDriver.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public EdgeDriver()
5353
/// </summary>
5454
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
5555
public EdgeDriver(EdgeOptions options)
56-
: this(EdgeDriverService.CreateDefaultService(), options)
56+
: this(EdgeDriverService.CreateDefaultService(), disposeService: true, options, RemoteWebDriver.DefaultCommandTimeout)
5757
{
5858
}
5959

@@ -95,7 +95,7 @@ public EdgeDriver(string edgeDriverDirectory, EdgeOptions options)
9595
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
9696
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
9797
public EdgeDriver(string edgeDriverDirectory, EdgeOptions options, TimeSpan commandTimeout)
98-
: this(EdgeDriverService.CreateDefaultService(edgeDriverDirectory), options, commandTimeout)
98+
: this(EdgeDriverService.CreateDefaultService(edgeDriverDirectory), disposeService: true, options, commandTimeout)
9999
{
100100
}
101101

@@ -117,7 +117,12 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options)
117117
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
118118
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
119119
public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
120-
: base(service, options, commandTimeout)
120+
: this(service, disposeService: false, options, commandTimeout)
121+
{
122+
}
123+
124+
private EdgeDriver(EdgeDriverService service, bool disposeService, EdgeOptions options, TimeSpan commandTimeout)
125+
: base(service, disposeService, options, commandTimeout)
121126
{
122127
this.AddCustomEdgeCommands();
123128
}

0 commit comments

Comments
 (0)