Dokcer環境などのCUI環境でcapybara/selenium/chromedriverを利用する際は no-sandbox/disable-dev-shm-usage
オプションが必要
Selenium::WebDriver::Error::UnknownError:
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.)
capybara.rb
...
Capybara.register_driver :selenium_chrome_headless do |app|
options = ::Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--no-sandbox') # chrootで隔離された環境(Sandbox)での動作を無効
options.add_argument('--disable-dev-shm-usage') # 共有メモリファイルの場所を/dev/shmから/tmpに移動
options.add_argument('--disable-gpu')
options.add_argument('--window-size=2500,2500')
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.javascript_driver = :selenium_chrome_headless