简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM