I am testing a web application form that has popups and it takes a lot of time to load another popup form that needs to be filled
currently, I am using a wait of 20 sec which mainly works but sometimes popups take more than 20 seconds to load which makes my test script fail
the popup is triggered using a button, when the button is clicked ajax request is made and when the response comes the popup is loaded (rendered)
the popup usually takes this much time because Ajax requests take a long so I wanted to create a dynamic function that will wait for that popup to render
so I want to make a dynamic wait function which will wait for popup to render (note: its a popup not another page)
code:
cy.get("div[class='question-btn'] a[class='btn btn-primary btn-lg cat-new-question-sortable']").click()
// button which triggers the popup
cy.wait(9000)
//multiple input, types get filled in the poup
cy.get("input[value='Submit']").click() // button which closes or submits the popup
cy.wait(9500)
cy.get("div[class='question-btn'] a[class='btn btn-primary btn-lg cat-new-question-sortable']").click()
// button which triggers the next popup and cycle repeats
There are a couple of options
Timeout on element instead of wait()
Add a timeout on an element on the popup that is much longer than the wait you currently have
A timeout is better than a wait() because you can make it really long (for this case maybe 60 seconds), but it only ever waits until the element appears.
Intercept
Add an intercept for the ajax request and wait on that.
Mocking the response
Use a mock response for the intercept to eliminate the waiting period