Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2ae5417
First step to not dispose driver process
nvborisenko Oct 27, 2024
b2fe911
Ability to specify whether to dispose inner driver service for Chrome
nvborisenko Oct 27, 2024
0c6699e
Simplify parameter
nvborisenko Oct 27, 2024
b3ea344
Remove dispose service param from chromium ctor
nvborisenko Nov 23, 2024
c789b68
Remove and simplify creation of default driver service
nvborisenko Nov 23, 2024
f90d364
Remove strange service types
nvborisenko Nov 23, 2024
aff5b83
Fix tests execution, but service is still not disposed yet
nvborisenko Nov 23, 2024
57b3a69
Fix tests execution, but service is still not disposed yet
nvborisenko Nov 23, 2024
62716d5
Revert "Fix tests execution, but service is still not disposed yet"
nvborisenko Nov 24, 2024
912bc7e
Merge branch 'dotnet-reusable-driverservice' of https://github.com/nv…
nvborisenko Nov 24, 2024
f1fc244
Chrome and Edge are good
nvborisenko Nov 24, 2024
ed72189
Merge remote-tracking branch 'upstream/trunk' into dotnet-reusable-dr…
nvborisenko Nov 26, 2024
f9143e5
Update DriverFactory.cs
nvborisenko Nov 26, 2024
ad5c170
Remove enableLogging unused parameter
nvborisenko Nov 26, 2024
164828f
Remove service from event
nvborisenko Nov 26, 2024
f16c08e
Revert "Remove service from event"
nvborisenko Nov 26, 2024
8dd2d6a
Split driver and service
nvborisenko Nov 26, 2024
74db60d
Thread safe driver service
nvborisenko Nov 26, 2024
87369ad
Rename to GetOrCreate
nvborisenko Nov 26, 2024
5565e0e
Merge remote-tracking branch 'upstream/trunk' into dotnet-reusable-dr…
nvborisenko Jan 10, 2025
20cb7ef
Remove Console.WriteLine
nvborisenko Jan 10, 2025
9db68e6
Highlight the issue
nvborisenko Jan 10, 2025
2b3852d
Fix temp tests to dispose in time
nvborisenko Jan 10, 2025
bd45673
More testing
nvborisenko Jan 10, 2025
6b96b82
Don't parallelize to be sure
nvborisenko Jan 10, 2025
edc7577
Merge remote-tracking branch 'upstream/trunk' into dotnet-reusable-dr…
nvborisenko Jan 11, 2025
c1c48d1
And for FF
nvborisenko Jan 11, 2025
07861c5
Chromium and firefox are good
nvborisenko Jan 11, 2025
6a2d3c0
Chain of disposal
nvborisenko Jan 11, 2025
12ca527
Disable parallelization for bidi fixture
nvborisenko Jan 11, 2025
d23443e
Safari?
nvborisenko Jan 11, 2025
e9626e6
Safari is tested
nvborisenko Jan 11, 2025
8ea2b30
Fix issue when service is shared and browser is not installed
nvborisenko Jan 11, 2025
2fc07b2
InternetExplorer!
nvborisenko Jan 11, 2025
dbf3ab0
IE doesn't allow setting of binary location
nvborisenko Jan 11, 2025
934b72e
Investigation off concurrency
nvborisenko Jan 11, 2025
1cc04a6
Rename make to avoid unnecessary changes
nvborisenko Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions dotnet/src/webdriver/Chrome/ChromeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ChromeDriver()
/// </summary>
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
public ChromeDriver(ChromeOptions options)
: this(ChromeDriverService.CreateDefaultService(), options, RemoteWebDriver.DefaultCommandTimeout)
: this(ChromeDriverService.CreateDefaultService(), disposeService: true, options, RemoteWebDriver.DefaultCommandTimeout)
{
}

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

Expand All @@ -148,7 +148,12 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options)
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
: base(service, options, commandTimeout)
: this(service, disposeService: false, options, commandTimeout)
{
}

private ChromeDriver(ChromeDriverService service, bool disposeService, ChromeOptions options, TimeSpan commandTimeout)
: base(service, disposeService, options, commandTimeout)
{
this.AddCustomChromeCommands();
}
Expand Down
28 changes: 17 additions & 11 deletions dotnet/src/webdriver/Chromium/ChromiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
/// </summary>
public static readonly string SetPermissionCommand = "setPermission";

