0

I am running into errors testing my Braintree sandbox payments using Rspec, Capybara, and Poltergeist in a feature test. I have it set up to do exactly what a human would do in development (entering payment info and clicking submit). It works fine in development. However, when I run my spec, I get a javascript error on the payment page when it loads:

 Capybara::Poltergeist::JavascriptError:
   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).

   [object Object]
   [object Object]
       at https://js.braintreegateway.com/js/braintree-2.24.0.js:9484 in fallbackError
 # /usr/local/bundle/gems/poltergeist-1.10.0/lib/capybara/poltergeist/browser.rb:365:in `command'
 # /usr/local/bundle/gems/poltergeist-1.10.0/lib/capybara/poltergeist/browser.rb:181:in `click'
 # /usr/local/bundle/gems/poltergeist-1.10.0/lib/capybara/poltergeist/node.rb:17:in `command'
 # /usr/local/bundle/gems/poltergeist-1.10.0/lib/capybara/poltergeist/node.rb:131:in `click'

Has anyone run into a similar issue or have any idea why Braintree's js might be throwing this error in testing (headless browser) when it works fine in development?

amclelland
  • 27
  • 4
  • Possible duplicate of [Poltergeist throws JS errors when js\_errors: false](http://stackoverflow.com/questions/25673890/poltergeist-throws-js-errors-when-js-errors-false) – fabdurso Mar 06 '17 at 09:51

1 Answers1

2

By looking at the line mentioned, braintree-2.24.0.js:9484, one can see that Braintree.js is outputting an error via console.error so Poltergeist is correctly notifying you of a JS error. Depending on which release version of PhantomJS you're using with Poltergeist it's equivalent at best to a 5 year old version of Safari so most so it may be that the braintree JS isn't compatible anymore or needs a polyfill or two to function correctly. You'll need to debug and attempt to figure out what the [object Object] that's being logged really is. One option would be to start by switching to selenium for that test and seeing if the error still exists.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
  • Thanks Thomas! Your comment pointed me on the right track - instead of using selenium (running tests in docker and didn't want to set that all up) I tried an older version of Braintree's js plugin and it worked. The latest one (2.24.0) must have broken support for PhantomJS, while 2.0.0 still works (at least with the FakeBraintree gem I am using as well). Thanks again! – amclelland Mar 12 '17 at 19:25