Skip to content

Instantly share code, notes, and snippets.

View loranmutafov's full-sized avatar

Loran loranmutafov

View GitHub Profile
Cypress.Commands.add('signHellosignContract', () => {
cy.waitForHellosignContractIframe(contractFrames => {
cy.wrap(contractFrames[0])
.contains('button', 'OK')
.click();
cy.wrap(contractFrames[0])
.contains('button', 'Get Started')
.click();
Cypress.Commands.add('waitForStripe3dIframe', callback => {
cy.get('iframe[src^="https://js.stripe.com/v3/three-ds-2-challenge"]')
.should('be.visible');
cy.get('iframe[src^="https://js.stripe.com/v3/three-ds-2-challenge"]')
.iframe()
.then(iframes => {
cy.wrap(iframes[0])
.find('iframe')
.should('be.visible');
Cypress.Commands.add('fillOutCreditCardForm', details => {
cy.get('.__PrivateStripeElement > iframe')
.iframe()
.then(iframes => {
cy.wrap(iframes[0])
.find('.InputElement')
.first()
.type(details.number);
cy.wrap(iframes[1])
.find('.InputElement')
@loranmutafov
loranmutafov / iframe.commands.js
Last active January 9, 2024 19:18
Cypress command to wait for iframes to load
/**
* Will check if an iframe is ready for DOM manipulation. Just listening for the
* load event will only work if the iframe is not already loaded. If so, it is
* necessary to observe the readyState. The issue here is that Chrome initialises
* iframes with "about:blank" and sets their readyState to complete. So it is
* also necessary to check if it's the readyState of the correct target document.
*
* Some hints taken and adapted from:
* https://stackoverflow.com/questions/17158932/how-to-detect-when-an-iframe-has-already-been-loaded/36155560
*