question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress test runner crashing on clicking make payment using Stripe payment gateway

See original GitHub issue

Current behavior

After entering the testing card details like card number, cvc and expire date in Stripe Gateway… on clicking make button, cypress test runner is crashing without giving any error or warning message. Manually Stripe payment is working fine with same card details. image

Desired behavior

Test runner should not be crash and in case of some major error - error should be shown there.

Test code to reproduce

 cy.get('iframe').its('0.contentDocument.body').should('not.be.empty')
        .then(cy.wrap).find('input[name="number"]').type(this.data.PaymentDetails.CardNumber)

    cy.get('iframe').its('0.contentDocument.body').should('not.be.empty')
        .then(cy.wrap).find('input[name="expiry"]').type(this.data.PaymentDetails.ExpMonthYear)

    cy.get('iframe').its('0.contentDocument.body').should('not.be.empty')
        .then(cy.wrap).find('input[name="cvc"]').type(this.data.PaymentDetails.Csv)

    cy.wait(5000)

    cy.get(".confirm-btn >button[id='c-submit-me']").click()    // Clicking on this, test runner is crashing.

Cypress Version

10.7.0

Node version

16.14.2

Operating System

Windows 10 Enterprise - OS build - 19044.1889

Debug Logs

Crashed... no logs generated.

Other

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:27 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
mschilecommented, Oct 14, 2022

@amar0120, it appears Stripe is attempting to change the top url which is causing Cypress to go back to the spec list. I initially thought setting experimentalModifyObstructiveThirdPartyCode would resolve the issue but it did not. We will need to investigate that further.

However, in the meantime, I was able to get the test to successfully run using the following intercepts:

    beforeEach(() => {
        // TODO: Remove once https://github.com/cypress-io/cypress/issues/23772 is complete
        cy.intercept('https://r.stripe.com/0', (req) => {
            // the origin header is not getting set which is causing the request to fail
            req.headers['origin'] = 'https://js.stripe.com'
        })

        // TODO: Remove once https://github.com/cypress-io/cypress/issues/23772 is complete
        cy.intercept('https://js.stripe.com/v3', (req) => {
            req.on('response', (res) => {
                // stripe is attempting to change window.top location so change it to window.self
                res.body = res.body.replaceAll('window.top', 'window.self')
            })
        })
    })
1reaction
mschilecommented, Nov 1, 2022

@MehdiSv, thanks for clearing that up for me 😄. I’m not sure why the intercepts wouldn’t run when you are in headless mode. If you are able to create a sample repo I’d be happy to look at it though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Stripe Integration with Cypress | by Bartek Golota
Custom payment flow integration requires end-to-end testing to make sure everything works as expected and we get a smooth user experience.
Read more >
Handling stripe payments checkout with cypress - Questions
Cypress runner vanishes when redirects to Stripe for payments checkout. Has anyone faced this issue? Any idea how to handle it.
Read more >
How to test your Stripe Checkout with Cypress
In this article we will look into how we can test a website that uses Stripe Checkout bringing more testing to your eCommerce!...
Read more >
Error Messages | Cypress Documentation
This message means that Cypress encountered an error when compiling and/or bundling your test file. Cypress automatically compiles and bundles your test code...
Read more >
Free for Developers
Developers and Open Source authors now have a massive amount of services offering free tiers, but it can be hard to find them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found