Skip to content

Commit

Permalink
Configure Capybara to use rack_test driver by default in system specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitemaeric committed Dec 22, 2023
1 parent 9f6cac1 commit a485bee
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'capybara/rspec'

# Use different Capybara ports when running tests in parallel
if ENV['TEST_ENV_NUMBER']
Capybara.server_port = 9887 + ENV['TEST_ENV_NUMBER'].to_i
end

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

options.add_argument('--headless') unless ENV['HEADLESS'] == 'false'
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument('--window-size=1400,1400')

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

Capybara.javascript_driver = :chrome_headless

RSpec.configure do |config|
config.before(:each, type: :system) do
if self.class.metadata[:js] == true
driven_by(:chrome_headless)
else
driven_by(:rack_test)
end
end
end

0 comments on commit a485bee

Please sign in to comment.