Selenium for Electron Applications

0_WMsq_uI0pTnauBUs

     Electron allows for the development of desktop GUI applications using front and back end components originally developed for web applications: Node.js run-time for the back-end and Chromium for the front-end.

    Electron uses HTML, JavaScript and CSS to build desktop applications. The vision of same codebase for web, mobile and desktop applications has never been closer.

   There is a small difference in the driver creation section when we compare with normal driver instantiation. Once the driver creation done; rest of the automation script executions are same as Selenium. Here I am explaining the driver creation for old and new selenium versions:

New selenium version(3.7.x) method driver creation in Electron Applications:

WebDriver driver;
System.setProperty(“webdriver.chrome.driver”, “pathTochromedriver”);
ChromeOptions options = new ChromeOptions();
options.setBinary(“pathToElectronApplication”);
ChromeDriverService chromeservices = new ChromeDriverService.Builder().build(); driver = new ChromeDriver(chromeservices, options);

Old selenium version method for driver creation in Electron Applications:

WebDriver driver;
System.setProperty(“webdriver.chrome.driver”, “pathTochromedriver”);
ChromeOptions options = new ChromeOptions();
options.setBinary(“pathToElectronApplication”);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“chromeOptions”, options ); capabilities.setBrowserName(“chrome”);
driver = new ChromeDriver(capabilities);

Shortcut to open inspect mode in Electron Applications,

Windows: Ctrl+Shift+i

MAC: Command+Alt+i

make it perfect !

9 thoughts on “Selenium for Electron Applications

  1. hi Sanoj,

    Thanks a lot for this ariticle.
    while running my application i am getting the following error:

    FAILED CONFIGURATION: @BeforeMethod setup
    org.openqa.selenium.WebDriverException: unknown error: no chrome binary at D:\Shared\roadMap
    (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 50 milliseconds
    Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: ‘2018-08-02T20:19:58.91Z’
    System info: host: ‘MUM-DSK-526’, ip: ‘10.102.193.204’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_191′
    Driver info: driver.version: ChromeDriver

    My code:

    WebDriver driver;

    @BeforeMethod
    public void setup() {

    System.setProperty(“webdriver.chrome.driver”, “D:\\softwares\\selenium\\chromedriver.exe”);
    ChromeOptions options = new ChromeOptions();
    options.setBinary(“D:\\Shared\\roadMap”);

    ChromeDriverService chromeservices = new ChromeDriverService.Builder().build(); driver = new ChromeDriver(chromeservices, options);

    }

    @Test
    public void test() throws InterruptedException {
    driver.findElement(By.xpath(“//p[contains(text(),’Call lists’)]”)).click();
    }
    }

    Can you please help in figuring it out.

    Like

  2. I am running into a different issue now for my electron desktop application.

    my code:
    WebDriver driver;

    @BeforeMethod
    public void setup() {

    System.setProperty(“webdriver.chrome.driver”,
    “D:\\softwares\\selenium\\chromedriver-v4.0.0-win32-x64\\chromedriver.exe”);
    ChromeOptions options = new ChromeOptions();
    options.setBinary(“D:\\Shared\\ProjectSandBox.exe”);
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(“chromeOptions”, options);
    capabilities.setBrowserName(“chrome”);

    options.addArguments(“start-maximized”); // open Browser in maximized mode
    options.addArguments(“disable-infobars”); // disabling infobars
    options.addArguments(“–disable-extensions”); // disabling extensions
    options.addArguments(“–disable-gpu”); // applicable to windows os only
    options.addArguments(“–disable-dev-shm-usage”); // overcome limited resource problems
    options.addArguments(“–no-sandbox”); // Bypass OS security model
    options.addArguments(“–headless”);
    driver = new ChromeDriver(capabilities);

    }

    }

    Issue:

    FAILED CONFIGURATION: @BeforeMethod setup
    org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally
    (unknown error: DevToolsActivePort file doesn’t exist)
    (The process started from chrome location D:\Shared\ProjectSandBox.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    (Driver info: chromedriver=69.0.3497.106 (857b284701ddf7bef0f14fa76416cf7ca786b411),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)

    Chrome version : Version 71.0.3578.98 (Official Build) (64-bit)
    selenium 3.14.0
    testNg 6.11
    ChromeDriver chromedriver-v4.0.0-win32-x64
    Windows 10

    Any help would be appreciated.

    Like

  3. Hi Sanoj, Thanks for enlightening us with the knowledge to automate Electron Application through selenium.

    I’m facing a problem here. I need to switch between Electron App and WebApplication . I use two drivers.
    1. to initiate Web and
    2. initiate Electron.

    I’m unable to get things into view/focus. Windows application gets overlapped by Electron App in the screen. I want to work on both the things one after another. Please help.

    Like

    1. What is the actual case? Do you have any connection or data exchange between electron app and web app? If it is parallel execution, you can handle it via testng.xml. If you need switch from electron app in between steps of test cases of between test cases:
      1. Load a electron app and get the session Id of electron app.
      2. Launch another browser and get the session ID that browser,
      3. Do whatever action needed in web browser.
      4. Compare the session Id’s of electron app, setDriver to electron driver and perform action in electron app,
      5. Compare the session Id’s of web app, setDriver to web app driver and validate your actions.

      You need to write a method to launch web driver (chrome or gecko driver), in your test case you can call that method to launch the web driver. Use SessionId sessionid = ((RemoteWebDriver) driver).getSessionId(); to get the session id.

      Like

  4. Hi,
    For electron desktop application automation is there any way to automate Tool bar options like File, Edit, View, Window and Help using selenium webdriver with python?
    I’m not able to inspect tool bar options using ctrl + shift + i.
    Let me know if there is any possible way.
    Also i’m not able to Maximize the application using both chrome options and using driver.maximize_window().

    Like

    1. In the case of Electron application, the toolbar is a builtin space in the Electron framework and you can’t inspect in a normal fashion. But there is an alternative you can use sikulixapi to perform click on toolbar but you have to pass image of the menu’s. Below is the dependency:

      com.sikulix
      sikulixapi
      1.1.0

      Create object of Screen class and then you can do the click action like
      Screen screen = new Screen();
      screen.click(“path_to_your_toolbar_menu_image”);

      Like

Leave a Reply to Hariharan Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s