This topic describes the prerequisites for enabling TestComplete to access and work with the web content rendered inside WebView2 controls.
To allow TestComplete to connect to the embedded WebView2 engine, the WebView2 tested application must be added to the TestedApps list and started with command-line parameters that open a Chrome DevTools Protocol (CDP) communication port. TestComplete uses this port to inspect and interact with the WebView2-based content.
Adding the Application to TestedApps
Add the WebView2 tested application to the TestedApps list in TestComplete. This process is similar to configuring CEF or Electron applications. Once added, specify the necessary command-line parameters to open a CDP port.
Configuring CDP Ports
The WebView2 tested application must open a CDP port for TestComplete to connect. You can configure this by using any of the supported parameters listed below.
Using the Official WebView2 Parameter
You can pass the official WebView2 debugging parameter directly:
--edge-webview-switches=--remote-debugging-port=<some_number>
This opens the specified CDP port, and TestComplete uses it for communication.
Automatic Port Selection
TestComplete can automatically select an available port:
--webview2-cdp-port=auto
TestComplete finds a free port, converts the parameter internally to the WebView2-compatible format, and passes it to the WebView2 tested application to open the port.
Specifying a Single Port
You can specify a specific CDP port manually:
--webview2-cdp-port=<some_number>
Example:
--webview2-cdp-port=9222
TestComplete forwards this port value to the WebView2 tested application and modifies the parameter name internally as required.
Specifying Multiple Ports
You can specify multiple comma-separated port numbers:
--webview2-cdp-port=<multiple_numbers>
Example:
--webview2-cdp-port=9229,9225
TestComplete checks the ports listed in this parameter. The WebView2 tested application must open and validate these ports.
Notes on Multi-Port Support
TestComplete supports multi-port communication. However, WebView2 does not provide an official way to open multiple CDP ports through command-line parameters. When multiple ports are required, the WebView2 tested application must open them itself. The parameter only instructs TestComplete to check the listed ports.
Verifying WebView2 Support
After starting the WebView2 tested application from the TestedApps list, open the Object Browser and expand the application node.
If WebView2 support is active, a Page object with a Chrome-style icon appears under the application. This indicates a successful CDP connection.
(Reference image: webview2-2.png)
Disabling Hardware Stack Protection
In some cases, similar to behavior observed with cefclient, the WebView2 tested application may fail to start when launched from TestComplete. Disabling hardware-enforced stack protection may resolve this issue.
To disable hardware-enforced stack protection:
- Open Windows Security.
- Select App & browser control.
- Under Exploit protection, select Exploit protection settings.
- Open the Program settings tab.
- Locate the WebView2 tested application. If it is not listed, select Add program to customize or Add by program name and enter the executable name.
- Edit the program settings.
- Select Override system settings in the Hardware-enforced Stack Protection section.
- Set the protection option to Off.
- Apply the changes.