private readonly ChromiumDriverService driverService;
private readonly bool disposeDriverService;
private readonly string optionsCapabilityName;
private DevToolsSession devToolsSession;

Expand All @@ -125,11 +127,14 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
/// Initializes a new instance of the <see cref="ChromiumDriver"/> class using the specified <see cref="ChromiumDriverService"/>.
/// </summary>
/// <param name="service">The <see cref="ChromiumDriverService"/> to use.</param>
/// <param name="disposeService">Wheter to dispose the original <paramref name="service"/>.</param>
/// <param name="options">The <see cref="ChromiumOptions"/> to be used with the ChromiumDriver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
protected ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
: base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
protected ChromiumDriver(ChromiumDriverService service, bool disposeService, ChromiumOptions options, TimeSpan commandTimeout)
: base(StartDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
{
this.driverService = service;
this.disposeDriverService = disposeService;
this.optionsCapabilityName = options.CapabilityName;
}

Expand All @@ -141,14 +146,7 @@ protected static IReadOnlyDictionary<string, CommandInfo> ChromiumCustomCommands
get { return new ReadOnlyDictionary<string, CommandInfo>(chromiumCustomCommands); }
}

/// <summary>
/// Uses DriverFinder to set Service attributes if necessary when creating the command executor
/// </summary>
/// <param name="service"></param>
/// <param name="commandTimeout"></param>
/// <param name="options"></param>
/// <returns></returns>
private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
private static ICommandExecutor StartDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
{
if (service.DriverServicePath == null)
{
Expand All @@ -162,7 +160,10 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi
options.BrowserVersion = null;
}
}
return new DriverServiceCommandExecutor(service, commandTimeout);

service.Start();

return new HttpCommandExecutor(service.ServiceUrl, commandTimeout);
}

/// <summary>
Expand Down Expand Up @@ -469,6 +470,11 @@ protected override void Dispose(bool disposing)
this.devToolsSession.Dispose();
this.devToolsSession = null;
}

if (this.disposeDriverService)
{
this.driverService.Dispose();
}
}

base.Dispose(disposing);
Expand Down
57 changes: 31 additions & 26 deletions dotnet/src/webdriver/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class DriverService : ICommandServer
private bool hideCommandPromptWindow;
private bool isDisposed;
private Process driverServiceProcess;
private object driverServiceProcessLock = new object();
private TimeSpan initializationTimeout = TimeSpan.FromSeconds(20);

