skip to Main Content

I’ve been trying to change the way I start the Selenium grid service from a shell script in .rclocal to a systemd service, but it is not working. The script is this:


#!/bin/bash
java -jar /opt/selenium-server-standalone.jar -role hub -hubConfig hubconfig.json
xvfb-run --server-args="-screen 0 2048x1536x24" java -jar /opt/selenium-server-standalone.jar -role 
node -nodeConfig nodeconfig.json

I created two different services as follows:

(Stackoverflow won’t let me put the contents of the services as it says it is not properly formated)

The services are starting correctly:

selenium-hub


● selenium-hub.service - Selenium service
   Loaded: loaded (/etc/systemd/system/selenium-hub.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-10-01 15:53:10 UTC; 2min 41s ago
 Main PID: 23803 (java)
   CGroup: /system.slice/selenium-hub.service
           └─23803 /bin/java -jar /opt/selenium-server-standalone.jar -role hub -hubConfig /home/selenium/hubconfig.json

Oct 01 15:53:12 vm java[23803]: 15:53:12.163 INFO - Selenium build info: version: '3.9.1', revision: '63f7b50'
Oct 01 15:53:12 vm java[23803]: 15:53:12.164 INFO - Launching Selenium Grid hub on port 4444
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.384:INFO::main: Logging initialized @2790ms to org.seleniumhq.jetty9.util.log.StdErrLog
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.492:INFO:osjs.Server:main: jetty-9.4.7.v20170914, build timestamp: 2017-11-21T21:27:37Z, git hash: 82b8fb23f757335bb3329d540ce37a2a2615f0a8
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.524:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.524:INFO:osjs.session:main: No SessionScavenger set, using defaults
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.529:INFO:osjs.session:main: Scavenging every 660000ms
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.538:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@60704c{/,null,AVAILABLE}
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.562:INFO:osjs.AbstractConnector:main: Started ServerConnector@1fe20588{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
Oct 01 15:53:13 vm java[23803]: 2019-10-01 15:53:13.562:INFO:osjs.Server:main: Started @2968ms
Oct 01 15:53:13 vm java[23803]: 15:53:13.562 INFO - Selenium Grid hub is up and running
Oct 01 15:53:13 vm java[23803]: 15:53:13.562 INFO - Nodes should register to http://1.2.3.4:4444/grid/register/
Oct 01 15:53:13 vm java[23803]: 15:53:13.562 INFO - Clients should connect to http://1.2.3.4:4444/wd/hub
Oct 01 15:53:14 vm java[23803]: 15:53:14.797 INFO - Registered a node http://1.2.3.4:5555

selenium-node:


● selenium-node.service - Selenium nodes
   Loaded: loaded (/etc/systemd/system/selenium-node.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-10-01 15:53:10 UTC; 6min ago
 Main PID: 23813 (xvfb-run)
   CGroup: /system.slice/selenium-node.service
           ├─23813 /bin/sh /bin/xvfb-run --server-args="-screen 0 2048x1536x24" java -jar /opt/selenium-server-standalone.jar -role node -nodeConfig /home/selenium/nodeconfig.json
           ├─23856 java -jar /opt/selenium-server-standalone.jar -role node -nodeConfig /home/selenium/nodeconfig.json
           ├─24326 /usr/local/bin/chromedriver --port=1713
           ├─24327 /usr/local/bin/chromedriver --port=26741
           ├─24328 /usr/local/bin/chromedriver --port=20065
           ├─24329 /usr/local/bin/chromedriver --port=6459
           ├─24331 /usr/local/bin/chromedriver --port=15872
           ├─24332 /usr/local/bin/chromedriver --port=29475
           ├─24333 /usr/local/bin/chromedriver --port=30216
           ├─24334 /usr/local/bin/chromedriver --port=6955
           ├─24558 /usr/local/bin/chromedriver --port=2425
           ├─24559 /usr/local/bin/chromedriver --port=19304
           ├─24560 /usr/local/bin/chromedriver --port=12150
           ├─24561 /usr/local/bin/chromedriver --port=26147
           ├─24562 /usr/local/bin/chromedriver --port=16545
           ├─24570 /usr/local/bin/chromedriver --port=12780
           ├─24602 /usr/local/bin/chromedriver --port=10959
           ├─24603 /usr/local/bin/chromedriver --port=8970
           ├─24753 /usr/local/bin/chromedriver --port=13438
           ├─24754 /usr/local/bin/chromedriver --port=15725
           └─24772 /usr/local/bin/chromedriver --port=28829

Oct 01 15:55:19 vm xvfb-run[23813]: Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) on port 15725
Oct 01 15:55:19 vm xvfb-run[23813]: Only local connections are allowed.
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.112 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.113 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.114 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.115 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@53702c02
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.115 INFO - Found handler: org.openqa.selenium.remote.server.commandhandler.BeginSession@4ae12041
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.116 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.117 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.118 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.118 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.120 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.120 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.121 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.123 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.123 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.124 INFO - /session: Executing POST on /session (handler: BeginSession)
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.139 INFO - Capabilities are: Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm
Oct 01 15:55:19 vm xvfb-run[23813]: 15:55:19.139 INFO - Capabilities {browserName: chrome, goog:chromeOptions: {args: [enable-automation, disable-infobars, disable-notifications, no-sandbox, --disable-dev-shm-usage, window-siz
Oct 01 15:55:19 vm xvfb-run[23813]: Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442}) on port 26147
Oct 01 15:55:19 vm xvfb-run[23813]: Only local connections are allowed.
Oct 01 15:55:19 vm xvfb-run[23813]: Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

However all tests fails with the same error:

OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'

The problem with DevToolsActivePort is derived from /dev/shm being too small and sometimes crashing the browser (https://stackoverflow.com/a/50642913/5364231, https://bugs.chromium.org/p/chromium/issues/detail?id=736452#c64) so I already added --disable-dev-shm-usage to the capabilities.

The problem, I think, resided in the service selenium-hub not being able to communicate with selenium-node. Any help is greatly appreciated.

2

Answers


  1. Thumb rule

    A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


    This error message…

    OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
    (unknown error: DevToolsActivePort file doesn't exist)
    (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z'
    

    …implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.


    Your main issue is the incompatibility between the version of the binaries you are using as follows:

    • You are using the latest chromedriver=77.0
    • Presumably you are using chrome= 77.0.
    • Your Selenium Client version is 3.9.1 of 2018-02-07T22:42:28.403Z which is almost 1.5 years older.

    So there is a clear mismatch between the Selenium Client v3.9.1 , ChromeDriver v77.0 and the Chrome Browser v77.0


    Solution

    Ensure that:

    • JDK is upgraded to current levels JDK 8u221.
    • Selenium is upgraded to current levels Version 3.141.59.
    • ChromeDriver is updated to current ChromeDriver v77.0 level.
    • Chrome is updated to current Chrome Version 77.0 level. (as per ChromeDriver v77.0 release notes)
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
    • Take a System Reboot.
    • Execute your @Test as non-root user.

    Reference

    You can find a couple of detailed discussions in:


    Outro

    Here is the link to the Sandbox story.

    Login or Signup to reply.
  2. Sometimes this Happens when Chrome is Updated to newer version but driver binaries are still older. Make sure that Chrome browser and ChromeDriver have the same version

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search