Cypress redirect e2e test with stripe js
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
- 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