Get chromes console log via Ruby WebDriver
Apologies for late response.
I originally achieved it by adding the following to Webdriver;
module Selenium
module WebDriver
class Options
#
# Returns the available logs for this webDriver instance
#
def available_log_types
@bridge.getAvailableLogTypes
end
#
# Returns the requested log
#
# @param type [String] The required log type
#
# @return [Array] An array of log entries
#
def get_log(type)
@bridge.getLog(type)
end
end
end
end
When "required" this resulted in the following being supported;
driver.manage.get_log(:browser)
However, Version 2.38 of the selenium ruby gem exposes the logging API (although experimental).
http://selenium.googlecode.com/git/rb/CHANGES
https://code.google.com/p/selenium/wiki/Logging
Therefore, from 2.38 onwards the following should work WITHOUT the above extension;
driver.manage.logs.get :browser
Check browser console output on Ruby
Version 2.38 of the selenium ruby gem exposes the logging API.
http://selenium.googlecode.com/git/rb/CHANGES
This allows you to access the chrome console logs.
https://code.google.com/p/selenium/wiki/Logging
Here is an example in Java but you should be able to translate easily to ruby;
java example
Enable/view console.log messages in headless Chrome
When Chrome changed to w3c mode by default (v75) it changed loggingPrefs
to goog:loggingPrefs
to be spec compliant. Try setting goog:loggingPrefs
instead.
Cromedriver `driver.manage.logs.get(:browser)` fails on chromedriver 75.0.3770.8
Capybara 3.24 now works around this issue when used with chromedriver >= 75.0.3770.90
Related Topics
What Does +@ Mean as a Method in Ruby
Ruby: Method Inexplicably Overwritten and Set to Nil
Is Regexp.Last_Match Thread Safe
Which Equality Test Does Ruby's Hash Use When Comparing Keys
Symbol#To_Proc with Custom Methods
Wrapping Text into Lines at Word Boundaries
Why Ruby Inject Method Cannot Sum Up String Lengths Without Initial Value
Sorting an Array in Ruby Without Using Sort Method
How to Force a Cucumber Scenario to Fail
How to Make Like Clause Case-Insensitive
Ruby: Array Contained in Array, Any Order
How to Install Rails with Jruby
How to Extract a Single Character (As a String) from a Larger String in Ruby
How to Access the Current Node from a Library in a Chef Cookbook
Rails Routes: Wrong Singular for Resources
How to Decode a Cookie from the Header of a Websocket Connection Handshake? (Ruby)