我正在尝试使用 Winium 自动化 Windows 应用程序 GUI.该应用同时使用 WPF 窗口和Chrome Legacy Window"(Chromium) 窗口.
我正在使用工具 "Automation Spy" 在 WPF 窗口中检查 GUI 元素的 ID 以与 Winium 一起使用.Automation Spy 无法检查Chrome Legacy Window"窗口中的元素,就像 Winium 无法访问这些元素一样.
Chrome Legacy Window"是一个 WEB 窗口,因此需要使用 Selenium 进行自动化.
我如何使用 Selenium 来挂钩 Chromium 窗口,它不是像 Firefox、Chrome 和类似浏览器的浏览器?
我将remote-debugging-port=XXXX"添加到我的 CEF(Chromium 嵌入式框架)命令中:https://blog.chromium.org/2011/05/remote-debugging-with-chrome-developer.html这让我可以通过 localhost:XXXX 查看和管理我的应用程序的 CEF 窗口.
我同时使用了 Winium 和 Selenium 来测试我的应用程序.Winium 用于我所有的 WPF 窗口,而 selenium 用于我的所有 CEF 窗口.我的 GUI 测试从 Winium 驱动程序开始,以打开我的应用程序并导航 WPF 窗口.每次我需要调试 CEF 窗口时,我都会使用 selenium 和remote-debugging-port"参数打开一个 Chrome 驱动程序,它允许我单击该窗口内的元素.当我完成这个 chromium 窗口时,我将关闭 selenium 驱动程序并继续使用 Winium.
Selenium 是一个可移植的框架,用于测试和自动化 Web 应用程序.Winium 是一个基于 Selenium 的工具,用于在 Windows 上测试和自动化桌面应用程序.要在 IntelliJ IDEA 项目中使用这些模块,请按照以下步骤操作:
现在所有的 Selenium 和 Winium 导入都应该可以工作了.例如:
import org.openqa.selenium.By;导入 org.openqa.selenium.WebDriver;导入 org.openqa.selenium.chrome.ChromeDriver;导入 org.openqa.selenium.chrome.ChromeOptions;导入 org.openqa.selenium.support.ui.ExpectedConditions;导入 org.openqa.selenium.support.ui.WebDriverWait;导入 org.openqa.selenium.winium.DesktopOptions;导入 org.openqa.selenium.winium.WiniumDriver;导入 org.openqa.selenium.winium.WiniumDriverService;
按照以下步骤操作:
<块引用>
c: empcef_binary_3.2171.1979_windows32_client发布cefclient.exe(和其他文件)chromedriver.exeExample.javaselenium-server-standalone-2.44.0.jar
有关更多信息,您可以阅读此 wiki:https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md
按照以下步骤操作:
启动一个winium驱动并打开你的应用:
DesktopOptions desktopOption = new DesktopOptions();desktopOption.setApplicationPath("Path_to_your_app.exe");文件 drivePath = new File("C:\temp\Winium.Desktop.Driver.exe");WiniumDriverService 服务 = 新 WiniumDriverService.Builder().usingDriverExecutable(drivePath).usingPort(9999).withVerbose(true).withSilent(false).buildDesktopService();服务.start();WiniumDriver winiumDriver = WiniumDriver(service, desktopOption);
使用 winium 导航和测试 WPF 窗口.例如:
winiumDriver.findElement(By.id("someElementID")).click();
创建一个 ChromeOptions 对象,该对象包含所有需要的 selenium 信息,例如 chromium 客户端和远程调试端口.确保将XXXX"端口更改为您的远程调试端口.
System.setProperty("webdriver.chrome.driver", "c:/temp/chromedriver.exe");ChromeOptions chromeOptions = new ChromeOptions();chromeOptions.setBinary("c:/temp/cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_windows64_client/Release/cefclient.exe");chromeOptions.addArguments("远程调试端口=XXXX");
使用 chrome 选项对象打开一个 chrome 驱动程序 (selenium).
WebDriver seleniumDriver = ChromeDriver(chromeOptions);
在铬窗口内使用元素.例如:
seleniumWait.until(ExpectedConditions.visibilityOfElementLocated(By.className("someButtonClassName")));seleniumDriver.findElement(By.className("someButtonClassName")).click();
完成 CEF 窗口后,关闭 selenium 驱动程序并继续使用 winium 驱动程序:
seleniumDriver.quit();winiumDriver.findElement(By.id("someElementID")).click();
关闭主winium驱动:
winiumDriver.quit();
I'm trying to automate a Windows application GUI using Winium. The app is using both WPF windows and "Chrome Legacy Window" (Chromium) windows.
I'm using the tool "Automation Spy" to inspect the GUI elements' ids inside the WPF windows to use with Winium. Automation Spy can't inspect elements in the "Chrome Legacy Window" windows in the same manner that Winium can't access these elements.
"Chrome Legacy Window" is a WEB window, so it requires automation with Selenium.
How do I use Selenium to hook on a Chromium window, which is not a browser like Firefox, Chrome and similar?
I added the "remote-debugging-port=XXXX" to my CEF (Chromium Embedded Framework) command: https://blog.chromium.org/2011/05/remote-debugging-with-chrome-developer.html This allowed me to see and manage my app's CEF windows through localhost:XXXX.
I used both Winium and Selenium to test my app. Winium for all my WPF windows and selenium for all my CEF windows. My GUI test starts with Winium Driver to open my app and navigate WPF windows. Each time I need to debug a CEF window, I'm opening a Chrome Driver using selenium with the "remote-debugging-port" argument, which allows me to click elements inside that window. When I'm finish with this chromium window I'm closing the selenium driver and continues with Winium.
Selenium is a portable framework for testing and automating web applications. Winium is a Selenium-based tool for testing and automating desktop applications on Windows. In order to use these modules inside IntelliJ IDEA project, follow these steps:
Now all Selenium and Winium imports should work. For example:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.openqa.selenium.winium.WiniumDriverService;
Follow these steps:
c: emp cef_binary_3.2171.1979_windows32_client Release cefclient.exe (and other files) chromedriver.exe Example.java selenium-server-standalone-2.44.0.jar
For more information you can read this wiki: https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md
Follow these steps:
Start a winium driver and open your app:
DesktopOptions desktopOption = new DesktopOptions();
desktopOption.setApplicationPath("Path_to_your_app.exe");
File drivePath = new File("C:\temp\Winium.Desktop.Driver.exe");
WiniumDriverService service = new WiniumDriverService.Builder().usingDriverExecutable(drivePath).usingPort(9999).withVerbose(true).withSilent(false).buildDesktopService();
service.start();
WiniumDriver winiumDriver = WiniumDriver(service, desktopOption);
Navigate and test WPF windows using winium. For example:
winiumDriver.findElement(By.id("someElementID")).click();
Create a ChromeOptions object which holds all needed selenium information such as chromium client and remote debugging port. Make sure to change the "XXXX" port to your remote debugging port.
System.setProperty("webdriver.chrome.driver", "c:/temp/chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("c:/temp/cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_windows64_client/Release/cefclient.exe");
chromeOptions.addArguments("remote-debugging-port=XXXX");
Open a chrome driver (selenium) using the chrome options object.
WebDriver seleniumDriver = ChromeDriver(chromeOptions);
Use element inside the chromium windows. For example:
seleniumWait.until(ExpectedConditions.visibilityOfElementLocated(By.className("someButtonClassName")));
seleniumDriver.findElement(By.className("someButtonClassName")).click();
When you're done with the CEF window, close selenium driver and continue with the winium driver:
seleniumDriver.quit();
winiumDriver.findElement(By.id("someElementID")).click();
Close main winium driver:
winiumDriver.quit();
这篇关于“Chrome Legacy Window"的自动化(铬)使用 Winium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!