# Setup chrome headless driver
Capybara.server = :puma, { Silent: true }

Capybara.register_driver :chrome_headless do |app|
  options = ::Selenium::WebDriver::Chrome::Options.new

  options.add_argument('--headless')
  options.add_argument('--no-sandbox')
  options.add_argument('--disable-dev-shm-usage')
  options.add_argument('--window-size=1400,1400')

  Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end

Capybara.javascript_driver = :chrome_headless

# Max wait time for a match to be found by capybara selectors
Capybara.default_max_wait_time = 15

# Remove whitespaces characters (\n, etc...) from "page" variable
Capybara.default_normalize_ws = true

# Setup rspec
RSpec.configure do |config|
  config.before(:each, type: :system) do
    driven_by :rack_test
  end

  config.before(:each, type: :system, js: true) do
    driven_by :chrome_headless
  end

  # Retry failed tests up to 3 times
  config.around(:each, type: :system) do |example|
    example.run_with_retry retry: 3
  end
end