I want to fetch browser(Chrome) console errors in my test reports. I am using Selenium with Ruby and for reports, I have used Report Builder. I want to get the reports in json format
Asked
Active
Viewed 577 times
1 Answers
1
The below code will log the console messages from the browser, you can save that in a file.
require 'watir-webdriver'
def test
Selenium::WebDriver::Chrome.driver_path= File.expand_path("C:\\chromedriver.exe")
@browser = Watir::Browser.new:chrome
@browser.window.maximize
@browser.goto("http://3qilabs.com/how_to/check-for-javascript-errors-on-a-page-with-ruby-and-selenium-webdriver/")
arr2 = @browser.driver.manage.logs
puts arr2.get(:browser)
end
test()
Update:
As suggested in the comments, using the watir
gem:
require 'watir'
b = Watir::Browser.new
b.goto "https://nytimes.com"
b.driver.manage.logs.get(:browser).each do |log|
puts log
end

I.Manev
- 709
- 7
- 23
-
1is correct, but I would tidy up the code: https://gist.github.com/samnissen/730be7b78fb9f3b4e2080a0515f60690 Most importantly, note the gem is called `watir` now. – Sam Jun 09 '18 at 05:45
-
hi, I need some modifications in the code. instead of just printing the error I want to display the test as fail. do you have any suggestions? – Netra Jun 12 '18 at 10:43