Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get chromes console log via Ruby WebDriver

This question has been previously answered in Java (Get chrome's console log)

However, I am using the Ruby bindings and was wondering if that provided similar functionality?

I have looked at the Ruby source code but cannot see any mention or reference to LoggingPreferences.

By the way, I am using RemoteWebDriver and passing in a desired capability object. Presumably I want to set the logging preferences in that object, but I am struggling to see where.

like image 661
Robbie Wareham Avatar asked Sep 17 '13 09:09

Robbie Wareham


1 Answers

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
like image 168
Robbie Wareham Avatar answered Sep 20 '22 07:09

Robbie Wareham