I am writing an e2e test in cypress for an online store and after clicking the confirm purchase button it redirects to stripe page (not iframe but one-time payment redirect to their website) to input credit card and then redirects back to our store to show the receipt.

Does anyone know what should be the best way to perform this test? Should it be API? How to use stripe API to do the payment using cy.request in order to avoid redirecting to their page?


Yes, as per official cypress documentation, you should avoid using cy.visit() when testing an external site. They also list a bunch of reasons why this is not the best approach:

However, you should never use your UI or visit a 3rd party site when testing because:

  • It is incredibly time consuming and slows down your tests.
  • The 3rd party site may have changed or updated its content.
  • The 3rd party site may be having issues outside of your control.
  • The 3rd party site may detect you are testing via a script and block you.
  • The 3rd party site may be running A/B campaigns.


So, in your case, you're better off with cy.request(). For that, you need:

  • read their documentation, if you don't know how to use cy.request()
  • read a documentation of yout API; I'm not sure what payment provider you're using, so I can link more resources for you to have a look at
| improve this answer | |
  • There is another complication, we have our own receipt and invoice generated after the transaction is made, so if we stub the response, we cannot check our invoice – Daniel Vianna Jan 14 at 16:02
  • We do not visit, when you click on the button it goes to a redirect (it's not the old stripe popup) but the new stripe checkout is not API, but it's a redirect github.com/stripe-samples/checkout-one-time-payments – Daniel Vianna Jan 14 at 16:02
  • I don't really know this Stripe, it might complicate things if there is no API as I understand from your comment. I mean it's not that you can go to an external page in Cypress, it's just not recommended. – pavelsaman Jan 14 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.