Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My nightwatch.js tests not runs in Chrome headless of CentOS

I run nightwatch.js tests using Nightwatch version 1.0.18 and It's working in windows environment but when I run it in centOS after installment of Xvfb I found below error.

 Error while running .navigateTo() protocol action: invalid session id

 Error while running .locateMultipleElements() protocol action: invalid session id

 Error while running .locateMultipleElements() protocol action: invalid session id

Here is my nightwatch.json file code:

{
  "src_folders": [
    "./tests"
  ],
  "output_folder": "./reports",
  "custom_commands_path": "./custom_commands",
  "custom_assertions_path": "",
  "test_workers": false,
  "webdriver": {
    "start_process": true
  },
  "test_settings": {
    "default": {
      "webdriver": {
        "port": 9515,
        "server_path": "./node_modules/chromedriver/lib/chromedriver/chromedriver",
        "cli_args": [
          "--log",
          "debug"
        ]
      },
      "skip_testcases_on_fail": true,
      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "chromeOptions": {
          "args": [
            "headless",
            "no-sandbox",
            "disable-gpu"
          ]
        }
      }
    }
  }
}

am I missing something to run my tests in the centOS environment because it is running in the windows environment?

like image 762
Dbshah Avatar asked Oct 21 '25 05:10

Dbshah


2 Answers

I had the same issue with Nightwatchjs and the npm chomedriver setup.

Background: Everything was working until I just recently updated Chromium on my system. In addition to the errors in the original post, verbose logging also showed:

{ 
  message: 'unknown error: Chrome failed to start: exited abnormally',
  error: [ 
    "(unknown error: DevToolsActivePort file doesn't exist)",
    '(The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)',
    '(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.9.0-8-amd64 x86_64)'
  ],
}

After downloading the standalone chromedriver (2.46.628388) to match my Chromium version (72.0.3626.69) it was still showing the same errors.

Solution: I ended up downloading an older version of Chromium (71.0.3578.127) and setting chromeOptions.binary to the new path of the chromium 71 binary. I also had to include 'no-sandbox' with chromeOptions.args.

Here is the snippet from the site mentioned above:

Downloading old builds of Chrome / Chromium

Let's say you want a build of Chrome 44 for debugging purposes. Google does not offer old builds as they do not have up-to-date security fixes.

However, you can get a build of Chromium 44.x which should mostly match the stable release. Here's how you find it:

  • Look in https://googlechromereleases.blogspot.com/search/label/Stable%20updates for the last time "44." was mentioned.
  • Loop up that version history ("44.0.2403.157") in the Position Lookup
  • In this case it returns a base position of "330231". This is the commit of where the 44 release was branched, back in May 2015.*
  • Open the continuous builds archive
  • Click through on your platform (Linux/Mac/Win)
  • Paste "330231" into the filter field at the top and wait for all the results to XHR in.
  • Eventually I get a perfect hit: https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Mac/330231/
  • Sometimes you may have to decrement the commit number until you find one.
  • Download and run!
like image 76
Amanda Flink Avatar answered Oct 24 '25 16:10

Amanda Flink


Upgrading to the latest version of chromedriver solved the issue for me. You can find the latest version here; https://www.npmjs.com/package/chromedriver

like image 44
Anthony Ngene Avatar answered Oct 24 '25 14:10

Anthony Ngene