I have a Rails 5.2.3 app running headless Chrome test using Capybara, Selenium, and chromedriver. My tests run just fine, but I can't seem to enable or view any messages output to console.log. Here is my setup:
Gemfile
ruby '2.6.5'
gem 'rails', '~> 5.2.3'
group :test do
  gem 'rspec-rails'
  gem 'capybara'
  gem 'selenium-webdriver'
  gem 'webdrivers'
end
spec_helper.rb
Capybara.register_driver :headless_chrome do |app|
  caps = Selenium::WebDriver::Remote::Capabilities.chrome loggingPrefs: {
    browser: 'ALL', client: 'ALL', driver: 'ALL', server: 'ALL'
  }
  opts = Selenium::WebDriver::Chrome::Options.new
  chrome_args = %w(--headless --window-size=1920,1080 --no-sandbox --disable-dev-shm-usage --enable-logging)
  chrome_args.each {|a| opts.add_argument a}
  Capybara::Selenium::Driver.new app, browser: :chrome, options: opts, desired_capabilities: caps
end
Then inside any of my tests, if I try to inspect the logs (and I know I am triggering console.log messages in my code that is run), I don't see anything:
page.driver.browser.manage.logs.get(:browser) # => []
So, what am I doing incorrectly? I assume I'm missing some configuration/logging setting when setting up the :headless_chrome driver, but what is it? Any help would be greatly appreciated.
When Chrome changed to w3c mode by default (v75) it changed loggingPrefs to goog:loggingPrefs to be spec compliant. Try setting goog:loggingPrefs instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With