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
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.
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
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
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 馃し鈥嶁檪
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-webdrivergem 馃し鈥嶁檪