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

五迷三道 提交于 2020-07-31 04:53:11

问题


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

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.

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

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/49297129/how-to-get-console-log-from-selenium-with-chrome-in-the-rails-log-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!