Skip to content

[🐛 Bug]: EdgeDriver downloaded in wrong version when using WebView2 #12958

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
ssrmm opened this issue Oct 16, 2023 · 14 comments
Closed

[🐛 Bug]: EdgeDriver downloaded in wrong version when using WebView2 #12958

ssrmm opened this issue Oct 16, 2023 · 14 comments
Labels
I-defect Something is not working as intended J-awaiting answer Question asked of user; a reply moves it to triage again

Comments

@ssrmm
Copy link

ssrmm commented Oct 16, 2023

What happened?

When Selenium Manager determines the version of the EdgeDriver to download for use with the WebView2 runtime, it looks for the version of the installed Edge Browser. This however is not correct when the versions of Edge and the WebView2 runtime differ. Instead the the version of the WebView runtime should be detected and used to determine the driver-version to download.

On the machine in question the following version of Edge and the WebView2 runtime are currently installed:
image

In this scenario the following code does not work:

var options = new EdgeOptions { DebuggerAddress = "localhost:12345", UseWebView = true };
using var driver = new EdgeDriver(options);

It produces this error:

Starting Microsoft Edge WebDriver 113.0.1774.57 (b3b212deff59d422d4ce9487f276cb0e0d352835) on port 61505
To submit feedback, report a bug, or suggest new features, please visit https://github.com/MicrosoftEdge/EdgeWebDriver

Only local connections are allowed.
Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.

Microsoft Edge WebDriver was started successfully.
Unhandled exception. OpenQA.Selenium.WebDriverException: unknown error: cannot connect to microsoft edge at localhost:12345
from session not created: This version of Microsoft Edge WebDriver only supports Microsoft Edge version 113
Current browser version is 118.0.2088.46
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String 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.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeDriverService service, EdgeOptions options)
   at OpenQA.Selenium.Edge.EdgeDriver..ctor(EdgeOptions options)
   at Program.<Main>$(String[] args)

As a workaround you currently need to specify at least the major Version explicitly (note the BrowserVersion property at the end):

var options = new EdgeOptions { DebuggerAddress = "localhost:12345", UseWebView = true, BrowserVersion = "118" };
using var driver = new EdgeDriver(options);

Invoking Selenium Manager directly yields the following output:

$ selenium-manager.exe --browser webview2 --debug
DEBUG   msedgedriver not found in PATH
DEBUG   webview2 detected at C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
DEBUG   Running command: wmic datafile where name='C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe' get Version /value
DEBUG   Output: "\r\r\n\r\r\nVersion=113.0.1774.35\r\r\n\r\r\n\r\r\n\r"
DEBUG   Detected browser: webview2 113.0.1774.35
DEBUG   Required driver: msedgedriver 113.0.1774.57
DEBUG   msedgedriver 113.0.1774.57 already in the cache
INFO    Driver path: C:\Users\username\.cache\selenium\msedgedriver\win64\113.0.1774.57\msedgedriver.exe

When specifying the version explicitly, this changes to:

$ selenium-manager.exe --browser webview2 --debug --browser-version 118
DEBUG   msedgedriver not found in PATH
DEBUG   webview2 detected at C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
DEBUG   Running command: wmic datafile where name='C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe' get Version /value
DEBUG   Output: "\r\r\n\r\r\nVersion=113.0.1774.35\r\r\n\r\r\n\r\r\n\r"
DEBUG   Detected browser: webview2 113.0.1774.35
DEBUG   Discovered webview2 version (113) different to specified browser version (118)
DEBUG   Required driver: msedgedriver 118.0.2088.46
DEBUG   msedgedriver 118.0.2088.46 already in the cache
INFO    Driver path: C:\Users\username\.cache\selenium\msedgedriver\win64\118.0.2088.46\msedgedriver.exe

At least on Windows Microsoft recommends to read the version of the installed WebView2 runtime from the registry. The registry value pv exists under one of the following keys and will contain the version information:

  • HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5} (system-wide installation)
  • HKEY_CURRENT_USER\Software\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5} (per-user installation)

