diff --git a/Gemfile b/Gemfile index 493e0c5..356401b 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ group :test do gem 'simplecov', :require => false gem 'selenium-webdriver' gem 'chromedriver-helper' if ENV['CI'] + gem 'capybara-screenshot' end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 783e12b..ab2485f 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -9,12 +9,28 @@ require 'rspec/rails' require 'capybara/rspec' +require 'capybara-screenshot/rspec' require 'spec_helper' -Capybara.javascript_driver = :selenium_chrome_headless +Capybara.javascript_driver = :chrome # :selenium_chrome_headless Capybara.server = :webrick +Capybara.register_driver :chrome do |app| + Capybara::Selenium::Driver.load_selenium + browser_options = ::Selenium::WebDriver::Chrome::Options.new + browser_options.args << '--headless' + browser_options.args << '--window-size=1366,768' + browser_options.args << '--disable-gpu' if Gem.win_platform? + Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options) +end + +Capybara::Screenshot.register_driver(:chrome) do |driver, path| + driver.browser.save_screenshot(path) +end +Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example| + "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}" +end # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories.