-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
WIP [dotnet] Reusable DriverService
instance by Drivers
#14662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
WIP [dotnet] Reusable DriverService
instance by Drivers
#14662
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
To move further we have to decide:
@YevgeniyShunevych your input is appreciated here. |
I vote for just fix "old" behavior. If user instantiates |
Remove strange service types Remove and simplify creation of default driver service Remove dispose service param from chromium ctor
This reverts commit 57b3a69.
…borisenko/selenium-hq into dotnet-reusable-driverservice
This reverts commit 164828f.
Co-authored-by: Michael Render <[email protected]>
Reusing shared driver service instance is ~2x faster. Simple test: start 50 chrome browsers simultaneously:
|
|
|
||
if (this.SessionId is not null) | ||
{ | ||
this.Execute(DriverCommand.Quit, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return back try/catch pattern as it was before. Then we can improve later.
I still don't know how to proceed and be user-friendly:
The first point is an ultimate, it would be great to see it in Selenium 5. The second is more friendly, but it adds complexity. |
In exchange for potentially more complexity, we can avoid breaking changes and make behavior more clear by adding a new method on the driver service types called This way, all the disposal magic won’t have to live in the driver disposal, the code could potentially be simpler. We will end up with “single-use driver service” and “reusable driver service”, depending on how it is created. |
It doesn't resolve the initial issue: "who creates those should dispose". |
If we want to fix the lifetime ownership issue without breaking anything, we can solve it with a new method. Existing: var driver = new ChromeDriver();
driver.Dispose(); // Owns its own service, service gets disposed here var driverService = ChromeDriverService.CreateDefaultService();
var driver = new ChromeDriver(driverService);
driver.Dispose(); // backwards-compatible, disposes the service as well Proposed: var driverService = ChromeDriverService.CreatePersistedService();
var driver = new ChromeDriver(driverService); // starts new chromedriver.exe
driver.Dispose(); // does not dispose service
driverService.Dispose(); |
It is a mess. Today |
I think a new overload is justified in the face of a breaking change, we can make a DriverServiceOptions in the future if things should be made more extensible. |
The direction of this PR is very good. Now it works properly (excluding our internal some tests). In my opinion the old behavior is not right. I propose to postpone for v5, where we can announce new "right" behavior. |
User description
DriverService
instance seems to be reusable by Drivers, but in fact no. As soon asQuit
command is handled by Drivers, then underlyingDriverService
is disposed silently.https://github.com/SeleniumHQ/selenium/blame/215e20b139f9af0c2db76b800472daed0633c73c/dotnet/src/webdriver/Remote/DriverServiceCommandExecutor.cs#L128 - this is bad design.
Description
Motivation and Context
Fixes #14624 and #14633
Types of changes
Checklist
PR Type
enhancement
Description
disposeService
parameter across various driver classes to control the disposal of driver services.disposeService
parameter.DriverServiceCommandExecutor
class and replaced its functionality with direct service management.WebDriver
class to ensure proper resource management.Changes walkthrough 📝
9 files
ChromeDriver.cs
Add disposeService parameter to ChromeDriver constructors
dotnet/src/webdriver/Chrome/ChromeDriver.cs
disposeService
parameter to constructors.disposeService
.ChromiumDriver.cs
Enhance ChromiumDriver with service disposal control
dotnet/src/webdriver/Chromium/ChromiumDriver.cs
disposeDriverService
field.EdgeDriver.cs
Update EdgeDriver constructor for service disposal
dotnet/src/webdriver/Edge/EdgeDriver.cs
disposeService
parameter.FirefoxDriver.cs
Update FirefoxDriver to start service in executor
dotnet/src/webdriver/Firefox/FirefoxDriver.cs
InternetExplorerDriver.cs
Modify InternetExplorerDriver to start service in executor
dotnet/src/webdriver/IE/InternetExplorerDriver.cs
DriverServiceCommandExecutor.cs
Remove DriverServiceCommandExecutor class
dotnet/src/webdriver/Remote/DriverServiceCommandExecutor.cs
DriverServiceCommandExecutor
class.SafariDriver.cs
Update SafariDriver to start service in executor
dotnet/src/webdriver/Safari/SafariDriver.cs
WebDriver.cs
Ensure executor disposal in WebDriver class
dotnet/src/webdriver/WebDriver.cs
Dispose
method.DriverFactory.cs
Modify DriverFactory to pass service in driver instantiation
dotnet/test/common/Environment/DriverFactory.cs