I don't know what the right approach on other operating systems would be.

How can we reproduce the issue?

See above

Relevant log output

See above

Operating System

Windows 10, Windows 11

Selenium version

.NET 4.14.1

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

Edge WebView2 118

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

EdgeDriver 118

Are you using Selenium Grid?

No

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

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

@diemol
Copy link
Member

diemol commented Oct 16, 2023

I would say WebView2 is a use case apart. I recommend you download the correct browser driver that matches your app binary. I do not think Selenium Manager needs to handle this.

What do you think @titusfortner @bonigarcia?

@diemol diemol added J-awaiting answer Question asked of user; a reply moves it to triage again and removed A-needs-triaging A Selenium member will evaluate this soon! labels Oct 16, 2023
@titusfortner
Copy link
Member

What happens if you specify the binary location in the options class? Selenium Manager now does not fail on the name, should get the version at the specified location (I think) and then download the driver you need.

@bonigarcia
Copy link
Member

I've been looking into the support for WebView2. Indeed, it seems the implementation of #12904, as requested in #12738, is incorrect.

The best way to support WebView2 would be to introduce a separate module from Edge, in which the browser name is webview2, and the mechanism for detecting the browser version is based on a registry query, as @ssrmm (source) suggested. That mechanism only works in Windows since WebView2 is only supported in Windows. There are plans to support macOS as well, but it is yet to be available.

The effort to support everything in Selenium Manager is low, so I am up to implementing this for the next release.

@ssrmm
Copy link
Author

ssrmm commented Oct 17, 2023

I recommend you download the correct browser driver that matches your app binary. I do not think Selenium Manager needs to handle this.

I agree that it makes sense that you need to specify the binary location yourself if you have the WebView2 binaries bundled together with your application (aka Fixed Version runtime distribution mode). However in this scenario WebView2 is installed in a well-known location on the system where it lives independent of the application under test (aka. Evergreen Runtime distribution mode). There I think it would make sense to centralize the logic of determining the version of WebView2 in a place like Selenium Manager.

As a matter of fact we use exactly this information from the registry to determine the BrowserVerion that we pass to the EdgeOptions because we want to avoid having to change the version number with every Edge release. And anyone else that runs into this case would likely too.

What happens if you specify the binary location in the options class?

You mean like this?

var options = new EdgeOptions
{
    DebuggerAddress = "localhost:12345",
    UseWebView = true,
    BinaryLocation = @"C:\Program Files (x86)\Microsoft\EdgeWebView\Application\118.0.2088.46\msedgewebview2.exe"
};
using var driver = new EdgeDriver(options);

This produces the same error as before,

Under the hood Selenium Manager seems to ignore the argument in this scenario:

selenium-manager.exe --browser webview2 --browser-path "C:\Program Files (x86)\Microsoft\EdgeWebView\Application\118.0.2088.46\msedgewebview2.exe" --debug
DEBUG   msedgedriver not found in PATH
DEBUG   webview2 detected at C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
DEBUG   Running command: wmic datafile where name='C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe' get Version /value
DEBUG   Output: "\r\r\n\r\r\nVersion=113.0.1774.35\r\r\n\r\r\n\r\r\n\r"
DEBUG   Detected browser: webview2 113.0.1774.35
DEBUG   Required driver: msedgedriver 113.0.1774.57
DEBUG   msedgedriver 113.0.1774.57 already in the cache
INFO    Driver path: C:\Users\username\.cache\selenium\msedgedriver\win64\113.0.1774.57\msedgedriver.exe

Though this wouldn't really help, even if it did work: Getting the path to the executable is equivalent to getting the version because the path depends on the version and both need to be read from the registry.

@titusfortner
Copy link
Member

Under the hood Selenium Manager seems to ignore the argument in this scenario:

But it's getting the right driver version... The change I just made will prevent the bindings from overwriting the browser path with an empty string in the options getting sent to the driver. I *think the next version should be good enough without Boni needing to do more work here.

