Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

When I run RSpec, is it possible to have capybara/selenium report any javascript console.errors and other exceptions back to RSpec?

I have a whole bunch of tests failing, but my application is working when I manually test it. Without knowing the javascript errors that are likely blocking my single-page web app only during testing, it's really hard to figure out why the tests are failing.

I've looked around and haven't really been able to find a solution to this.

1 Answer

0 votes
by (62.9k points)
edited by

I am currently working with Selenium and using headless Chrome (The below code should also work with Firefox). The solution would be to add the following to spec/rails_helper.rb, within the RSpec.configure do |config| block and all feature specs with js: true metadata will display JS errors.

class JavaScriptError< StandardError; end

RSpec.configure do |config|

  config.after(:each, type: :feature, js: true) do |spec|

    errors = page.driver.browser.manage.logs.get(:browser)

               .select {|e| e.level == "SEVERE" && e.message.present? }



    if errors.present?

      raise JavaScriptError, errors.join("\n\n")




Browse Categories