Skip to content

Commit

Permalink
Fix performance logs issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Aug 8, 2024
1 parent e3412a2 commit f7fd245
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@
line_number = scenario.location.line.to_s

# Network logs
if page.driver.browser.respond_to?(:manage)
if page.driver.browser.respond_to?(:logs)
# performance logs may fail if this logging type is not configured or not supported by driver
if page.driver.browser.manage.logs.available_types.include? :performance
logs = page.driver.browser.manage.logs.get(:performance)
array = logs.each_with_object([]) do |entry, messages|
logs = page.driver.browser.logs

if logs.available_types.include? :performance
perf_logs = logs.get(:performance)
array = perf_logs.each_with_object([]) do |entry, messages|
message = JSON.parse(entry.message)
# next unless message.dig('message', 'params', 'documentURL').to_s.end_with? '/p/login'
messages << message
Expand All @@ -139,11 +141,11 @@

console_log = folder.join("#{line_number}.log")

if (logs = page.driver.browser.manage.logs.get(:browser)).present?
entries = logs.map{ |entry| "[#{entry.level}] #{entry.message}" }
if (browser_logs = logs.get(:browser)).present?
entries = browser_logs.map { |entry| "[#{entry.level}] #{entry.message}" }

console_log.open('w') do |f|
f.puts *entries
f.puts(*entries)
end

print "Saved console log to #{console_log}\n"
Expand Down

0 comments on commit f7fd245

Please sign in to comment.