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

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


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

Here, the path-to-electron-app is the directory where the application source (main.js) is stored, and the electron binary is taken from dependencies downloaded during the build process.

Alternatively, if you want to work with precompiled application - it itself becomes the electron binary, and you can use the following:

System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); Map<String, Object> chromeOptions = new HashMap<>();chromeOptions.put("binary", "D:\\my-electron-app.exe");DesiredCapabilities capabilities = new DesiredCapabilities();capabilities.setCapability("chromeOptions", chromeOptions);capabilities.setBrowserName("chrome");WebDriver driver = new ChromeDriver(capabilities);