Get chromes console log via Ruby WebDriver

后端 未结 2 620
盖世英雄少女心
盖世英雄少女心 2020-12-16 03:55

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 fu

相关标签:
2条回答
  • 2020-12-16 04:11

    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
    
    0 讨论(0)
  • 2020-12-16 04:12

    You can use this code as well

    require 'selenium-webdriver'

    console_logs = @browser.driver.manage.logs.get(:browser) puts = console_logs

    ReportBuilder.build_report

    Use command -f json -o my_report_file.json to generate reports.

    0 讨论(0)
提交回复
热议问题