Question

I'm using Stripe JS on the checkout page of an ecommerce site. When testing manually in the browser, the flow works just fine. But when automating testing with Cucumber, I receive the following error when submitting the form:

An unexpected error has occurred submitting your credit card to our secure credit card processor. This may be due to network connectivity issues, so you should try again (you won't be charged twice). If this problem persists, please let us know!

Is there a reason Stripe JS wouldn't work in a test environment but is fine in development + production?

Was it helpful?

Solution

I am not a Stripe JS expert but when I have problems with Cucumber + JS in most cases there are two options:

  1. I need to add @javascript tag before feature/scenario (obvious problem)

  2. There is some delay required before steps with js functionality:

    When /^wait (\d) sec$/ do |delay|
      sleep delay.to_i
    end
    

Obviously it is not a good practise to use 'sleep' in tests but sometimes it is the only workaround.

OTHER TIPS

This is because if you use Stripe's method (https://stripe.com/docs/tutorials/forms), Stripe validates the information entered by the user asynchronously. Since this is done asynchronously, cucumber doesn't know about it. What you really need is have Cucumber wait in the step that follows Strip form submission until a certain condition is true with something like this.

Then(/^they should see "(.*?)"$/) do |content|
  wait_until do
   page.should have_content(content)
  end 
end

However, wait_until was removed from Capybara v2. So you will need to implement it yourself if you want to use it (via https://gist.github.com/jnicklas/d8da686061f0a59ffdf7)

Here is the full blog post on the topic

http://www.elabs.se/blog/53-why-wait_until-was-removed-from-capybara

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top