0

I got a new task to automation an electron app on Mac. So I use python and selenium to start the task.

with the flowing code, I'm able to start the app but after the app is launched, the automation script hangs and not able to even print some messages.

Here is my code right now:

from time import sleep

from selenium import webdriver

def startdriver():

    print("start service")
    service = webdriver.chrome.service.Service("chromedriver")
    service.start()
    print("started")
    print(service.service_url)
    caps = {
                               'browserName': 'chrome',
                               'goog:chromeOptions': {
                                   'args': ['--no-sandbox',
                                            '--disable-dev-shm-usage'],
                                   'binary': r"/Applications/Enterprise.app/Contents/MacOS/Enterprise",
                                   'extensions': [],
                                   'windowTypes': ['webview']},
                               'platform': 'ANY',
                               'version': ''}
    print(caps)
    driver = webdriver.remote.webdriver.WebDriver(
                 command_executor=service.service_url,
                 desired_capabilities=caps,

                 #desired_capabilities={'chromeOptions': caps},
                 browser_profile=None,
                 proxy=None,
                 keep_alive=False)
    sleep(4)
    print("start")
    driver.get("http://www.google.com")

Here is the output of the script:

start service
started
http://localhost:50506
{'browserName': 'chrome', 'goog:chromeOptions': {'args': ['--no-sandbox', '--disable-dev-shm-usage'], 'binary': '/Applications/Enterprise.app/Contents/MacOS/Enterprise', 'extensions': [], 'windowTypes': ['webview']}, 'platform': 'ANY', 'version': ''}

And after about 1 min, the app closed and the script shows:

Traceback (most recent call last):
  File "/Users/leo.wong/auto/Auto/try/try4.py", line 31, in <module>
    keep_alive=False)
  File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Users/leo.wong/auto/Auto/venv/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

I have tried similar code in Java and Javascript with Spectron which is mentions on Electron official website. But I'm seeing the same thing.

My Environment:

  • MacOS: 10.14.6
  • Python: 3.7
  • Chrome: Version 79.0.3945.88 (Official Build) (64-bit)
  • Chromedriver: ChromeDriver 79.0.3945.36

Anyone has an idea how I can get it to work and I would like to provide more info but please let me know what I should provide.

Leon Wang
  • 3
  • 2

1 Answers1

0

There can be multiple reasons for this exception. One of the most common one is the incompatibility of ChromeDriver version and the electron version with which the electron app you are trying to automate is distributed/packed.

For e.g. If Electron version of my app is v7.1.2 then the ChromeDriver version to be used should be 78.0.3904.113.

More info about this compatibility can be found here - Electron and Chromium version

An example that I tried using Java v1.8, Electron v7.1.6 (Default electron.exe that gets created in node_module/.../dist folder) and ChromeDriver v78.0.3904.105

ChromeOptions options = new ChromeOptions();
options.setBinary("./electron-quick-start/node_modules/electron/dist/electron.exe");
ChromeDriverService chromeservices = new ChromeDriverService.Builder().build();
WebDriver driver = new ChromeDriver(chromeservices, options);
String chromeVersion = driver.findElement(By.cssSelector("ul > li.chrome-version")).getText();
String electronVersion = driver.findElement(By.cssSelector("ul > li.electron-version")).getText();
System.out.println("Chromium version : " + chromeVersion);
System.out.println("Electron version : " + electronVersion);
driver.quit();
  • 1
    Thanks for your answer and finally I found the developers used 3.x to build the app and for sure it is not compatible with the chrome 79.x. I will check the list and switch back to the old versions and hope this can solve my issue. – Leon Wang Dec 19 '19 at 20:01
  • 1
    Thanks for the idea and after I installed Spectron 5.0.0 which is compatible with the electron 3.x, I have my script running. – Leon Wang Dec 19 '19 at 23:27