Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created August 27, 2020 17:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyWay/000401927686d72e77318d5e36d532e6 to your computer and use it in GitHub Desktop.
Save JeffreyWay/000401927686d72e77318d5e36d532e6 to your computer and use it in GitHub Desktop.
/**
* 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