通过 Ruby WebDriver 获取 chromes 控制台日志 [英] Get chromes console log via Ruby WebDriver
问题描述
这个问题之前已经用 Java 回答过(获取 chrome 的控制台日志)
This question has been previously answered in Java (Get chrome's console log)
但是,我正在使用 Ruby 绑定,想知道它是否提供了类似的功能?
However, I am using the Ruby bindings and was wondering if that provided similar functionality?
我查看了 Ruby 源代码,但没有看到任何提及或引用 LoggingPreferences.
I have looked at the Ruby source code but cannot see any mention or reference to LoggingPreferences.
顺便说一句,我正在使用 RemoteWebDriver 并传入所需的功能对象.大概我想在该对象中设置日志记录首选项,但我很难看到在哪里.
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.
推荐答案
抱歉迟到了.
我最初是通过在Webdriver中添加以下内容来实现的;
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)
但是,selenium ruby gem 的 2.38 版公开了日志记录 API(尽管是实验性的).
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
因此,从 2.38 开始,以下内容应该可以在没有上述扩展的情况下工作;
Therefore, from 2.38 onwards the following should work WITHOUT the above extension;
driver.manage.logs.get :browser
这篇关于通过 Ruby WebDriver 获取 chromes 控制台日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!