percy / percy-capybara

Visual testing for Capybara with Percy.
https://docs.percy.io/docs/capybara
MIT License
45 stars 23 forks source link

Disabling JS Errors from erroring tests #53

Closed JamesIves closed 6 years ago

JamesIves commented 6 years ago

Running into this error when running Percy Anywhere:

home/circleci/project/vendor/cache/ruby/2.3.0/gems/poltergeist-1.17.0/lib/capybara/poltergeist/browser.rb:384:in `command': One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details). (Capybara::Poltergeist::JavascriptError)

ReferenceError: Can't find variable: Intl
ReferenceError: Can't find variable: Intl
    at http://localhost/visual-regression/?_website=:83 in global code
ReferenceError: Can't find variable: Promise
ReferenceError: Can't find variable: Promise
    at http://localhost/pb/resources/scripts/arcads.js?_=1bda7:1 in initializeBiddingServices
    at http://localhost/pb/resources/scripts/arcads.js?_=1bda7:1 in e
    from /home/circleci/project/vendor/cache/ruby/2.3.0/gems/poltergeist-1.17.0/lib/capybara/poltergeist/browser.rb:39:in `visit'
    from /home/circleci/project/vendor/cache/ruby/2.3.0/gems/poltergeist-1.17.0/lib/capybara/poltergeist/driver.rb:99:in `visit'
    from /home/circleci/project/vendor/cache/ruby/2.3.0/gems/capybara-2.18.0/lib/capybara/session.rb:274:in `visit'
    from snapshots.rb:17:in `block in <main>'
    from /home/circleci/project/vendor/cache/ruby/2.3.0/gems/percy-capybara-3.1.2/lib/percy/capybara/anywhere.rb:28:in `run'
    from snapshots.rb:15:in `<main>'
Exited with code 1

I believe this is being triggered by some JavaScript errors that are on the page when Percy is run from a couple of vendor integrations that don't impact the page layout. I see that in the error log there's a way to turn off these errors using js_errors: false but I can't seem to figure out how to actually turn them off.

Here's my attempt:

Percy::Capybara::Anywhere.run(server, assets_dir, assets_base_url) do |page|
  page.visit('/visual-regression/?_website=')
  Percy::Capybara.snapshot(page, name: 'Kitchen Sink', js_errors: false)

end
faun commented 6 years ago

Thanks for filing this issue.

The problem here appears to be that you’re trying to pass configuration settings to Poltergeist when creating a snapshot. You must configure Poltergeist directly to ignore JavaScript errors. See this example on Stack Overflow for more information.