best-stone-6612
03/11/2023, 11:44 AMhundreds-window-7679
03/12/2023, 12:20 AMdescribe('Duo Factor Authorization', () => {
it('should log in and complete Duo authorization', () => {
// Visit the login page and enter username and password
cy.visit('https://example.com/login')
cy.get('#username').type('myusername')
cy.get('#password').type('mypassword')
// Click the Sign In button
cy.get('button[type="submit"]').click()
// Wait for the Duo iframe to load
cy.get('iframe[name="duo_iframe"]')
.should('be.visible')
.its('0.contentDocument.body').should('not.be.empty')
.then(cy.wrap)
.find('#duo_iframe')
.its('0.contentDocument.body').should('not.be.empty')
// Switch to the Duo iframe and click the "Send Me a Push" button
cy.get('iframe[name="duo_iframe"]')
.its('0.contentDocument.body').should('not.be.empty')
.then(cy.wrap)
.find('#duo_iframe')
.its('0.contentDocument.body').should('not.be.empty')
.then((body) => {
const duoIframe = body.find('#duo_iframe')
return cy.wrap(duoIframe.contents().find('button[value="Send Me a Push"]')).click()
})
// Switch back to the parent window and confirm Duo authorization
cy.get('body').then((body) => {
return cy.wrap(body).find('.duo-iframe-container iframe').then((duoIframe) => {
return cy.wrap(duoIframe.contents().find('.auth-status[data-reactid$="-status"]')).should('contain', 'Approve the request sent to your device')
})
})
cy.get('body').then((body) => {
return cy.wrap(body).find('.duo-iframe-container iframe').then((duoIframe) => {
return cy.wrap(duoIframe.contents().find('.auth-button[data-reactid$="-accept"]')).click()
})
})
// Complete the rest of the login process
// ...
})
})
In this example, we're first waiting for the Duo iframe to load using cy.get() and the appropriate selector. We're then using cy.wrap() to wrap the iframe contents so that we can interact with its child elements.hundreds-window-7679
03/12/2023, 12:20 AMbest-stone-6612
03/12/2023, 1:40 AM