Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check browser console output on Ruby

How can I check a browser console for errors?

For example, I have raised browser(chrome of firefox) with Selenium and I have done some actions with Selenium WebDriver. After than I want to know is there any error in the web console.

like image 488
Maxim Banaev Avatar asked Jan 10 '14 11:01

Maxim Banaev


People also ask

How do I get my browser console output?

Google Chrome: In Google Chrome, the Console Logs are available as a part of Chrome Dev Tools. To open the dedicated Console panel, either: Press Ctrl + Shift + J (Windows / Linux) or Cmd + Opt + J (Mac).

Can you console log in rails?

One of the best tools in a rails developers arsenal is the rails console, being extremely useful for brainstorming, debugging, and testing. Having it log active record queries directly to the console can improve readability and convenience over looking through the development logs to see what SQL queries have been run.


1 Answers

I tried to take console error like:

def check_console_log
    console_log = @browser.driver.manage.get_log(:browser)
    if console_log != nil
      raise(console_log)
    end
end

and also log it to file

def write_log(file_path)
    work_log = @browser.driver.manage.get_log(:browser)
    messages = ""
    work_log.each { | item | messages += item.message + "\n"}
    File.write( "#{file_path}.log", messages ) unless messages == ""
end
like image 79
Kirikami Avatar answered Oct 02 '22 14:10

Kirikami