Electron_Selenium

Selenium automation for Electron js Desktop App

The below tutorial provides how to do a Selenium automation for Electron js Desktop app in java

I don’t find a good guide for selenium Java with electron application for QA automation. So, I am writing this article to help anyone who is looking for it.

Steps:

  1. Install Eclipse
  2. Go to the Electron app release page
  3. Download the latest chrome webdriver from the above page
    • For Mac: download version 3.1.6
    • For Windows: Download version 3.16
  4. Extract into the location
  5. Copy the location path and replace into below code

Run the above program and it launches the electron app and prints the window title on the console. That’s a simple sample code I have written. Please use this approach to implement automation in your QA Automation projects.

Update:

Desired capabilities are depreciated so updated the code with below changes. If you face any difficulties, please drop a comment.

package myPackage;

import java.sql.Driver;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Test {
	public static void main(String args[]) throws InterruptedException {

		ChromeOptions opt = new ChromeOptions();
		//Enter the path of your Electron app
		opt.setBinary("<directory>\app.exe");
		System.setProperty("webdriver.chrome.driver",
				"<downloaded_chrome_driver_path>");
		WebDriver driver = new ChromeDriver(opt);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		

		//Printing the window title
		System.out.println(driver.getTitle());
		
	}
}

5
Leave a Reply

avatar
4 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
VickyAmadeo garcoaO.S.labsfactorManu Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Manu
Guest
Manu

For me it is unable to load dependent nodeJS files for the electron app installed

O.S.
Guest
O.S.

That code is deprecated.

Amadeo garcoa
Guest
Amadeo garcoa

The code part where is that written “WebDriver driver = new ChromeDriver(capabilities);” it’s deprecated

Vicky
Guest
Vicky

BRO Not able to identify the elements using locators for electron desktop application using selenium web driver. Could you please help out in this?….

%d bloggers like this: