Can't get WebView2 Automation testing working.

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
matthew.butler
Posts: 4
Joined: Wed Sep 15, 2021 11:37 am

Can't get WebView2 Automation testing working.

Post by matthew.butler » Thu Mar 31, 2022 4:33 pm

Hi,

The AUT I work on has recently migrated from CEFSharp to Microsoft Edge WebView2 to display some web content launched by the main application. I've been trying to get Ranorex to pick up elements in the browser as it used to when using CEFSharp, but I can't seem to get it instrumented correctly. I've tried launching the main .exe with remote debugging set to 8081 and I've tried making modifications to the applications code to get it working but none have worked yet.

Edit: Managed to connect to the hosted webpage with "localhost:8081" and I can see the port open when looking at netstat on the cmd prompt so looks like the porting is working fine. So now just looks like it's just ranorex not being able to identify the elements

I'd greatly appreciate any help from anyone,
Kind Regards,
Matt

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Can't get WebView2 Automation testing working.

Post by odklizec » Thu Mar 31, 2022 7:49 pm

Hi,

As far as I know, WebView2 is not yet supported by Ranorex. There is a ticket for this, but there are no details as of when it will be supported.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

albertog
Posts: 15
Joined: Fri Mar 19, 2021 12:33 pm

Re: Can't get WebView2 Automation testing working.

Post by albertog » Wed Jul 13, 2022 4:16 pm

Hello everyone,

We get the very same issue here. Hope it will get fixed soon, or at least a workaround shall be provided....

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: Can't get WebView2 Automation testing working.

Post by doke » Tue Jul 19, 2022 7:57 am

Hi all,
As we are possibly moving to webview2 I am also investigating.

According to Microsoft ther is a way to instrument webview2 using edge webdriver (for use with selenium) :
https://docs.microsoft.com/en-us/micros ... /webdriver

Is ranorex able to use the edge webdriver ?

Regards,
Don

matthew.butler
Posts: 4
Joined: Wed Sep 15, 2021 11:37 am

Re: Can't get WebView2 Automation testing working.

Post by matthew.butler » Thu Oct 13, 2022 9:26 am

Hi All,

Figured I'd post an update to this now to help others trying to solve this problem. Having recently seen dokes post I now have automation working with WebView2. I did this using Selenium and an Edge WebDriver. Specifically using the packages Selenium WebDriver 4.5.0 and Selenium.WebDriver.EdgeChromiumDriver 99.0.1153. The latter of these I installed in Visual Studio as Ranorex wasn't letting me add a past version of a package and I had to get the version of the EdgeChromiumDriver that was specific to the version of Webview2 in use in our AUT. We are still using the 8081 port that Ranorex uses in case they add the functionality to Ranorex in the future. I also had to disable the Unused Ranorex.Plugin.WebDriver by changing its alias to stop reference conflicts with the "By" used to get elements.

This is the code used in Ranorex to attach to the WebView2 launched by the main application.

Code: Select all

//These Additional Imports
using OpenQA.Selenium.Edge;
using OpenQA.Selenium;

//This code in the .Run() method
EdgeOptions eo = new EdgeOptions();
eo.UseWebView = true;
eo.DebuggerAddress = "localhost:8081";
EdgeDriver e = new EdgeDriver(eo);

//Interacting like this, using inspect on the webpage to get the full XPath
var submitBtn = e.FindElement(By.XPath("/html/body/div[1]/div/main/div[1]/div/div[1]/div/div[4]/div[3]/div/button"));
submitBtn.Click();

I also had to disable the Unused Ranorex.Plugin.WebDriver by changing its alias to stop reference conflicts with the "By" used to get elements. There may have been an easier way of getting it working but for now it's working perfectly fine.

Hope others find this helpful if you need to get WebView2 Automation working :D

dhale
Posts: 84
Joined: Thu Feb 27, 2014 7:33 pm

Re: Can't get WebView2 Automation testing working.

Post by dhale » Tue Dec 13, 2022 4:18 pm

I'm still working with Support but to date the only way I've been able to get Spy to find and work with a WebView2 control is if the webview2 control is not extended (aka cant do this: public class ExtendedWebView : WebView2), and not implemented inside of a custom UserControl -
and you need to do something like this to get the remote debug port enabled

Code: Select all

CoreWebView2Environment environment = null;
                // Ranorex needs access to the remote debug port
                string remoteDebugPort = "8081";
                CoreWebView2EnvironmentOptions environmentOptions = new CoreWebView2EnvironmentOptions(additionalBrowserArguments: $"--remote-debugging-port={remoteDebugPort}");
                environment = await CoreWebView2Environment.CreateAsync(options: environmentOptions);
                await EnsureCoreWebView2Async(environment);