Skip to content
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

[🐛 Bug]: Quit () takes a long time when driver instance is created with ChromeDriverService #14633

Open
CarlVerret opened this issue Oct 21, 2024 · 8 comments

Comments

@CarlVerret
Copy link

What happened?

We've been experiencing something quite strange with Quit function of webdriver instanciated with ChromeDirverService since an upgrade to latest version:

let's say we create an instance like this :

    Instance = new ChromeDriver( chromeOptions);
    Instance.Quit()  //  is really quick

But, if we instanciate the driver with this constructor :

    Instance2 = new ChromeDriver(ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory), chromeOptions);
    Instance2.Quit() ; // Quitting takes a lot of time (over 10 seconds)

How can we reproduce the issue?

Instanciate a webdriver like this
 var chromeOptions = new ChromeOptions();

 if (headLess)
   chromeOptions.AddArgument("headless");

  Instance2 = new ChromeDriver(ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory), chromeOptions);

Relevant log output

I've turned on logging as following :

   Log.SetLevel(LogEventLevel.Trace);
   Log.Handlers.Add(new FileLogHandler("C:\\temp\\log_selenium_itself.txt"));
   Log.SetLevel(typeof(ChromeDriverService), LogEventLevel.Trace);
   Log.SetLevel(typeof(SeleniumManager), LogEventLevel.Trace);
   Log.SetLevel(typeof(ChromeDriver), LogEventLevel.Trace);


The only relevant-like info I saw when comparing both constructors : 

With ChromeDriverService it starts with the two following lines :


Instance2 = new ChromeDriver(ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory), chromeOptions);

-----

2024-10-21 13:20:53.549 DEBUG HttpCommandExecutor: Executing command: []: newSession {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["headless","ignore-certificate-errors","start-maximized"]}}]}}
2024-10-21 13:20:53.583 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:52810/session', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:

 Instance = new ChromeDriver( chromeOptions); starts with 4 lines instead
-----------------------------------------------

2024-10-21 13:21:59.163 TRACE SeleniumManager: Driver path: C:\Users\cav001\.cache\selenium\chromedriver\win64\130.0.6723.58\chromedriver.exe
2024-10-21 13:21:59.165 TRACE SeleniumManager: Browser path: C:\Program Files\Google\Chrome\Application\chrome.exe
2024-10-21 13:21:59.338 DEBUG HttpCommandExecutor: Executing command: []: newSession {"capabilities":{"firstMatch":[{"browserName":"chrome","goog:chromeOptions":{"args":["headless","ignore-certificate-errors","start-maximized"],"binary":"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"}}]}}
2024-10-21 13:21:59.360 TRACE HttpCommandExecutor: >> Method: POST, RequestUri: 'http://localhost:52851/session', Version: 1.1, Content: System.Net.Http.ByteArrayContent, Headers:

Operating System

Windows 10 - aspnet core

Selenium version

4.25.0

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

Selenium.WebDriver.ChromeDriver 130.0.6723.5800

Are you using Selenium Grid?

none

Copy link

@CarlVerret, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@CarlVerret CarlVerret changed the title [🐛 Bug]: [🐛 Bug]: Quit () takes a long time when driver instance is created with ChromeDriverService Oct 21, 2024
@nvborisenko
Copy link
Member

@CarlVerret when you use:

Instance = new ChromeDriver( chromeOptions);

Then Selenium Manager is used to automatically manage chromedriver.exe binary for you. Most likely it is downloading recent/latest version (v130 based on logs you provided). And seems it works smoothly.

But when you use:

Instance2 = new ChromeDriver(ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory), chromeOptions);

Then chromedriver.exe is taken from your Environment.CurrentDirectory, which is not managed by Selenium. Somebody else (or you) put this binary, and seems this binary is "outdated" or not "compatible" with existing chrome browser.

@CarlVerret
Copy link
Author

CarlVerret commented Oct 21, 2024

Thanks for your quick feedback.
As performance is a major concern for us, we've put the driver initialization in the Fixture of our test base class. Is there any advantage to take the ChromeDriverService constructor approach ? It feels that for a couple hundreds of tests, it was quicker with the driver service method. (the right binary version was ensured by a nuget package (nupkg-selenium-webdriver-chromedriver)

@nvborisenko
Copy link
Member

  1. When you say about performance, do we have some numbers to compare?
  2. Looks like you use shared instance of ChromeDriverService across tests, which is similar to [🐛 Bug]: C#: Driver process left running if DriverService is reused and Driver disposed #14624

@nvborisenko
Copy link
Member

@CarlVerret I believe this functionality worked for you well, please remind in which Selenium version.

@CarlVerret
Copy link
Author

i'll try to come back with numbers. as far as I remember, it was working with this version :

Maybe a bit after that.

I wonder what's the typical scenario to use ChromeDriverService ctor ?

@nvborisenko
Copy link
Member

You are doing it right in my personal opinion. And Selenium Manager is not bad, it cashes output. Ps: you missed the version In your previous message.

@CarlVerret
Copy link
Author

You are doing it right in my personal opinion. And Selenium Manager is not bad, it cashes output. Ps: you missed the version In your previous message.

that's strange. I was certain to have put xml tags containing nuget versions ...

I'm pretty sure these bundle of version were working fine.

		<PackageReference Include="Selenium.Support" Version="4.21.0" />
		<PackageReference Include="Selenium.WebDriver" Version="4.21.0" />
		<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="125.0.6422.6000" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants