diff --git a/.travis.yml b/.travis.yml index 15205d73..2a9167e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: - ruby rvm: - 2.4.1 -sudo: false +sudo: true notifications: slack: shakacode:YvfXbuFMcFAHt6ZjABIs0KET addons: @@ -17,18 +17,20 @@ env: global: - RAILS_ENV=test - CXX=g++-4.9 -before_install: - - mkdir $PWD/travis-phantomjs - - curl -sSL https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2 -o $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 - - tar -xvf $PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis-phantomjs - - export PATH=$PWD/travis-phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH install: - bundle install - chromedriver-update + - wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add - + - sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' + - sudo apt-get update + - sudo apt-get install google-chrome-stable - nvm install stable && nvm alias default stable - - npm install -g npm@5.3.x + - npm install -g npm@5.6.x - npm install -g yarn + - node --version - npm --version + - google-chrome --version + - chromedriver --version - yarn install - rake db:setup diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index b1683793..cbbf405a 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -7,7 +7,6 @@ require "rspec/rails" require "capybara/rspec" -require "capybara/poltergeist" require "capybara-screenshot/rspec" require "database_cleaner" @@ -51,9 +50,7 @@ default_driver = :selenium_chrome - supported_drivers = %i[ poltergeist poltergeist_errors_ok - poltergeist_no_animations webkit - selenium_chrome selenium_firefox selenium] + supported_drivers = %i[selenium_chrome selenium_firefox selenium] driver = ENV["DRIVER"].try(:to_sym) || default_driver Capybara.default_driver = driver @@ -62,39 +59,6 @@ end case driver - when :poltergeist, :poltergeist_errors_ok, :poltergeist_no_animations - basic_opts = { - window_size: [1300, 1800], - screen_size: [1400, 1900], - phantomjs_options: ["--load-images=no", "--ignore-ssl-errors=true"], - timeout: 180 - } - - Capybara.register_driver :poltergeist do |app| - Capybara::Poltergeist::Driver.new(app, basic_opts) - end - - no_animation_opts = basic_opts.merge( # Leaving animations off, as a sleep was still needed. - extensions: ["#{Rails.root}/spec/support/phantomjs-disable-animations.js"] - ) - - Capybara.register_driver :poltergeist_no_animations do |app| - Capybara::Poltergeist::Driver.new(app, no_animation_opts) - end - - Capybara.register_driver :poltergeist_errors_ok do |app| - Capybara::Poltergeist::Driver.new(app, no_animation_opts.merge(js_errors: false)) - end - Capybara::Screenshot.register_driver(:poltergeist) do |js_driver, path| - js_driver.browser.save_screenshot(path) - end - Capybara::Screenshot.register_driver(:poltergeist_no_animations) do |js_driver, path| - js_driver.render(path, full: true) - end - Capybara::Screenshot.register_driver(:poltergeist_errors_ok) do |js_driver, path| - js_driver.render(path, full: true) - end - when :selenium_chrome DriverRegistration.register_selenium_chrome when :selenium_firefox, :selenium diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0a8eeb90..eea9c198 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,7 +40,7 @@ # Show retry status in spec process config.verbose_retry = true # Try twice (retry once) - config.default_retry_count = 4 + config.default_retry_count = 2 # Only retry when Selenium raises Net::ReadTimeout # config.exceptions_to_retry = [Net::ReadTimeout] end diff --git a/spec/support/poltergeist.rb b/spec/support/poltergeist.rb deleted file mode 100644 index d138d1a0..00000000 --- a/spec/support/poltergeist.rb +++ /dev/null @@ -1,92 +0,0 @@ -# This file supports 2 strategies: -# 1. switch_to_selenium: switch drivers -# 2. restart_poltergeist - -RESTART_PHANTOMJS = ENV["RESTART_PHANTOMJS"] && - %w[TRUE YES].include?(ENV["RESTART_PHANTOMJS"].upcase) -puts "RESTART_PHANTOMJS = #{RESTART_PHANTOMJS}" - -CAPYBARA_TIMEOUT_RETRIES = 5 - -# HACK: workaround for Capybara Poltergeist StatusFailErrors, simply retries -# based on https://gist.github.com/afn/c04ccfe71d648763b306 -RSpec.configure do |config| - config.around(:each, type: :feature) do |ex| - example = RSpec.current_example - use_selenium = false - original_driver = Capybara.default_driver - CAPYBARA_TIMEOUT_RETRIES.times do - example.instance_variable_set("@exception", nil) - - # Private method in rspec: - # rspec-core-3.5.4/lib/rspec/core/memoized_helpers.rb:139 - __init_memoized - - if use_selenium - puts "Switching to selenium from #{Capybara.current_driver}" - Capybara.current_driver = js_selenium_driver - Capybara.javascript_driver = js_selenium_driver - end - - ex.run - - example_ex = example.exception - - break unless example_ex - - is_multiple_exception = example_ex.is_a?(RSpec::Core::MultipleExceptionError) - - break unless example_ex.is_a?(Capybara::Poltergeist::StatusFailError) || - example_ex.is_a?(Capybara::Poltergeist::DeadClient) || - is_multiple_exception - - if is_multiple_exception - m_exceptions = example_ex.all_exceptions - - idx = m_exceptions.find_index do |exception| - exception.is_a?(Capybara::Poltergeist::StatusFailError) || - exception.is_a?(Capybara::Poltergeist::DeadClient) || - exception.class < SystemCallError - end - - break unless idx - end - - puts "\n" - puts "=" * 80 - puts "Exception caught! #{example_ex}" - puts example_ex.message - puts "when running example:\n #{example.full_description}" - puts " at #{example.location} with driver #{Capybara.current_driver}." - - if RESTART_PHANTOMJS - PhantomJSRestart.call - else - use_selenium = true - end - puts "=" * 80 - end - Capybara.current_driver = original_driver - Capybara.javascript_driver = original_driver - Capybara.use_default_driver - end -end - -# Rather than using switching to use selenium, we could have restarted Phantomjs -module PhantomJSRestart - def self.call - puts "Restarting phantomjs: iterating through capybara sessions..." - session_pool = Capybara.send("session_pool") - session_pool.each do |mode, session| - msg = " => #{mode} -- " - driver = session.driver - if driver.is_a?(Capybara::Poltergeist::Driver) - msg += "restarting" - driver.restart - else - msg += "not poltergeist: #{driver.class}" - end - puts msg - end - end -end