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:
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
}

View File

@ -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