自动化"Chrome旧版窗口" (铬)使用Winium [英] Automation for "Chrome Legacy Window" (Chromium) using Winium

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

问题描述

我正在尝试使用Winium自动化Windows应用程序GUI.该应用程序同时使用WPF窗口和"Chrome旧版窗口"(Chromium)窗口.

I'm trying to automate a Windows application GUI using Winium. The app is using both WPF windows and "Chrome Legacy Window" (Chromium) windows.

我正在使用工具自动化间谍" 检查WPF窗口中与Winium一起使用的GUI元素的ID. Automation Spy无法以与Winium无法访问这些元素相同的方式来检查"Chrome旧版窗口"窗口中​​的元素.

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旧版窗口"是一个WEB窗口,因此需要使用Selenium进行自动化.

"Chrome Legacy Window" is a WEB window, so it requires automation with Selenium.

如何使用Selenium钩住Chromium窗口,而不是像Firefox,Chrome等类似的浏览器?

How do I use Selenium to hook on a Chromium window, which is not a browser like Firefox, Chrome and similar?

推荐答案

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

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

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

我同时使用Winium和Selenium来测试我的应用程序. 我的所有WPF窗口均使用Winium,我的所有CEF窗口均使用硒. 我的GUI测试从Winium Driver开始,以打开我的应用程序并浏览WPF窗口. 每次我需要调试CEF窗口时,我都会使用带有"remote-debugging-port"参数的硒打开Chrome驱动程序,这使我可以单击该窗口中的元素.当我完成此铬窗口后,我将关闭硒驱动程序,并继续运行Winium.

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.

通过IntelliJ IDEA使用Selenium和Winium

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

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. 下载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. 将两个jar都添加到您的项目结构中:File→Project Structure→Dependencies→+
  4. 现在所有Selenium和Winium导入都可以使用.例如:

  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;

将ChromeDriver与Selenium一起使用

请按照以下步骤操作:

Use ChromeDriver with Selenium

Follow these steps:

  1. 安装Java JDK并将其bin目录添加到系统PATH中 变量.
  2. 创建一个包含所有文件的目录.本教程使用c:\​​ temp.
  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. 您的目录结构现在看起来应与此类似:
  1. Install the Java JDK and add its bin directory to your system PATH variable.
  2. Create a directory that will contain all files. This tutorial uses c:\temp.
  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:

c:\temp\
  cef_binary_3.2171.1979_windows32_client\
    Release\
      cefclient.exe  (and other files)
  chromedriver.exe
  Example.java
  selenium-server-standalone-2.44.0.jar

有关更多信息,您可以阅读以下Wiki: https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md

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

请按照以下步骤操作:

  1. 下载Winium.Desktop.Driver.zip并将其解压缩到c:\ temp https://github.com/2gis/Winium.Desktop/releases
  1. Download the Winium.Desktop.Driver.zip and extract it to c:\temp https://github.com/2gis/Winium.Desktop/releases

Java代码示例

启动Winium驱动程序并打开您的应用程序:

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);

使用Winium导航和测试WPF窗口.例如:

Navigate and test WPF windows using winium. For example:

winiumDriver.findElement(By.id("someElementID")).click();

创建一个ChromeOptions对象,其中包含所有必需的硒信息,例如Chrome客户端和远程调试端口. 确保将"XXXX"端口更改为远程调试端口.

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");

使用chrome选项对象打开chrome驱动程序(硒).

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();

在完成CEF窗口后,请关闭Selenium驱动程序,然后继续使用Winium驱动程序:

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();

关闭主要的Winium驱动程序:

Close main winium driver:

winiumDriver.quit();

这篇关于自动化"Chrome旧版窗口" (铬)使用Winium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