diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 38f60402..8855eb76 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,8 +1,12 @@ +require "timeout" + require "selenium/webdriver" Capybara.register_driver :headless_chrome do |app| + # `--disable-dev-shm-usage` keeps Chrome off the small `/dev/shm` of CI + # runners and containers, where exhausting it crashes the renderer. options = Selenium::WebDriver::Chrome::Options.new( - args: %w[--no-sandbox --headless], + args: %w[--no-sandbox --headless --disable-dev-shm-usage], ) # Point Selenium at a specific Chrome binary, e.g. inside a container @@ -23,3 +27,11 @@ Capybara.server = :webrick Capybara.javascript_driver = :headless_chrome + +RSpec.configure do |config| + # A crashed browser can leave the driver waiting forever: fail the example + # with a backtrace instead of eating the job's runtime cap. + config.around(:each, :js) do |example| + Timeout.timeout(300) { example.run } + end +end