【问题标题】:Testing Electron application with org.openqa.selenium in a Java environment (Intellij)在 Java 环境 (Intellij) 中使用 org.openqa.selenium 测试 Electron 应用程序
【发布时间】:2016-02-19 14:08:58
【问题描述】:

有没有办法在 Java 环境中为 Electron 应用程序使用 cucumberselenium-webdriver 创建自动化场景?

我在electron.atom.io 上找到了一些Node.js 解决方案,但我更喜欢Java。

谢谢。

【问题讨论】:

    标签: java selenium intellij-idea electron cucumber-jvm


    【解决方案1】:

    您可以通过 ChromeDriver 使用 Electron 浏览器。尝试使用类似的设置创建 WebDriver:

    // If chromediver executable is not in your project directory, 
    //  point to it with this system variable
    System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); 
    
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    chromeOptions.put("binary", "path/to/electron/binary");
    chromeOptions.put("args", Arrays.asList(" path-to-electron-app"));
    //eg.: chromeOptions.put("binary", "D:\\electron-quick-start\\node_modules\\electron-prebuilt\\dist\\electron.exe");
    //     chromeOptions.put("args", Arrays.asList(" D:\\electron-quick-start"));
    //  for some reason the app arg needs to follow a space on my Windows machine
        
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("chromeOptions", chromeOptions);
    capabilities.setBrowserName("chrome");
    
    WebDriver driver = new ChromeDriver(capabilities);
    

    这里,path-to-electron-app 是存储应用程序源 (main.js) 的目录,电子二进制文件取自构建过程中下载的依赖项。

    或者,如果您想使用预编译的应用程序 - 它本身会变成电子二进制文件,您可以使用以下内容:

    System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); 
    Map<String, Object> chromeOptions = new HashMap<>();
    chromeOptions.put("binary", "D:\\my-electron-app.exe");
    
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("chromeOptions", chromeOptions);
    capabilities.setBrowserName("chrome");
    
    WebDriver driver = new ChromeDriver(capabilities);
    

    【讨论】:

    • 非常直接的回答,对我帮助很大。谢谢!
    • path/to/electron/binary 和 path-to-electron-app 有什么区别?你能举个例子吗?它们都以 exe 结尾还是我们正在寻找 dll?我可以让我的 chromedriver 打开 chrome,但我无法让它打开应用程序
    • @LorenRogers 如果您使用的是 exe 而不是应用程序源,那么您的 exe 电子/二进制文件,因此您可以跳过 args 选项。查看更新的答案。
    • 当使用已编译的应用程序并将二进制文件定向到我的 .exe 时,我收到一条错误消息,指出在 Users/myUsername/electronAppFolder/dist_electron/win-unpacked/myApp.exe 中没有 chrome 二进制文件。我什至设置了 System.Setproperty("webdriver.chrome.driver"," C://chromdriver.exe") 。我打开了 chrome 浏览器,然后测试失败,并在 Users/myUsername/electronAppFolder/dist_electron/win-unpacked/myApp.exe 处显示 no chrome binary 消息我错过了什么?
    猜你喜欢
    • 2017-04-01
    • 2021-06-16
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-29
    • 2016-04-23
    相关资源
    最近更新 更多