Cypress foolishly waits for the new page to load after the button has been clicked and even the new page's core actionable resource is ready

Viewed 1966

I know this has been asked on SO and Github already, but none of the solutions are suitable for the scenario I have because, I am looking for successful SSO login by doing keypress/button-click actions on Google Auth and Identity Auth SSO options.

In these options the final Login page URL is too long and unknown(in it's entirety) so not fully and reliably verifiable by Cypress URL match methods, so I want Cypress to just click the button and wait for the next page to load until certain core-actionable element is found/present on the new page and then not stupidly wait any further and type required credentials(username) on that long-URL login page and press enter to go to password page and fill the password and press enter and let the rest of the steps continue "naturally".

Below is the code that I have and as I mentioned in the comment in the code, after the button click, it waits for new page to fully load, even after the new page already has actionable item, and increasing the defaultCommandTimeout to 20000 also doesn't help:

describe('Test if <ProjectName> Search page is reachable', () => {
    it('Visits the <ProjectName> Search page', () => {
        cy.visit('/')
        cy.window().then(w => w.beforeReload = true)
         // Sign in with Google button, cypress timeouts after this button has been clicked, 
         // even if the new page has actionable item("identifier" field) ready for use
        cy.get('button.<sso-class>').first().click()
        cy.window().should('not.have.prop', 'beforeReload')
        cy.get('input[name=identifier]').type('<GoogleUsername>').type('{enter}')
        cy.get('input[name=password]', {timeout: 4000}).type('<GooglePassword>').type('{enter}')
        cy.url().should('eq', '/search')
    })
})

And after waiting, times out throwing the below error:

(page load)
--waiting for new page to load--
CypressError
Cypress command timeout of 20000ms exceeded.

Because this error occurred during a after all hook we are skipping all of the remaining tests.

As you can see in the code, I have already tried one fix mentioned in this GH(Github) post and the other fix is not suitable, as I said, I don't know the final Login page URL of Google/Identity server, and also it's too long with too many querystrings which makes it unreliable for Login page-load checks...

Anyone has any better suggestions ?

0 Answers
Related