LeeWay LeeWay - 1 year ago 358
Java Question

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

Is there a way to create automated scenarios using

in Java environment for an Electron application?

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


Answer Source

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

WebDriver driver = new ChromeDriver(capabilities);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download