WebView2 is a Chromium-based control that allows desktop applications to display web content. TestComplete connects to the WebView2 runtime to automate testing of desktop applications by using the Chrome DevTools Protocol (CDP). After you enable this connection, you can explore the WebView2 DOM, identify page elements, and run reliable tests in the embedded browser.
Adding a WebView2 Application to the Tested Apps List
Adding a WebView2 Application to the Tested Apps List
Perform the following steps to add a WebView2 application to the Tested Apps list:
-
Open your project in TestComplete.
-
In Project Explorer, right-click Tested Apps, and select Add Application.
-
Go to the application file.
-
On the Run Mode page, enter the required command-line parameters:
--edge-webview-switches=--remote-debugging-port=9222
TestComplete applies these parameters each time you launch the tested application from the Tested Apps list.
Configuring CDP Ports for WebView2 Applications
Why You Need a Debugging Port
You can enable TestComplete to interact with the embedded Microsoft Edge (Chromium) engine by configuring a debugging port for WebView2. Configuring this port lets TestComplete access and automate WebView2 web content by using the Chrome DevTools Protocol (CDP).
Setting the Debugging Port for WebView2
You can set the debugging port in multiple ways. Use one of the following methods to enable TestComplete to connect to the WebView2 runtime.
1. Use the Official WebView2 Command-Line Parameter (Recommended)
Add the following parameter when starting your application:
--edge-webview-switches=--remote-debugging-port=9222
How WebView2 Works with TestComplete
-
Opens a local debugging port (default:
localhost:9222) in the WebView2 runtime. -
Allows TestComplete to communicate with the embedded browser by using the Chrome DevTools Protocol.
-
Enables DOM inspection, object recognition, and interaction with web elements inside the WebView2 control.
Prefix of --edge-webview-switches=
-
WebView2 accepts Chromium flags only if you use the
--edge-webview-switches=prefix. -
Passing
--remote-debugging-portby itself does not work. -
Microsoft documents this as the supported method for passing debugging flags to WebView2.
Security Considerations
-
The debugging port operates only on the local machine.
-
No external network traffic occurs unless another local process connects.
-
The parameter is part of Microsoft’s supported WebView2 configuration.
-
TestComplete uses the port only when executing tests.
2. Allow TestComplete to Choose the Port
Use the following parameter:
--webview2-cdp-port=auto
-
TestComplete finds and applies an available port.
-
You do not need to configure the port manually.
3. Specify a Single Port
To set a specific port, use:
--webview2-cdp-port=9222
-
TestComplete forwards the port to the WebView2 application and uses the correct internal format.
4. Specify Multiple Ports
To set multiple ports, use:
--webview2-cdp-port=9229,9225
-
TestComplete checks the specified ports for communication.
-
WebView2 does not open multiple ports. If you require multiple ports, configure your application to open each port.
Verifying the WebView2 Connection
After you launch the application from Tested Apps, verify the connection by performing the following steps:
-
Open Object Browser.
-
Expand the node for your WebView2 tested application.
-
Look for a Page object with a Chrome-style icon.
If a Page object appears, TestComplete has successfully connected to the WebView2 runtime.
Disabling Hardware Stack Protection
If your WebView2 application does not start when launched from TestedApps, you might need to disable hardware-enforced stack protection in Windows Exploit settings.
Disabling Exploit Protection for a Specific Application
Perform the following steps to disable exploit protection features for a specific application
(for example, webview2app.exe):
-
Go to Windows Security from the Start menu on the taskbar.
-
Select App & browser control.
-
In the Exploit protection section, select Exploit protection settings.
-
Click the Program settings tab.
-
Locate
webview2app.exe. Ifwebview2app.exeis not listed, select Add program to customize > Add by program name, enterwebview2app.exe, and click Add. -
Configure the following program-specific settings:
-
In the Hardware-enforced Stack Protection section, select Override system settings checkbox, and set the option to Off.
-
If the issue persists after disabling hardware stack protection:
-
In Randomize memory allocations (Bottom-up ASLR), select the Override system settings checkbox, and set the option to Off.
-
-
-
Apply the changes and relaunch the application from TestComplete.
| Note: | You need to make these configuration changes only the first time you launch webview2app.exe. After the initial launch with TestComplete, Windows security settings allow the application to run without further changes. |
