Created
August 27, 2020 17:46
-
-
Save JeffreyWay/000401927686d72e77318d5e36d532e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Fetch the body of an iFrame. | |
*/ | |
Cypress.Commands.add('getIframe', () => { | |
return cy | |
.get('iframe') | |
.its('0.contentDocument.body', { log: false }) | |
.should('not.be.empty') | |
.then((body) => { | |
cy.wrap(body, { log: false }); | |
}); | |
}); | |
/** | |
* Enter the card details for a Stripe elements form. | |
* | |
* @param {Object} options | |
*/ | |
Cypress.Commands.add('enterStripeCard', (options = {}) => { | |
options = { | |
...{ approved: true }, | |
...options, | |
}; | |
cy.getIframe().within(() => { | |
cy.get('[name=cardnumber]') | |
.type(options.approved ? '4242424242424242' : '4000000000000002') | |
.wait(300); | |
cy.get('[name=exp-date]').type('0424').wait(300); | |
cy.get('[name=cvc]').type('242').wait(300); | |
cy.get('[name=postal]').type('42424'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment