是否有使用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);
}
4 回答
你可以阅读Using Selenium and WebDriver . 我通常不会粘贴链接,但您应该阅读此内容 . 其他章节也可能对您有用 .
我可以给出一个在macOS上完美运行的例子,因为我最近一直在测试它们 .
这是我在MacOS上使用seleniumWebDriver Java启动电子应用程序的示例
您是否尝试在硒网格的帮助下在远程驱动程序上使用相同的方法?我的应用程序是基于电子的消息传递应用程序,需要在两个应用程序之间发送 - 接收消息 . 我可以在我的本地机器上执行任何操作,发送即时消息,使用所有按钮,登录注销等,但是当涉及到使用为节点机器设置的远程驱动程序时,即使调用应用程序的二进制文件并启动应用程序,远程驱动程序无能为力,