Last active
January 11, 2021 15:10
-
-
Save s0kil/43c247893ea74d7a293018a498ad9a9d to your computer and use it in GitHub Desktop.
RSpec, Capybara JavaScript Driver (https://github.com/twalpole/apparition)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara/apparition' | |
Capybara.server = :puma, { Silent: true } | |
Capybara.register_driver :chrome_headless do |app| | |
Capybara::Apparition::Driver.new(app, { headless: true, browser_options: { 'headless': '', 'no-sandbox': '' } }) | |
end | |
Capybara.register_driver :chrome do |app| | |
options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox]) | |
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) | |
end | |
RSpec.configure do |config| | |
config.before(:all, type: :feature) do | |
Capybara.default_driver = :chrome | |
end | |
config.before(:all, type: :system) do | |
driven_by(:chrome_headless) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Create a
spec/support/drivers.rb
file with above contents, and then require it into yourspec/rails_helper.rb
file.See it in practice here https://github.com/danielsokil/nutrire/blob/develop/spec/rails_helper.rb
You will also need
gem 'capybara'
andgem 'apparition'
in yourGemfile