diff --git a/.travis.yml b/.travis.yml index c677239be7617..9adfdf00229a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_install: - nvm install install: - bundle install --path vendor/bundle - - bundle exec chromedriver-update + - bundle exec rails runner bin/chromedriver-update - yarn install - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter diff --git a/Gemfile b/Gemfile index cdc0831f6ef6e..fd2ee1c386560 100644 --- a/Gemfile +++ b/Gemfile @@ -133,14 +133,12 @@ end group :test do gem "approvals", "~> 0.0" # A library to make it easier to do golden-master style testing in Ruby - gem "chromedriver-helper", "~> 2.1" # Easy installation and use of chromedriver, the Chromium project's Selenium webdriver adapter gem "factory_bot_rails", "~> 4.11" # factory_bot is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies gem "fake_stripe", "~> 0.2" # An implementation of the Stripe credit card processing service to run during your integration tests gem "launchy", "~> 2.4" # Launchy is helper class for launching cross-platform applications in a fire and forget manner. gem "pundit-matchers", "~> 1.6" # A set of RSpec matchers for testing Pundit authorisation policies gem "rspec-retry", "~> 0.6" # retry intermittently failing rspec examples gem "ruby-prof", "~> 0.17", require: false # ruby-prof is a fast code profiler for Ruby - gem "selenium-webdriver", "~> 3.141" # WebDriver is a tool for writing automated tests of websites gem "shoulda-matchers", "4.0.1", require: false # Simple one-liner tests for common Rails functionality gem "simplecov", "~> 0.16", require: false # Code coverage with a powerful configuration library and automatic merging of coverage across test suites gem "stackprof", "~> 0.2", require: false, platforms: :ruby # stackprof is a fast sampling profiler for ruby code, with cpu, wallclock and object allocation samplers @@ -148,6 +146,7 @@ group :test do gem "test-prof", "~> 0.7" # Ruby Tests Profiling Toolbox gem "timecop", "~> 0.9" # A gem providing "time travel" and "time freezing" capabilities, making it dead simple to test time-dependent code gem "vcr", "~> 4.0" # Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests + gem "webdrivers", "~> 3.7" # Run Selenium tests more easily with install and updates for all supported webdrivers gem "webmock", "~> 3.5" # WebMock allows stubbing HTTP requests and setting expectations on HTTP requests gem "zonebie", "~> 0.6.1" # Runs your tests in a random timezone end diff --git a/Gemfile.lock b/Gemfile.lock index 21f2a66543d99..6255305a79089 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,8 +111,6 @@ GEM approvals (0.0.24) nokogiri (~> 1.6) thor (~> 0.18) - archive-zip (0.11.0) - io-like (~> 0.3.0) arel (9.0.0) ast (2.4.0) autoprefixer-rails (9.5.1) @@ -191,9 +189,6 @@ GEM activesupport (>= 3) childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) - chromedriver-helper (2.1.0) - archive-zip (~> 0.10) - nokogiri (~> 1.8) cld (0.8.0) ffi cloudinary (1.11.1) @@ -562,7 +557,6 @@ GEM inline_svg (1.3.1) activesupport (>= 3.0) nokogiri (>= 1.6) - io-like (0.3.0) ipaddress (0.8.3) jaro_winkler (1.5.2) jbuilder (2.8.0) @@ -630,6 +624,7 @@ GEM nenv (0.3.0) net-http-persistent (3.0.0) connection_pool (~> 2.2) + net_http_ssl_fix (0.0.10) netrc (0.11.0) nio4r (2.3.1) nokogiri (1.10.2) @@ -939,6 +934,11 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) + webdrivers (3.7.2) + net_http_ssl_fix + nokogiri (~> 1.6) + rubyzip (~> 1.0) + selenium-webdriver (~> 3.0) webmock (3.5.1) addressable (>= 2.3.6) crack (>= 0.3.2) @@ -987,7 +987,6 @@ DEPENDENCIES capybara (~> 3.13) carrierwave (~> 1.3) carrierwave-bombshelter (~> 0.2) - chromedriver-helper (~> 2.1) cld (~> 0.8) cloudinary (~> 1.11) counter_culture (~> 2.1) @@ -1066,7 +1065,6 @@ DEPENDENCIES sass-rails (~> 5.0) scout_apm (~> 2.4) sdoc (~> 1.0) - selenium-webdriver (~> 3.141) serviceworker-rails (~> 0.5) shoulda-matchers (= 4.0.1) simplecov (~> 0.16) @@ -1090,6 +1088,7 @@ DEPENDENCIES validate_url (~> 1.0) vcr (~> 4.0) web-console (~> 3.7) + webdrivers (~> 3.7) webmock (~> 3.5) webpacker (~> 3.5) webpush (~> 0.3) diff --git a/bin/chromedriver-update b/bin/chromedriver-update new file mode 100755 index 0000000000000..8f1cf7dc5462d --- /dev/null +++ b/bin/chromedriver-update @@ -0,0 +1,11 @@ +#!/usr/bin/env ./bin/rails runner + +# webdrivers 3.7.2 doesn't provide a standalone update script, so we made one + +if Rails.env.test? + # allow browser websites, so that "webdrivers" can access their binaries + # see + WebMock.disable_net_connect!(allow: ["https://chromedriver.storage.googleapis.com"]) + + Webdrivers::Chromedriver.update +end diff --git a/docs/testing.md b/docs/testing.md index e447f6bef3db1..0e54dd933eb87 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -4,7 +4,7 @@ We use the following testing tools: - [**RSpec**](http://rspec.info/) for testing the backend - [**Capybara**](https://github.com/teamcapybara/capybara) with [**selenium-webdriver**](https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver) for view testing -- [**chromedriver-helper**](https://github.com/flavorjones/chromedriver-helper) for standard JS testing +- [**webdrivers**](https://github.com/titusfortner/webdrivers) for standard JS testing - [**guard-rspec**](https://github.com/guard/guard-rspec) for automated testing - [**Jest**](https://facebook.github.io/jest) for testing in the front-end - [**preact-render-spy**](https://github.com/mzgoddard/preact-render-spy) for testing Preact components. diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a57097615372f..7f188d35417c5 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -36,7 +36,26 @@ ActiveRecord::Migration.maintain_test_schema! # Disable internet connection with Webmock -WebMock.disable_net_connect!(allow_localhost: true) +# allow browser websites, so that "webdrivers" can access their binaries +# see +allowed_sites = [ + "https://chromedriver.storage.googleapis.com", + "https://github.com/mozilla/geckodriver/releases", + "https://selenium-release.storage.googleapis.com", + "https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver", +] +WebMock.disable_net_connect!(allow_localhost: true, allow: allowed_sites) + +# tell VCR to ignore browsers download sites +# see +VCR.configure do |config| + config.ignore_hosts( + "chromedriver.storage.googleapis.com", + "github.com/mozilla/geckodriver/releases", + "selenium-release.storage.googleapis.com", + "developer.microsoft.com/en-us/microsoft-edge/tools/webdriver", + ) +end RSpec.configure do |config| config.use_transactional_fixtures = true diff --git a/spec/support/initializers/capybara.rb b/spec/support/initializers/capybara.rb index 4bd1fbe9d4958..a690b2efe3a12 100644 --- a/spec/support/initializers/capybara.rb +++ b/spec/support/initializers/capybara.rb @@ -1,15 +1,13 @@ require "capybara/rails" require "capybara/rspec" -require "selenium/webdriver" Capybara.default_max_wait_time = 5 Capybara.register_driver :headless_chrome do |app| - Capybara::Selenium::Driver.new app, - browser: :chrome, - desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome( - chromeOptions: { args: %w[headless disable-gpu no-sandbox window-size=1400,2000] }, - ) + capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( + chromeOptions: { args: %w[headless disable-gpu no-sandbox window-size=1400,2000] }, + ) + Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities) end RSpec.configure do |config|