【发布时间】:2017-04-01 12:14:04
【问题描述】:
是否有使用 selenium-chromedriver 启动电子应用程序的示例 java 代码?这就是我现在的位置。我的代码启动了电子应用程序,我可以在该页面上查看 webElements,但没有启动我需要测试的应用程序。我可以将应用程序拖到电子窗口并启动它,但 WebDriver 没有指向它。
private void electronTest() throws Exception {
//select electron-chromedriver
System.setProperty("webdriver.chrome.driver", "/Users/username/work/node_modules/electron-chromedriver/bin/chromedriver");
ChromeOptions options = new ChromeOptions();
// path for Electron
options.setBinary("/Users/username/work/app/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron");
// I have tried both the folder and the app
options.addArguments("/Users/username/work/app/out/packages/mac/electronApplication.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", options);
capabilities.setBrowserName("chrome");
driver = new ChromeDriver(capabilities);
// have also tried...
//driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
// Electron page appears, but doesn't launch the Electron app
// driver is pointing to the electron page elements even if I drag the app to launch it
String screenText = " [" + driver.findElement(By.tagName("BODY")).getText().replace("\n", "][") + "]";
System.out.println("screenText " + screenText);
}
【问题讨论】:
-
取得进展... 我没有启动 Electron 并尝试将路径传递给构建,而是构建了应用程序,并将二进制文件设置为 .app 中的 MacOS 构建:选项.setBinary("/Users/username/work/ape/out/packages/mac/appName.app/Contents/MacOS/appName");现在这会启动应用程序本身,但有必要抓住第二个窗口句柄并在窗口出现时执行 driver.switchTo。
标签: java macos selenium electron selenium-chromedriver