From 5d383454783ad1332b71ea36cc5768c3fdd47e42 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 24 Oct 2022 21:10:22 +0200 Subject: [PATCH] feat(system-spec): display js console error --- Gemfile | 1 + Gemfile.lock | 3 +++ README.md | 4 ++++ spec/support/capybara.rb | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/Gemfile b/Gemfile index b519e633a..ff6f05271 100644 --- a/Gemfile +++ b/Gemfile @@ -100,6 +100,7 @@ group :test do gem 'launchy' gem 'rails-controller-testing' gem 'rspec_junit_formatter' + gem 'selenium-devtools' gem 'selenium-webdriver' gem 'shoulda-matchers', require: false gem 'timecop' diff --git a/Gemfile.lock b/Gemfile.lock index 5f14aad5c..ef3ab8ebc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -660,6 +660,8 @@ GEM scss_lint (0.59.0) sass (~> 3.5, >= 3.5.5) selectize-rails (0.12.6) + selenium-devtools (0.106.0) + selenium-webdriver (~> 4.2) selenium-webdriver (4.5.0) childprocess (>= 0.5, < 5.0) rexml (~> 3.2, >= 3.2.5) @@ -905,6 +907,7 @@ DEPENDENCIES sanitize-url sassc-rails scss_lint + selenium-devtools selenium-webdriver sentry-delayed_job sentry-rails diff --git a/README.md b/README.md index 8bf38b514..4ccc423d5 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,10 @@ Pour exécuter les tests de l'application, plusieurs possibilités : NO_HEADLESS=1 bin/rspec spec/system +- Afficher les logs js en error issus de la console du navigateur `console.error('coucou')` + + JS_LOG=error 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 34dec9e8f..8bc563491 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -64,6 +64,12 @@ RSpec.configure do |config| config.before(:each, type: :system, js: true) do driven_by ENV['NO_HEADLESS'] ? :chrome : :headless_chrome + + if ENV['JS_LOG'].present? + page.driver.browser.on_log_event(:console) do |event| + puts event.args if event.type == ENV['JS_LOG'].downcase.to_sym + end + end end # Set the user preferred language before Javascript system specs.