Capybara Selenium Headless Chrome config for CI/CD
Default Capybara Selenium headless Chrome has high chance of not working properly on CI/CD. The following config works on Bitbucket Pipelines
Capybara.register_driver :custom_chrome_headless do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.read_timeout = 120
Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new.tap do |opts|
opts.args << '--headless'
opts.args << '--disable-gpu'
# Workaround https://bugs.chromium.org/p/chromedriver/issues/detail?id=2650&q=load&sort=-id&colspec=ID%20Status%20Pri%20Owner%20Summary
opts.args << '--disable-site-isolation-trials'
opts.args << '--no-sandbox'
opts.args << '--disable-dev-shm-usage'
# opts.args << '--disable-setuid-sandbox'
opts.args << 'window-size=1200,1100'
end
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, http_client: client)
end
Capybara.default_driver = :custom_chrome_headless