是否有示例java代碼用於使用硒 - chromedriver啓動電子應用程序?這是我在這裏的地方。我的代碼帶來了電子應用程序,我可以在該頁面上查看webElements,但不會啓動我需要測試的應用程序。我可以將應用程序拖到電子窗口並啓動,但WebDriver並未指向它。測試在MacOS環境下使用硒,java的電子應用程序
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);
}
製作相反發射電子,並試圖路徑傳遞到構建的進步......,我已經建立的應用程序,我設置的二進制MacOS的建立。應用程序中:options.setBinary ( 「/Users/username/work/ape/out/packages/mac/appName.app/Contents/MacOS/appName」);這現在調出應用程序本身,但有必要抓住第二個窗口句柄並在出現窗口時執行driver.switchTo。 – AJW