ORN*_*RNS 3 selenium webdriver
我需要将 Selenium Webdriver 的实例连接/创建到我的测试应用程序在 Winform 中打开的 Web 内容。
我的测试框架使用 CodedUI 打开 Winform 应用程序,进一步的测试步骤会导致 Winform 应用程序打开另一个嵌入了浏览器的 Winform 窗口。我需要创建一个 Selenium 实例或将其绑定到此嵌入式浏览器内容。它在嵌入区域使用 WebViewer/Edge。
注意 - 尚未准备好迁移到 WinAppDriver(如果有的话)。
解决了这个问题。我发现 Web 窗格是一个名为 WebView2 的对象。
其内部的自动化需要以特殊方式启动应用程序:
Dim AppPath As String = "[full path to your app and its name].exe"
Dim edgeOptions As New EdgeOptions
edgeOptions.UseChromium = True
edgeOptions.UseWebView = True
edgeOptions.DebuggerAddress = "localhost:9222"
Dim AppStartInfo = New ProcessStartInfo(AppPath)
AppStartInfo.UseShellExecute = False
AppStartInfo.EnvironmentVariables("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS") = "--remote-debugging-port=9222"
Diagnostics.Process.Start(AppStartInfo)
Run Code Online (Sandbox Code Playgroud)
您还需要:
最后,在您的自动化代码中,当其中包含 WebView2 的窗口最终出现时,您需要运行以下代码将 selenium webdriver 绑定到 WebView2 窗格:
Dim driver As String = "[path to:]msedgedriver.exe"
Dim edgeOptions As New EdgeOptions
edgeOptions.UseChromium = True
edgeOptions.UseWebView = True
edgeOptions.DebuggerAddress = "localhost:9222"
Dim WebDriver = New EdgeDriver(EdgeDriverService.CreateDefaultService(".", driver), edgeOptions)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1767 次 |
| 最近记录: |