如何获取“ console.log”从硒(使用Chrome)在Rails日志文件中? [英] How to get "console.log" from Selenium (with Chrome) in the Rails log files?

查看:68
本文介绍了如何获取“ console.log”从硒(使用Chrome)在Rails日志文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails项目中,我与Capybara一起使用Cucumber,以便通过Selenium在Chrome网络浏览器中运行测试。

In Rails project, I'm using Cucumber, with Capybara, in order to run my tests in a Chrome web browser through Selenium.

我的测试运行良好但我想在Rails的日志文件中获取 console.log console.error

My tests are running fine but I would like to get the console.log, console.error and so on in the log files of my Rails application.

我已经注册了一个:chrome 水豚驱动程序(基于不同的文章和答案):

I have registered a :chrome capybara driver like this (based on different articles and SO answers):

Capybara.register_driver :chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: {
      args: chrome_switches,
    },
    loggingPrefs: {
      browser: 'ALL',
      client: 'ALL',
      driver: 'ALL',
      server: 'ALL'
    }
  )
  Capybara::Selenium::Driver.new(
    app,
    browser: :remote,
    url: "http://selenium:#{ENV['SELENIUM_PORT']}/wd/hub",
    desired_capabilities: capabilities
  )
end

我的Chrome文件中没有任何日志文件。

But I have nothing, from the Chrome browser, in the log files.

如何从Rails日志文件中的Selenium(带有Chrome)中获取 console.log? / p>

How to get "console.log" from Selenium (with Chrome) in the Rails log files?

推荐答案

日志不会自动显示,您需要从Selenium请求它们,然后添加然后将其写到任何内容记录你喜欢的。要请求日志,您需要执行以下操作

The logs don't show up automatically, you would need to request them from Selenium and then add then write them out to whatever log you like. To request the logs you need to do something like

page.driver.browser.manage.logs.get(:browser) # :driver, etc.

通常,您会在后续步骤中执行类似的操作,然后编写到您要放入的日志文件。

Generally you'd do something like that in an after step and then write it to the log file you want it to be in.

这篇关于如何获取“ console.log”从硒(使用Chrome)在Rails日志文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