From d4d9d60a5f3befd108f0528a9305d8791ce751f0 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Wed, 28 Dec 2022 10:47:57 +0000 Subject: [PATCH] DEV: Print system test logs with other test metadata (#19637) Previously, browser logs would be printed to STDOUT halfway through the test run. This commit changes the behaviour so that the logs are included in the failure summary along with other rspec failure information. --- lib/turbo_tests/json_rows_formatter.rb | 3 ++- spec/rails_helper.rb | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/turbo_tests/json_rows_formatter.rb b/lib/turbo_tests/json_rows_formatter.rb index f6a424a63a9..1c2e78a0839 100644 --- a/lib/turbo_tests/json_rows_formatter.rb +++ b/lib/turbo_tests/json_rows_formatter.rb @@ -57,7 +57,8 @@ module TurboTests shared_group_inclusion_backtrace: example .metadata[:shared_group_inclusion_backtrace] - .map(&method(:stack_frame_to_json)) + .map(&method(:stack_frame_to_json)), + extra_failure_lines: example.metadata[:extra_failure_lines] }, location_rerun_argument: example.location_rerun_argument } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 10744cdfde1..5aa35a947bc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -379,14 +379,17 @@ RSpec.configure do |config| end config.after(:each, type: :system) do |example| + lines = RSpec.current_example.metadata[:extra_failure_lines] + # This is disabled by default because it is super verbose, # if you really need to dig into how selenium is communicating # for system tests then enable it. if ENV["SELENIUM_VERBOSE_DRIVER_LOGS"] - puts "~~~~~~ DRIVER LOGS: ~~~~~~~" + lines << "~~~~~~~ DRIVER LOGS ~~~~~~~" page.driver.browser.logs.get(:driver).each do |log| - puts log.message + lines << log.message end + lines << "~~~~~ END DRIVER LOGS ~~~~~" end # Recommended that this is not disabled, since it makes debugging @@ -394,20 +397,28 @@ RSpec.configure do |config| if ENV["SELENIUM_DISABLE_VERBOSE_JS_LOGS"].blank? if example.exception skip_js_errors = false + if example.exception.kind_of?(RSpec::Core::MultipleExceptionError) - puts "~~~~~~ SYSTEM TEST ERRORS: ~~~~~~~" + lines << "~~~~~~~ SYSTEM TEST ERRORS ~~~~~~~" example.exception.all_exceptions.each do |ex| - puts ex.message + lines << ex.message end + lines << "~~~~~ END SYSTEM TEST ERRORS ~~~~~" skip_js_errors = true end if !skip_js_errors - puts "~~~~~~ JS ERRORS: ~~~~~~~" - page.driver.browser.logs.get(:browser).each do |log| - puts log.message + lines << "~~~~~~~ JS LOGS ~~~~~~~" + logs = page.driver.browser.logs.get(:browser) + if logs.empty? + lines << "(no logs)" + else + logs.each do |log| + lines << log.message + end end + lines << "~~~~~ END JS LOGS ~~~~~" end end end