cypresscypress-origin

Can cy.origin wait longer for a redirect?


I have some code that visits my page, which then redirects for authentication. The issue is the page takes too long to do the redirect, so cy.origin times out before the domain it is targeting is loaded. Is there a way (other than an evil hard coded wait) to get cy.origin to wait longer for the domain it's targeting?

I tried cy.url().should('match', /^authurl.com/) before the cy.origin call, but of course that won't work because cy.url() is cross domain by the time authurl.com is loaded (cy.url() seems to return blank at that time). I tried putting cy.url().should('match', /^authurl.com/) inside the origin call, but I think that's redundant, as it won't execute until the authurl.com domain is loaded.

Any suggestions?

  cy.visit(Cypress.config().baseUrl)
  
  cy.origin( 'authurl.com', { args: { username, password } }, 
   ({ username, password }) => {   
      // Enter username and submit.
      cy.get('input[type="email"]').type(username, { log: false })
      cy.get('input[type="submit"]').click()

      // Enter password and submit.
      cy.get('input[type="password"]').type(password, { log: false })
      cy.get('input[type="submit"]').click()
    }

Solution

  • Working solution similar to the first option suggested by @aladin-spaz, just using url() instead of location(), and located at the top of the origin instead of the bottom.

     cy.visit(Cypress.config().baseUrl)
      
      // Login to your AAD tenant.
      cy.origin( 'authurl.com', { args: { username, password } }, 
       ({ username, password }) => {
          cy.url().should('match', /^https:\/\/authurl\.com/, { timeout: 90000 })
    
          // Enter username and submit.
          cy.get('input[type="email"]').type(username, { log: false })
          cy.get('input[type="submit"]').click()
    
          // Enter password and submit.
          cy.get('input[type="password"]').type(password, { log: false })
          cy.get('input[type="submit"]').click()
        }
      )