From 091a522cbfd77c7af454a9771d2b1998c8bba3b2 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 27 Oct 2022 22:23:25 +0200 Subject: [PATCH] conf(capybara): add MAKE_IT_SLOW option to reveal bugs --- README.md | 4 ++++ spec/support/capybara.rb | 26 ++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4ccc423d5..a78769236 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,10 @@ Pour exécuter les tests de l'application, plusieurs possibilités : JS_LOG=error bin/rspec spec/system +- Augmenter la latence lors de tests end2end pour déceler des bugs récalcitrants + + MAKE_IT_SLOW=1 bin/rspec spec/system + ### Ajout de taches à exécuter au déploiement rails generate after_party:task task_name diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 66ef268f7..3fcaf9368 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -3,6 +3,22 @@ require 'capybara-screenshot/rspec' require 'capybara/email/rspec' require 'selenium/webdriver' +def setup_driver(app, download_path, options) + Capybara::Selenium::Driver.new(app, browser: :chrome, options:).tap do |driver| + # Set download dir for Chrome < 77 + driver.browser.download_path = download_path + + if ENV['MAKE_IT_SLOW'].present? + driver.browser.network_conditions = { + offline: false, + latency: 800, + download_throughput: 1024000, + upload_throughput: 1024000 + } + end + end +end + Capybara.register_driver :chrome do |app| options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--no-sandbox') unless ENV['SANDBOX'] @@ -15,10 +31,7 @@ Capybara.register_driver :chrome do |app| options.add_preference('download.default_directory', download_path) options.add_preference(:download, default_directory: download_path) - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options).tap do |driver| - # Set download dir for Chrome < 77 - driver.browser.download_path = download_path - end + setup_driver(app, download_path, options) end Capybara.register_driver :headless_chrome do |app| @@ -36,10 +49,7 @@ Capybara.register_driver :headless_chrome do |app| options.add_preference('download.default_directory', download_path) options.add_preference(:download, default_directory: download_path) - Capybara::Selenium::Driver.new(app, browser: :chrome, options: options).tap do |driver| - # Set download dir for Chrome < 77 - driver.browser.download_path = download_path - end + setup_driver(app, download_path, options) end Capybara.default_max_wait_time = 2