How to get information about JS errors in rspec?

Viewed 319

A specific test in my Rails app is failing on CircleCI.

This test expects an input to exist. The input/ form is rendered by React.

Screenshots from the failing test look like the React component is simply not rendering, perhaps a JS error. But I'm having difficulty identifying the cause.

In my local dev environment the form renders correctly.

In my local test environment the test passes.

If I make a remote browser connection to the CI build, the form renders correctly.

I've tried to inspect the CI headless chrome browser console logs, but recent Chrome updates seem to cause this error:

page.driver.browser.manage.logs.get(:browser)
Selenium::WebDriver::Error::WebDriverError:
  unexpected response, code=404, content-type="text/plain"
  unknown command: session/1595d6324fa6ae6bdc1ed885ba8c9ebf/se/log

Does anyone have a good idea how I can investigate this issue further? Is there an easier way to get hold of the browser console logs from this specific test?

2 Answers

Try something like this

config.after(:each, type: :system, js: true) do
  errors = page.driver.browser.manage.logs.get(:browser)
  if errors.present?
    aggregate_failures 'javascript errrors' do
      errors.each do |error|
        expect(error.level).not_to eq('SEVERE'), error.message
        next unless error.level == 'WARNING'
        STDERR.puts 'WARN: javascript warning'
        STDERR.puts error.message
      end
    end
  end
end

This issue caused me many headaches for a long time. Turns out to be an easy fix, and a big part of the problem was that I'd made assumptions I should have checked.

Local I was running the latest versions of Chrome and ChromeDriver.

I thought I was running the same on my CI builds. Turns out the docker image I am using did not use the latest version of Chrome as I expected, even when manually configured to download ChromeDriver.

I updated the image to a more recent ruby version, and the problem went away.

Related