Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Stripe Checkout w/ Cypress

I have to call stripe.redirectToCheckout (https://stripe.com/docs/js/checkout/redirect_to_checkout) in js to take a customer to their stripe checkout page.

I want to use cypress to test the checkout process, but it is not able to handle the stripe redirect as the cypress frame is lost when stripe.redirectToCheckout navigates to the page on Stripe's domain.

I also want to test that Stripe redirects us back to the success or error URL.

  1. Is there any way to force cypress to "reattach" to the page once we've navigated to the Stripe checkout -or-
  2. Is there any way to get the URL for the Stripe checkout page so we can redirect manually or just know that it was at least called with the right parameters.

I know that testing external sites is considered an "anti-pattern" by the people at cypress (https://github.com/cypress-io/cypress/issues/1496). But how can a very standard web process, checkout, be tested (with a very popular and standard payment service, I will add) in that case? I don't buy that this is an "anti-pattern". This is an important step of the end-to-end test, and Stripe specifically gives us a testing sandbox for this kind of thing.

like image 249
Salami Avatar asked Jun 15 '20 19:06

Salami


1 Answers

One common way to e2e test application with external dependencies like stripe is to make a simple mock version of it, that is then applied in e2e testing. The mock can also be applied during development, to speed things up.

like image 67
Ville Miekk-oja Avatar answered Sep 21 '22 15:09

Ville Miekk-oja