@ssrmm
Copy link
Author

ssrmm commented Oct 17, 2023

But it's getting the right driver version...

It's getting 113.x even though it should get 118.x

@ssrmm
Copy link
Author

ssrmm commented Oct 17, 2023

This produces the same error as before,

Just realized that this sentence may have been ambiguous. I was referring to the stacktrace from the initial message in this issue, i.e.

This version of Microsoft Edge WebDriver only supports Microsoft Edge version 113
Current browser version is 118.0.2088.46

@titusfortner
Copy link
Member

titusfortner commented Oct 17, 2023

Right, right I wasn't looking closely enough. Your edge is 113, and your webview is 118.
So we want SM to evaluate the version of the binary provided, download the right edge driver, and then return the "browser location" as the location of the webview app.

@ssrmm
Copy link
Author

ssrmm commented Oct 17, 2023

Right, right I wasn't looking closely enough. Your edge is 113, and your webview is 118.

Since this is an actual case where the version numbers are coincidence, the laws of physics obviously require that the two numbers must be ones that are the hardest to distinguish 😆

So we want SM to evaluate the version of the binary provided, download the right edge driver, and then return the "browser location" as the location of the webview app.

I guess that would work nicely for people that use the above mentioned Fixed Version runtime distribution mode where the WebView2 binaries are just somewhere next to the application. They presumably know that location anyway because it is either in a fixed location period or at the very least in a fixed location relative to the application under test.

With this hypothetical change, if WebView2 is installed system-wide in Evergreen Runtime distribution mode one would still need to get the binary location from the registry somewhere in the test setup code. Which is equivalent to the current situation where one needs to get the version from the registry. That or hardcoding the version, either by hardcoding it directly or by hardcoding it as part of the binary location. The convenience win for the Evergreen Runtime case would be that Selenium finds the installed WebView2 without having to specify neither path nor version (both of which change).

image

@bonigarcia
Copy link
Member

I created a PR to fix the support for WebView2 in Selenium Manager.

@ssrmm Can you please have a try? Please download and extract the new Selenium Manager binary (from here: selenium-manager_windows-x32) and run the following command with it:

selenium-manager.exe --browser webview2 --debug

@ssrmm
Copy link
Author

ssrmm commented Oct 18, 2023

Looks like this is working:

$ selenium-manager.exe --browser webview2 --debug
DEBUG   msedgedriver not found in PATH
DEBUG   webview2 detected at C:\Program Files (x86)\Microsoft\EdgeWebView\Application
DEBUG   Running command: REG QUERY HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5} /v pv
DEBUG   Output: "\r\nHKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}\r\n    pv    REG_SZ    118.0.2088.46\r\n"
DEBUG   Detected browser: webview2 118.0.2088.46
DEBUG   Reading msedgedriver version from https://msedgedriver.azureedge.net/LATEST_RELEASE_118_WINDOWS
DEBUG   Required driver: msedgedriver 118.0.2088.46
DEBUG   msedgedriver 118.0.2088.46 already in the cache
INFO    Driver path: C:\Users\username\.cache\selenium\msedgedriver\win64\118.0.2088.46\msedgedriver.exe
INFO    Browser path: C:\Program Files (x86)\Microsoft\EdgeWebView\Application\118.0.2088.46\msedge.exe

I've also replaced the Selenium Manager binary in the build-folder of the the test code. With the replaced binary the tests now run without having to specify anything with an otherwise 4.14.1 Selenium NuGet package 👍

@ssrmm
Copy link
Author

ssrmm commented Nov 20, 2023

I guess this can be closed. At this point we have even upgraded to the latest release that contains these changes and that is working as well.

Thanks!

@ssrmm ssrmm closed this as completed Nov 20, 2023
Copy link

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 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I-defect Something is not working as intended J-awaiting answer Question asked of user; a reply moves it to triage again
Projects
None yet
Development

No branches or pull requests

4 participants