0

I have a desktop application based on Electron (with Electron we can build cross-platform desktop apps with JavaScript, HTML, and CSS)

Can I test an it using Selenium Library?

Haythem
  • 43
  • 6

2 Answers2

1
  1. Electron contains Chromium and ChromeDriver, so it can talk to Chromium and Selenium, it’s just Webdriver implementation.
  2. Selenium needs this to be able to make calls to the Electron App. ChromeDriver acts as a bridge between Selenium and our application, it follows Selenium wire protocol. By default, chromium runs on port 9515. Selenium - ChromeDriver - ElectronApp

- Demo

1. Install and start ChromeDriver: we need to download ChromeDriver version which matches what our application uses.

With Python: Testing Electron application with SeleniumLibrary with

Arguments:

  • command_executor: Local or remote port where chromedriver is running (9515 in our case)
  • desired_capabilities: dictionary specifying location of Electron App executable (ElectronApp.exe)
  • remote-debugging-port: port for the application (7070 in our case)

==> After this you should see the first page of your Electron Application pop up!

with RobotFramework: Testing Electron application with SeleniumLibrary with RobotFramework

The options argument can be used to launch Chomium-based applications which utilize the Chromium Embedded Framework . To launch Chomium-based application, use options to define binary_location attribute and use add_argument method to define remote-debugging-port port for the application. Once the browser is opened, the test can interact with the application.

Haythem
  • 43
  • 6
0

By RobotFramework

  1. Download Chrome Driver. It must be same Chrome version in Electron.

  2. Start chromedriver.exe as a service

***Keywords***
Start WebDriver Service
    ${port}             Convert To Integer      ${portNumber}
    ${service}=         Evaluate        sys.modules['selenium.webdriver'].chrome.service      sys
    ${service}          CallMethod      ${service}      Service         path/to/chromedriver.exe     port=${port}
    Call Method         ${service}      start

the ${portNumber} is a variable for port of ChromeDriver

  1. Start Electron application
Start Electron App
    ${options}=         Evaluate        sys.modules['selenium.webdriver'].ChromeOptions()     sys
    Call Method         ${options}      add_argument                        --remote-debugging-port\=7070
    Call Method         ${options}      add_argument                        --no-sandbox
    ${options.binary_location}    Set Variable    path/to/electron/application
    Create WebDriver    Remote          command_executor=127.0.0.1:${portNumber}     options=${options}

then you can run test cases like browser Apps.

behtgod
  • 251
  • 3
  • 15