5

I've been attempting to bypass using Spectron for End2End testing an electron application by leveraging my experience with Selenium Webdriver on Python. Using a combination of the Chromedriver get started page, and several resources that seem to suggest its possible, this is what I came up with:

from selenium import webdriver
import selenium.webdriver.chrome.service as service
servicer = service.Service('C:\\browserDrivers\\chromedriver_win32\\chromedriver.exe')
servicer.start()
capabilities = {'chrome.binary': 'C:\\path\\to\\electron.exe'}
remote = webdriver.remote.webdriver.WebDriver(command_executor=servicer.service_url, desired_capabilities = capabilities, browser_profile=None, proxy=None, keep_alive=False

The issue is that instead of opening the electron application, it opens a standard instance of Chrome.

Most of resources I've seen have been several years old so something may have changed to make it no longer possible.

Does anyone know of a way to use Python Selenium WebDriver to test an Electron application?

Yoni Shurygin
  • 65
  • 1
  • 6
  • I think this can help you: https://stackoverflow.com/questions/72447964/testing-electron-application-with-selenium-python-robotframework – Haythem May 31 '22 at 13:06

1 Answers1

5

Below works great for me

from selenium import webdriver


options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Electron.app/Contents/MacOS/Electron"

driver = webdriver.Chrome(chrome_options=options)

driver.get("http://www.google.com")


driver.quit()
Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265