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.
This commit is contained in:
David Taylor 2022-12-28 10:47:57 +00:00 committed by GitHub
parent d24dfe8f96
commit d4d9d60a5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -57,7 +57,8 @@ module TurboTests
shared_group_inclusion_backtrace: shared_group_inclusion_backtrace:
example example
.metadata[:shared_group_inclusion_backtrace] .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 location_rerun_argument: example.location_rerun_argument
} }

View File

@ -379,14 +379,17 @@ RSpec.configure do |config|
end end
config.after(:each, type: :system) do |example| 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, # This is disabled by default because it is super verbose,
# if you really need to dig into how selenium is communicating # if you really need to dig into how selenium is communicating
# for system tests then enable it. # for system tests then enable it.
if ENV["SELENIUM_VERBOSE_DRIVER_LOGS"] if ENV["SELENIUM_VERBOSE_DRIVER_LOGS"]
puts "~~~~~~ DRIVER LOGS: ~~~~~~~" lines << "~~~~~~~ DRIVER LOGS ~~~~~~~"
page.driver.browser.logs.get(:driver).each do |log| page.driver.browser.logs.get(:driver).each do |log|
puts log.message lines << log.message
end end
lines << "~~~~~ END DRIVER LOGS ~~~~~"
end end
# Recommended that this is not disabled, since it makes debugging # 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 ENV["SELENIUM_DISABLE_VERBOSE_JS_LOGS"].blank?
if example.exception if example.exception
skip_js_errors = false skip_js_errors = false
if example.exception.kind_of?(RSpec::Core::MultipleExceptionError) if example.exception.kind_of?(RSpec::Core::MultipleExceptionError)
puts "~~~~~~ SYSTEM TEST ERRORS: ~~~~~~~" lines << "~~~~~~~ SYSTEM TEST ERRORS ~~~~~~~"
example.exception.all_exceptions.each do |ex| example.exception.all_exceptions.each do |ex|
puts ex.message lines << ex.message
end end
lines << "~~~~~ END SYSTEM TEST ERRORS ~~~~~"
skip_js_errors = true skip_js_errors = true
end end
if !skip_js_errors if !skip_js_errors
puts "~~~~~~ JS ERRORS: ~~~~~~~" lines << "~~~~~~~ JS LOGS ~~~~~~~"
page.driver.browser.logs.get(:browser).each do |log| logs = page.driver.browser.logs.get(:browser)
puts log.message if logs.empty?
lines << "(no logs)"
else
logs.each do |log|
lines << log.message
end
end end
lines << "~~~~~ END JS LOGS ~~~~~"
end end
end end
end end