Yoni Shurygin
Yoni Shurygin

Reputation: 65

Using Python Selenium Webdriver to open Electron Application

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?

Upvotes: 5

Views: 4012

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

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()

Upvotes: 5

Related Questions