Skip to content

[🐛 Bug]: Dotnet Breaking Change in 4.11.0 #12473

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

Closed
tidusjar opened this issue Aug 2, 2023 · 8 comments
Closed

[🐛 Bug]: Dotnet Breaking Change in 4.11.0 #12473

tidusjar opened this issue Aug 2, 2023 · 8 comments
Assignees
Labels
C-dotnet .NET Bindings I-defect Something is not working as intended
Milestone

Comments

@tidusjar
Copy link

tidusjar commented Aug 2, 2023

What happened?

When using the following code to create a ChromeDriver, it throws the following exception in 4.11.0

How can we reproduce the issue?

var pathToDriver = GetDriverPath(typeof(ChromeDriver));
return new ChromeDriver(pathToDriver, options);

pathToDriver is the full path to the driver instance e.g. C:\something\chrome\driver.exe

This change is related to #12344

Relevant log output

System.ComponentModel.Win32Exception : The FileName property should not be a directory unless UseShellExecute is set.
TearDown : BoDi.ObjectContainerException : Interface cannot be resolved: OpenQA.Selenium.IWebDriver
StackTrace:    at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at OpenQA.Selenium.DriverService.Start()
   at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
   at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)

Operating System

Linux

Selenium version

4.11.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?

ChromeDriver 114.0.5735.90

Are you using Selenium Grid?

N/A

@tidusjar tidusjar added I-defect Something is not working as intended A-needs-triaging A Selenium member will evaluate this soon! labels Aug 2, 2023
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

@tidusjar, 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!

@titusfortner
Copy link
Member

Ok, this is a fun one.
In Selenium 4.10, the driver constructor that takes a single string argument is supposed to be a directory not the full path. So, it needs to be C:\something\chrome\ not C:\something\chrome\driver.exe. https://github.com/SeleniumHQ/selenium/blob/selenium-4.10.0/dotnet/src/webdriver/Chrome/ChromeDriver.cs#L103

If the latter was passed in, .NET would actually look for C:\something\chrome\driver.exe\chromedriver.exe, and if it didn't find it, it would ignore it and use what it could find on the system.

4.11 does not ignore it any longer, but respects what a user passes in (as it should).

But since I know people sometimes pass in the full path, I added code to fix it — https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/Chrome/ChromeDriverService.cs#L72

But it looks like I was assuming that the driver would be named "chromedriver.exe".
Regardless I didn't test this well enough.

But the feature you thought was working before was not actually working the way you thought, which is why it was bad and needed to be changed..

@titusfortner titusfortner added C-dotnet .NET Bindings and removed A-needs-triaging A Selenium member will evaluate this soon! labels Aug 2, 2023
@titusfortner titusfortner added this to the 4.12 milestone Aug 2, 2023
@tidusjar
Copy link
Author

tidusjar commented Aug 2, 2023

Thanks for the explanation behind that.

Another potential fix instead of just 'making it work', could be if it's a full path, throw an exception so the developer knows exactly what is wrong and how to fix it?

@titusfortner
Copy link
Member

Yes, I went this route to make it more closely match all the other bindings.

Looking through the code I don't see where we make use of it being two arguments in general since we just end up combining them when they actually get used. If I had more time/energy, I'd deprecate the constructor for setting 2 parameters and require the single string to always be full path because that is what people seem to most expect.

@titusfortner titusfortner self-assigned this Aug 2, 2023
@timandella
Copy link

I think the original description for this issue was a bit misleading, as the example for "pathToDriver" is not accurate. In this instance, path to driver is "c:<somefolders>\chromedriver" so the command being executed is this

return new ChromeDriver("c:\<somefolders>\chromedriver", options);

The chrome driver exe itself is still named "chromedriver.exe"

I think it is the fact that the containing folder is also named "chromedriver" that is causing issues, Looking at the fix at https://github.com/SeleniumHQ/selenium/blob/trunk/dotnet/src/webdriver/Chrome/ChromeDriverService.cs#L72, it looks like it is checking the folder path contains "chromedriver" and assuming it is the full exe path, and adjusting the folder path accordingly. (so the driver path becomes "c:<somefolders>")

If we pass in the full exe path "c:<somefolders>\chromedriver\chromedriver.exe" then it works as expected, but I would really expect it to work if just the folder path is passed in, even if the folder is named "chromedriver" too

@titusfortner
Copy link
Member

Ah, yes, it's matching anything with the driver name in it.

To be honest the best fix for all of this is to delete the driver and let Selenium manage it for you now. But thanks for the clarification, that's definitely the wrong conditional.

@titusfortner
Copy link
Member

titusfortner commented Aug 3, 2023

No, that's not true...

If my driver is here: "/Users/titusfortner/chromedriver/chromedriver"

This works:

ChromeDriverService.CreateDefaultService("/Users/titusfortner/chromedriver/chromedriver");

and this works:

ChromeDriverService.CreateDefaultService("/Users/titusfortner/chromedriver/");

This does not work, because it is not getting parsed as a directory, but as a file:

ChromeDriverService.CreateDefaultService("/Users/titusfortner/chromedriver");

I've updated the conditional to just check if it is a file. If it's a file, Selenium will just use the directory, if it isn't a file, Selenium will use what was passed in.

Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-dotnet .NET Bindings I-defect Something is not working as intended
Projects
None yet
Development

No branches or pull requests

3 participants