Skip to content

Commit 80194ca

Browse files
committed
Fix Net::ReadTimeout error in selenium_logger.rb
- Add error handling around browser log access - Catch Net::ReadTimeout and Selenium::WebDriver::Error::WebDriverError - Display warning messages instead of crashing when browser connection is closed - Prevents test failures due to browser connection timeouts
1 parent 15e54aa commit 80194ca

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

spec/dummy/spec/support/selenium_logger.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111

1212
errors = []
1313

14-
page.driver.browser.logs.get(:browser).each do |entry|
15-
next if entry.message.include?("Download the React DevTools for a better development experience")
16-
17-
log_only_list.include?(entry.level) ? puts(entry.message) : errors << entry.message
14+
begin
15+
page.driver.browser.logs.get(:browser).each do |entry|
16+
next if entry.message.include?("Download the React DevTools for a better development experience")
17+
18+
log_only_list.include?(entry.level) ? puts(entry.message) : errors << entry.message
19+
end
20+
rescue Net::ReadTimeout, Selenium::WebDriver::Error::WebDriverError => e
21+
puts "Warning: Could not access browser logs: #{e.message}"
1822
end
1923

20-
page.driver.browser.logs.get(:driver).each do |entry|
21-
log_only_list.include?(entry.level) ? puts(entry.message) : errors << entry.message
24+
begin
25+
page.driver.browser.logs.get(:driver).each do |entry|
26+
log_only_list.include?(entry.level) ? puts(entry.message) : errors << entry.message
27+
end
28+
rescue Net::ReadTimeout, Selenium::WebDriver::Error::WebDriverError => e
29+
puts "Warning: Could not access driver logs: #{e.message}"
2230
end
2331

2432
# https://stackoverflow.com/questions/60114639/timed-out-receiving-message-from-renderer-0-100-log-messages-using-chromedriver

0 commit comments

Comments
 (0)