Automation for “Chrome Legacy Window” (Chromium) using Winium

前端 未结 1 869
借酒劲吻你
借酒劲吻你 2021-01-20 16:15

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 too

相关标签:
1条回答
  • 2021-01-20 16:36

    "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.html This 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 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
    

    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:\temp https://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();
    
    0 讨论(0)
提交回复
热议问题