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

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

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 31 (13 by maintainers)

Most upvoted comments

@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')
            })
        })
    })

No update right now, I spent a few hours playing around with Stripe quickstart but I can’t select the elements with Cypress - I’m not sure if I’m missing something, but it looks like Stripe makes it quite tricky for automation tools to interact with it.

@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.

Thanks for the update @MehdiSv, I’ll try to take a look at this later today.