Skip to content

Instantly share code, notes, and snippets.

@gzzsound
Created May 9, 2023 19:04
Show Gist options
  • Save gzzsound/5fdbaa8b3aef873c1b05b9d3a7132ce8 to your computer and use it in GitHub Desktop.
Save gzzsound/5fdbaa8b3aef873c1b05b9d3a7132ce8 to your computer and use it in GitHub Desktop.
// in Cypress commands.js
Cypress.Commands.add('getStripeElement', (selector, value) => {
cy.get('iframe')
.should((iframe) => expect(iframe.contents().find(selector)).to.exist)
.then((iframe) => cy.wrap(iframe.contents().find(selector)))
.within((input) => {
cy.wrap(input).should('not.be.disabled').clear().type(value)
})
})
// in your test
cy.getStripeElement("#Field-numberInput", "4242424242424242");
cy.getStripeElement("#Field-expiryInput", "1025");
cy.getStripeElement("#Field-cvcInput", "123");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment