繁体   English   中英

如何为 CEF 应用程序编写 Selenium 测试

[英]How to write Selenium tests for CEF applications

我有一个C++应用程序application.exe ,它使用CEF browser (chrome 嵌入式框架)作为 UI。

对于这个 UI,我想用Selenium开发自动化测试。 通常我通过Python控制Selenium

我曾多次使用chromedriver并开发了浏览器测试。 我不太明白如何使用它来控制CEF browser

我已经在这里找到了一些包含相同主题的页面。 但是,我仍然不了解SeleniumCEF browser之间的交互。

我的目标是Selenium启动application.exe以便我可以控制CEF browser web 元素。

您需要在chromeoptions 中设置setBinary并提供CEF 浏览器.exe 文件的路径。

Java 示例代码:

public class Example  {
  public static void main(String[] args) {
    // Path to the ChromeDriver executable.
    System.setProperty("webdriver.chrome.driver", "c:/temp/chromedriver.exe");

    ChromeOptions options = new ChromeOptions();
    // Path to the CEF executable.
    options.setBinary("c:/temp/cef_binary_3.2171.1979_windows32_client/Release/cefclient.exe");
    // Port to communicate on. Required starting with ChromeDriver v2.41.
    options.addArguments("remote-debugging-port=12345");

    WebDriver driver = new ChromeDriver(options);
    driver.get("http://www.google.com/xhtml");
    sleep(3000);  // Let the user actually see something!
    WebElement searchBox = driver.findElement(By.name("q"));
    searchBox.sendKeys("ChromeDriver");
    searchBox.submit();
    sleep(3000);  // Let the user actually see something!
    driver.quit();
  }

  static void sleep(int time) {
    try { Thread.sleep(time); } catch (InterruptedException e) {}
  }
}

来源:

https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md

https://www.ultimateqa.com/chromium-embedded-framework/

注意:您可能需要在项目中使用不同版本的 chrome 驱动程序二进制文件和 chrome 版本依赖项。 确定与您当前版本的CEF browser兼容的版本

Chrome 驱动程序二进制文件的下载链接:

https://chromedriver.storage.googleapis.com/index.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM