Testing Electron application with org.openqa.selenium in a Java environment (Intellij)

眉间皱痕 提交于 2020-01-13 04:56:25

问题


Is there a way to create automated scenarios using cucumber and selenium-webdriver in Java environment for an Electron application?

I found some Node.js solutions on electron.atom.io, but I would prefer Java.

Thanks.


回答1:


You can use Electron browser with ChromeDriver. Try creating WebDriver with similar setup:

// 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);


来源:https://stackoverflow.com/questions/35507295/testing-electron-application-with-org-openqa-selenium-in-a-java-environment-int

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!