1

Initiating a visit(), it triggers three fetches before ending up on the final NEW URL. Each fetches triggers their corresponding wait() - except the NEW URL.

describe('login', () => {
  it('login', () => {
    cy.intercept('/_next/static/development/_devMiddlewareManifest.json').as('fetch1')
    cy.intercept('http://localhost:3333/auth/works/token-check').as('fetch2')
    cy.intercept('/_next/static/development/_devPagesManifest.json').as('fetch3')
    cy.intercept('http://localhost:3002/login').as('login')

    cy.visit('/')

    // cy.wait(['@fetch1', '@fetch2', '@fetch3', '@login'])
    cy.wait('@fetch1')
    cy.wait('@fetch2')
    cy.wait('@fetch3')
    // cy.wait('@login')
    cy.wait('@login', {
      requestTimeout: 10000
    })

    cy.url().should('include', '/login')
  })
})

enter image description here

Rich
  • 705
  • 9
  • 16
  • One of my mate has recommended a solution: pass an options object into url() with a worst case timeout. cy.url( { timeout: 20000 } ).should('include', '/login'). Same strategy can be applied with cy.contains( { timeout: 20000 } ), cy.get( { timeout: 20000 } ),... whichever accepts timeout in options object – Rich Aug 23 '22 at 06:57

1 Answers1

1

The (new page) log entry is not actually a network request, it just informs you that the page has navigated to a new URL.

Since your app is a SPA, this is most likely caused by the app router and not by any traffic coming over the network, so you can't use cy.intercept() to catch it.

You last command cy.url().should('include', '/login') should be sufficient to wait for the new page to occur.

Fody
  • 23,754
  • 3
  • 20
  • 37
  • Thanks Fody. Useful info, but in reality Cypress operation depends on computer's performance. The weaker the computer the more likely that your final statement becomes false. With one of my mate we test each others test on a regular basis with different computers and for the weaker one there must be a timeout passed in as an options object for successful run, while stronger one does the job without timeout. See my comments below the main question. – Rich Aug 23 '22 at 07:03
  • Indeed, increasing timeout is a good strategy when the test is flaky. It's so common, I presumed you would already know to increase it - sorry about that. – Fody Aug 23 '22 at 07:07