Ruby on Rails Project
Rails 5.2.3
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
Using webdrivers and capybara
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
gem 'faker'
gem 'guard-minitest'
gem 'webdrivers'
end
Heroku CI environment
"environments": {
"test": {
"buildpacks": [{
"url": "heroku/ruby"
},
{
"url": "heroku/nodejs"
},
{
"url": "heroku-community/apt"
},
{
"url": "https://github.com/heroku/heroku-buildpack-chromedriver"
},
{
"url": "https://github.com/heroku/heroku-buildpack-google-chrome"
}
],
"addons": [
"heroku-redis:in-dyno",
"heroku-postgresql:in-dyno"
],
"scripts": {
"test-setup": "bin/rails assets:precompile",
"test": "rake"
}
}
}
Capybara and Webdrivers settings
require 'webdrivers'
require 'capybara/rails'
require 'capybara/minitest'
Capybara.server = :puma, { Silent: true }
Capybara.server_port = 55_707
Capybara.default_max_wait_time = 10
Webdrivers.cache_time = 86_400
Webdrivers.logger.level = :DEBUG
Selenium::WebDriver::Chrome.path = ENV.fetch('GOOGLE_CHROME_BIN', nil)
chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil)
chrome_opts = chrome_bin ? { 'chromeOptions' => { 'binary' => chrome_bin }, 'args' => ['--headless', '--no-sandbox', '--disable-gpu', '--remote-debugging-port=9222'] } : {}
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(
app,
browser: :chrome,
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(chrome_opts)
)
end
Capybara.javascript_driver = :chrome
class ActionDispatch::SystemTestCase
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
# Make `assert_*` methods behave like Minitest assertions
include Capybara::Minitest::Assertions
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400] unless ENV['CI']
# Reset sessions and driver between tests
teardown do
Capybara.reset_sessions!
Capybara.use_default_driver
end
end
Running
# Running:
2019-06-12 20:16:20 DEBUG Webdrivers Checking current version
2019-06-12 20:16:20 DEBUG Webdrivers /app/.webdrivers/chromedriver is not already downloaded
2019-06-12 20:16:20 DEBUG Webdrivers making System call: /app/.apt/opt/google/chrome/chrome --product-version
2019-06-12 20:16:20 DEBUG Webdrivers Browser version: 75.0.3770.80
2019-06-12 20:16:20 DEBUG Webdrivers making System call: /app/.apt/opt/google/chrome/chrome --product-version
2019-06-12 20:16:20 DEBUG Webdrivers Browser version: 75.0.3770.80
2019-06-12 20:16:20 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_75.0.3770
2019-06-12 20:16:21 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2019-06-12 20:16:21 DEBUG Webdrivers Latest version available: 75.0.3770.8
2019-06-12 20:16:21 DEBUG Webdrivers Deleting /app/.webdrivers/chromedriver.version
2019-06-12 20:16:21 DEBUG Webdrivers Deleting /app/.webdrivers/chromedriver
2019-06-12 20:16:21 DEBUG Webdrivers making System call: /app/.apt/opt/google/chrome/chrome --product-version
2019-06-12 20:16:21 DEBUG Webdrivers Browser version: 75.0.3770.80
2019-06-12 20:16:21 DEBUG Webdrivers making System call: /app/.apt/opt/google/chrome/chrome --product-version
2019-06-12 20:16:21 DEBUG Webdrivers Browser version: 75.0.3770.80
2019-06-12 20:16:21 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_75.0.3770
2019-06-12 20:16:21 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2019-06-12 20:16:21 DEBUG Webdrivers Latest version available: 75.0.3770.8
2019-06-12 20:16:21 DEBUG Webdrivers chromedriver URL: https://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_linux64.zip
2019-06-12 20:16:21 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/75.0.3770.8/chromedriver_linux64.zip
2019-06-12 20:16:21 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2019-06-12 20:16:21 DEBUG Webdrivers Successfully downloaded /tmp/20190612-7728-42bkkfchromedriver_linux64.zip
2019-06-12 20:16:21 DEBUG Webdrivers Decompressing /tmp/20190612-7728-42bkkfchromedriver_linux64.zip
2019-06-12 20:16:21 DEBUG Webdrivers Deleting /app/.webdrivers/chromedriver
2019-06-12 20:16:21 DEBUG Webdrivers Completed download and processing of /app/.webdrivers/chromedriver
2019-06-12 20:16:22 DEBUG Webdrivers Checking current version
2019-06-12 20:16:22 DEBUG Webdrivers /app/.webdrivers/chromedriver is already downloaded
2019-06-12 20:16:22 DEBUG Webdrivers making System call: /app/.webdrivers/chromedriver --version
2019-06-12 20:16:22 DEBUG Webdrivers Current version of /app/.webdrivers/chromedriver is ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40})
2019-06-12 20:16:22 DEBUG Webdrivers A working webdriver version is already on the system
2019-06-12 20:16:22 DEBUG Webdrivers Checking current version
2019-06-12 20:16:22 DEBUG Webdrivers /app/.webdrivers/chromedriver is already downloaded
2019-06-12 20:16:22 DEBUG Webdrivers making System call: /app/.webdrivers/chromedriver --version
2019-06-12 20:16:22 DEBUG Webdrivers Current version of /app/.webdrivers/chromedriver is ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40})
2019-06-12 20:16:22 DEBUG Webdrivers A working webdriver version is already on the system
The error
Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /app/.apt/opt/google/chrome/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
test/system/my/profile_test.rb:19:in `block in <class:ProfileTest>'
Hi @PaulineTW, I don't remember how I solved this in the past, but I can try to help you ๐
What about adding
Capybara.default_driver = :selenium_chrome_headless
in the top of your file?Also, make sure the
capybara
andwebdrivers
gems are updated ๐