/// <summary>
Expand Down Expand Up @@ -258,38 +259,42 @@ public void Dispose()
/// </summary>
public void Start()
{
if (this.driverServiceProcess != null)
if (this.driverServiceProcess is null)
{
return;
}

this.driverServiceProcess = new Process();
lock (this.driverServiceProcessLock)
{
if (driverServiceProcess is null)
{
this.driverServiceProcess = new Process();

if (this.driverServicePath != null)
{
this.driverServiceProcess.StartInfo.FileName = Path.Combine(this.driverServicePath, this.driverServiceExecutableName);
}
else
{
this.driverServiceProcess.StartInfo.FileName = new DriverFinder(this.GetDefaultDriverOptions()).GetDriverPath();
}
if (this.driverServicePath != null)
{
this.driverServiceProcess.StartInfo.FileName = Path.Combine(this.driverServicePath, this.driverServiceExecutableName);
}
else
{
this.driverServiceProcess.StartInfo.FileName = new DriverFinder(this.GetDefaultDriverOptions()).GetDriverPath();
}

this.driverServiceProcess.StartInfo.Arguments = this.CommandLineArguments;
this.driverServiceProcess.StartInfo.UseShellExecute = false;
this.driverServiceProcess.StartInfo.CreateNoWindow = this.hideCommandPromptWindow;
this.driverServiceProcess.StartInfo.Arguments = this.CommandLineArguments;
this.driverServiceProcess.StartInfo.UseShellExecute = false;
this.driverServiceProcess.StartInfo.CreateNoWindow = this.hideCommandPromptWindow;

DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(this.driverServiceProcess.StartInfo);
this.OnDriverProcessStarting(eventArgs);
DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(this.driverServiceProcess.StartInfo);
this.OnDriverProcessStarting(eventArgs);

this.driverServiceProcess.Start();
bool serviceAvailable = this.WaitForServiceInitialization();
DriverProcessStartedEventArgs processStartedEventArgs = new DriverProcessStartedEventArgs(this.driverServiceProcess);
this.OnDriverProcessStarted(processStartedEventArgs);
this.driverServiceProcess.Start();
bool serviceAvailable = this.WaitForServiceInitialization();
DriverProcessStartedEventArgs processStartedEventArgs = new DriverProcessStartedEventArgs(this.driverServiceProcess);
this.OnDriverProcessStarted(processStartedEventArgs);

if (!serviceAvailable)
{
string msg = "Cannot start the driver service on " + this.ServiceUrl;
throw new WebDriverException(msg);
if (!serviceAvailable)
{
string msg = "Cannot start the driver service on " + this.ServiceUrl;
throw new WebDriverException(msg);
}
}
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions dotnet/src/webdriver/Edge/EdgeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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.CreateDefaultService(), disposeService: true, options, RemoteWebDriver.DefaultCommandTimeout)
{
}

Expand Down Expand Up @@ -96,7 +96,7 @@ public EdgeDriver(string edgeDriverDirectory, 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(string edgeDriverDirectory, EdgeOptions options, TimeSpan commandTimeout)
: this(EdgeDriverService.CreateDefaultService(edgeDriverDirectory), options, commandTimeout)
: this(EdgeDriverService.CreateDefaultService(edgeDriverDirectory), disposeService: true, options, commandTimeout)
{
}

Expand All @@ -118,7 +118,12 @@ 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)
: this(service, disposeService: false, options, commandTimeout)
{
}

private EdgeDriver(EdgeDriverService service, bool disposeService, EdgeOptions options, TimeSpan commandTimeout)
: base(service, disposeService, options, commandTimeout)
{
this.AddCustomEdgeCommands();
}
Expand Down
9 changes: 6 additions & 3 deletions dotnet/src/webdriver/Firefox/FirefoxDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
/// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
: base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
: base(StartDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
{
// Add the custom commands unique to Firefox
this.AddCustomFirefoxCommands();
Expand All @@ -201,7 +201,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeS
/// <param name="commandTimeout"></param>
/// <param name="options"></param>
/// <returns></returns>
private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
private static ICommandExecutor StartDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
{
if (service.DriverServicePath == null)
{
Expand All @@ -215,7 +215,10 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi
options.BrowserVersion = null;
}
}
return new DriverServiceCommandExecutor(service, commandTimeout);

service.Start();

return new HttpCommandExecutor(service.ServiceUrl, commandTimeout);
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions dotnet/src/webdriver/IE/InternetExplorerDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public InternetExplorerDriver(InternetExplorerDriverService service, InternetExp
/// <param name="options">The <see cref="InternetExplorerOptions"/> used to initialize the driver.</param>
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
public InternetExplorerDriver(InternetExplorerDriverService service, InternetExplorerOptions options, TimeSpan commandTimeout)
: base(GenerateDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
: base(StartDriverServiceCommandExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
{
}

Expand All @@ -153,7 +153,7 @@ public InternetExplorerDriver(InternetExplorerDriverService service, InternetExp
/// <param name="commandTimeout"></param>
/// <param name="options"></param>
/// <returns></returns>
private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
private static ICommandExecutor StartDriverServiceCommandExecutor(DriverService service, DriverOptions options, TimeSpan commandTimeout)
{
if (service.DriverServicePath == null)
{
Expand All @@ -162,7 +162,10 @@ private static ICommandExecutor GenerateDriverServiceCommandExecutor(DriverServi
service.DriverServicePath = Path.GetDirectoryName(fullServicePath);
service.DriverServiceExecutableName = Path.GetFileName(fullServicePath);
}
return new DriverServiceCommandExecutor(service, commandTimeout);

service.Start();

return new HttpCommandExecutor(service.ServiceUrl, commandTimeout);
}

/// <summary>
Expand Down
Loading
Loading