- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.6k
 
          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 herevar driverService = ChromeDriverService.CreateDefaultService();
var driver = new ChromeDriver(driverService);
driver.Dispose(); // backwards-compatible, disposes the service as wellProposed: 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.  | 
    
| 
           Good decision is: new FirefoxDriver(); // it always starts new service and dispose it, current behavior;
new FirefoxDriver(service); // it takes existing service and dispose it, current behavior;
new FirefoxDriver(service, bool disposeService); // introduce new flag whether existing service should be disposedImplementation notes: it should not be optional! Only new method overload. Also don't refactor unit tests, keep existing behavior. The key changes are identified, let's fix this bad design and forget. This approach is not a breaking change.  | 
    
User description
DriverServiceinstance seems to be reusable by Drivers, but in fact no. As soon asQuitcommand is handled by Drivers, then underlyingDriverServiceis 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
disposeServiceparameter across various driver classes to control the disposal of driver services.disposeServiceparameter.DriverServiceCommandExecutorclass and replaced its functionality with direct service management.WebDriverclass to ensure proper resource management.Changes walkthrough 📝
9 files
ChromeDriver.cs
Add disposeService parameter to ChromeDriver constructorsdotnet/src/webdriver/Chrome/ChromeDriver.cs
disposeServiceparameter to constructors.disposeService.ChromiumDriver.cs
Enhance ChromiumDriver with service disposal controldotnet/src/webdriver/Chromium/ChromiumDriver.cs
disposeDriverServicefield.EdgeDriver.cs
Update EdgeDriver constructor for service disposaldotnet/src/webdriver/Edge/EdgeDriver.cs
disposeServiceparameter.FirefoxDriver.cs
Update FirefoxDriver to start service in executordotnet/src/webdriver/Firefox/FirefoxDriver.cs
InternetExplorerDriver.cs
Modify InternetExplorerDriver to start service in executordotnet/src/webdriver/IE/InternetExplorerDriver.cs
DriverServiceCommandExecutor.cs
Remove DriverServiceCommandExecutor classdotnet/src/webdriver/Remote/DriverServiceCommandExecutor.cs
DriverServiceCommandExecutorclass.SafariDriver.cs
Update SafariDriver to start service in executordotnet/src/webdriver/Safari/SafariDriver.cs
WebDriver.cs
Ensure executor disposal in WebDriver classdotnet/src/webdriver/WebDriver.cs
Disposemethod.DriverFactory.cs
Modify DriverFactory to pass service in driver instantiationdotnet/test/common/Environment/DriverFactory.cs