0 votes
1 view
in DevOps and Agile by (19.8k 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 (63.4k 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")




Welcome to Intellipaat Community. Get your technical queries answered by top developers !