本文介绍了“Chrome Legacy Window"的自动化(铬)使用 Winium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 和类似浏览器的浏览器?

解决方案

远程调试端口"是我的问题的解决方案.

  1. 我将remote-debugging-port=XXXX"添加到我的 CEF(Chromium 嵌入式框架)命令中:https://blog.chromium.org/2011/05/remote-debugging-with-chrome-developer.html这让我可以通过 localhost:XXXX 查看和管理我的应用程序的 CEF 窗口.

  2. 我同时使用了 Winium 和 Selenium 来测试我的应用程序.Winium 用于我所有的 WPF 窗口,而 selenium 用于我的所有 CEF 窗口.我的 GUI 测试从 Winium 驱动程序开始,以打开我的应用程序并导航 WPF 窗口.每次我需要调试 CEF 窗口时,我都会使用 selenium 和remote-debugging-port"参数打开一个 Chrome 驱动程序,它允许我单击该窗口内的元素.当我完成这个 chromium 窗口时,我将关闭 selenium 驱动程序并继续使用 Winium.

在 IntelliJ IDEA 中使用 Selenium 和 Winium

Selenium 是一个可移植的框架,用于测试和自动化 Web 应用程序.Winium 是一个基于 Selenium 的工具,用于在 Windows 上测试和自动化桌面应用程序.要在 IntelliJ IDEA 项目中使用这些模块,请按照以下步骤操作:

  1. 下载 selenium-server-standalone jar 文件(例如 selenium-server-standalone-3.141.59.jar)https://www.seleniumhq.org/download/
  2. 下载 winium-webdriver jar 文件(例如 winium-webdriver-0.1.0-1.jar)http://central.maven.org/maven2/com/github/2gis/winium/winium-webdriver/0.1.0-1/
  3. 将两个 jars 添加到您的项目结构中:文件 → 项目结构 → 依赖项 → +
  4. 现在所有的 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;

将 ChromeDriver 与 Selenium 一起使用

按照以下步骤操作:

  1. 安装 Java JDK 并将其 bin 目录添加到系统 PATH变量.
  2. 创建一个包含所有文件的目录.本教程使用 c:emp.
  3. 下载 ChromeDriver 并解压(如 chromedriver_win32.zip 提供 chomedriver.exe)https://sites.google.com/a/chromium.org/chromedriver/下载
  4. 下载 selenium-server-standalone-X.X.X-alpha-1.zip(例如 selenium-server-standalone-4.0.0-alpha-1.zip)http://selenium-release.storage.googleapis.com/index.html
  5. 从 Cefbuilds 下载 CEF 二进制分发客户端并提取(例如 cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_windows64.tar.bz2)http://opensource.spotify.com/cefbuilds/index.html
  6. 您的目录结构现在应该如下所示:
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 中使用 WiniumDriver

按照以下步骤操作:

  1. 下载 Winium.Desktop.Driver.zip 并解压到 c:emphttps://github.com/2gis/Winium.Desktop/releases

Java 代码示例

启动一个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?

解决方案

"Remote Debugging Port" was the solution for my problem.

  1. 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.htmlThis allowed me to see and manage my app's CEF windows through localhost:XXXX.

  2. 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.

Use Selenium and Winium with IntelliJ IDEA

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:

  1. Download selenium-server-standalone jar file (e.g. selenium-server-standalone-3.141.59.jar) https://www.seleniumhq.org/download/
  2. Download winium-webdriver jar file (e.g. winium-webdriver-0.1.0-1.jar)http://central.maven.org/maven2/com/github/2gis/winium/winium-webdriver/0.1.0-1/
  3. Add both jars to your project structure: File → Project Structure → Dependencies → +
  4. 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;
    

Use ChromeDriver with Selenium

Follow these steps:

  1. Install the Java JDK and add its bin directory to your system PATHvariable.
  2. Create a directory that will contain all files. This tutorial uses c:emp.
  3. Download ChromeDriver and extract it (e.g. chromedriver_win32.zip provides chomedriver.exe)https://sites.google.com/a/chromium.org/chromedriver/downloads
  4. Download selenium-server-standalone-X.X.X-alpha-1.zip (e.g. selenium-server-standalone-4.0.0-alpha-1.zip)http://selenium-release.storage.googleapis.com/index.html
  5. Download a CEF binary distribution client from Cefbuilds and extract (e.g. cef_binary_76.1.13+gf19c584+chromium-76.0.3809.132_windows64.tar.bz2)http://opensource.spotify.com/cefbuilds/index.html
  6. Your directory structure should now look similar to this:

For more information you can read this wiki:https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md

Use WiniumDriver with Winium

Follow these steps:

  1. Download the Winium.Desktop.Driver.zip and extract it to c:emphttps://github.com/2gis/Winium.Desktop/releases

Java Code Example

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 03:56