Virtual-environments: "DevToolsActivePort file doesn't exist" error when running Capybara tests using headless Chrome

Created on 5 Mar 2020  路  6Comments  路  Source: actions/virtual-environments

Describe the bug

I have a Rails app that uses Capybara to run some integration tests using Selenium and headless Chrome, but I get this error when the tests execute.

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.) (Selenium::WebDriver::Error::UnknownError)

This is my job file (uses ubuntu-latest):

name: Application Build & Test
on: [push]

jobs:
  build:
    name: Build & run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-ruby@v1
        with:
          ruby-version: "2.4"
      - uses: actions/setup-node@v1
        with:
          node-version: "10.x"

      - uses: actions/cache@v1
        env:
          cache-name: gem-cache
        with:
          path: ./vendor/bundle
          key: build-${{ env.cache-name }}-${{ hashFiles('**/Gemfile.lock') }}

      - name: Build
        env:
          RAILS_ENV: test
        run: |
          sudo apt-get update && sudo apt-get -yqq install libpq-dev libsqlite3-dev
          gem install bundler:1.16.2
          bundle config set path 'vendor/bundle'
          bundle install --jobs 4 --retry 3
          bundle exec rails db:create
          bundle exec rails db:migrate

      - name: Unit tests
        env:
          RAILS_ENV: test
          MAILER_TO: ${{ secrets.MAILER_TO }}
        run: |
          mkdir -p /tmp/test-results

          bundle exec rspec --format progress \
            --format RspecJunitFormatter \
            --out /tmp/test-results/rspec.xml \
            --format progress

      - name: Integration tests
        env:
          RAILS_ENV: test
          MAILER_TO: ${{ secrets.MAILER_TO }}
        run: |
          bundle exec cucumber --format junit --out /tmp/test-results/cucumber

This is how headless Chrome is initialized:

Capybara.register_driver :headless_chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: { args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage] }
  )

  Capybara::Selenium::Driver.new app,
                                 browser: :chrome,
                                 desired_capabilities: capabilities
end

I understand from recent issues that Chromedriver is now supported by default on all images. Am I using it correctly?

Area for Triage:

Ruby

Question, Bug, or Feature?:
Question/bug

Virtual environments affected

  • [ ] macOS 10.15
  • [X] Ubuntu 16.04 LTS
  • [X] Ubuntu 18.04 LTS
  • [ ] Windows Server 2016 R2
  • [ ] Windows Server 2019

Expected behavior
Chromedriver to be available and working during my integration tests

Actual behavior

The error described above is received when trying to run integration tests using Selenium and headless Chrome.

The repository that I'm having trouble with is private but I am willing to add someone as a contributor to help diagnose the problem.

Common Tools Ruby Ubuntu bug needs triage

Most helpful comment

@al-cheb Thanks for the detailed diagnosis. I appear to have it working now - the only thing I've done is update the selenium-webdriver gem 馃し鈥嶁檪

All 6 comments

Hello, @stevehobbsdev
Could you please try to add just for test a parameter --remote-debugging-port=9222

Thanks @al-cheb . Where am I adding that parameter? Onto the end of the cucumber command?

bundle exec cucumber --format junit --out /tmp/test-results/cucumber --remote-debugging-port=9222

chromeOptions: { args: %w[headless disable-gpu no-sandbox disable-dev-shm-usage] } <- Param section

Thanks @al-cheb, I have added the parameter but nothing changed, the tests still fail for the same reason.

Python3 ChromeDriver test works without any errors.

name: CI
on: [push]

jobs:
  build:
    runs-on: [ubuntu-latest]
    steps:
      - name: Install Selenium
        run: |
            sudo pip3 install selenium
      - name: ChromeWebDriver
        run: |
            cat <<EOF >> test.py
            from selenium import webdriver
            from selenium.webdriver.chrome.options import Options
            options = Options()
            options.add_argument("--headless")
            options.add_argument('--no-sandbox')
            options.add_argument('--disable-gpu')
            options.add_argument('--disable-dev-shm-usage')
            options.add_argument('disable-infobars')
            options.add_argument("--disable-extensions")
            driver = webdriver.Chrome(chrome_options=options, executable_path='/usr/bin/chromedriver')
            driver.get("http://github.com/")
            print ('Page title is ' + driver.title)
            EOF

            python3 test.py

Capture - Copy

Ruby ChromeDriver test works without any errors:

name: CI
on: [push]

jobs:
  build:
    runs-on: [ubuntu-latest]
    steps:
      - name: Install Selenium
        run: |
            sudo gem install selenium-webdriver
            wget https://filebin.net/6cw0f2x2sfgqyhi0/headless_chrome.rb?t=7g4c257d -O headless_chrome.rb
            chmod +x headless_chrome.rb
      - name: ChromeWebDriver
        run: |
            ./headless_chrome.rb

Capture - Copy

Ruby script:

#!/usr/bin/ruby
require 'selenium-webdriver'

def setup
    Selenium::WebDriver::Chrome::Service.driver_path = "/usr/bin/chromedriver"

    # options
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')

    # create driver using options and capabilities
    @driver = Selenium::WebDriver.for :chrome, options: options

end

def teardown
    @driver.quit
end

def run
    setup
    yield
    teardown
end

run do
    # go to google search page
    @driver.get 'http://www.github.com'

    # create screenshot of search results
    print "RESULTS TITLE: #{@driver.title}\n"
end

@al-cheb Thanks for the detailed diagnosis. I appear to have it working now - the only thing I've done is update the selenium-webdriver gem 馃し鈥嶁檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mxschmitt picture mxschmitt  路  3Comments

orj picture orj  路  4Comments

adamsiembida picture adamsiembida  路  3Comments

frankieroberto picture frankieroberto  路  4Comments

motss picture motss  路  3Comments