问题
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