1

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?

1 Answer 1

0

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.

(https://docs.cypress.io/guides/references/best-practices.html#Visiting-external-sites)

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
7
  • 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 Commented Jan 14, 2020 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 Commented Jan 14, 2020 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
    Commented Jan 14, 2020 at 20:30
  • @DanielVianna I have the exact same issue. Did you ever find a solution for this?
    – bigsee
    Commented Oct 16, 2020 at 13:16
  • 1
    @bigsee Not ideal solution, What I have done was doing separate tests. We mock the response by creating a different UI button (changed back-end to support this), so we have one button that does real transaction and another for test mock. Then I have a second test in cypress which is a pure API call to Stripe checking API key and a 200 response, It's like a health monitor. Commented Oct 17, 2020 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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