I have come from a Selenium/Python background and I'm now learning Cypress.
In a nutshell, we have a visual regression tool that has to wait for everything on the page to completely load prior to taking a screenshot.
In my previous framework, I was able to use the following code to wait for a page to completely load that had jQuery requests and it worked.
def wait_for_page_to_load(self):
"""
Waits for page to fully load
"""
try:
wait = WebDriverWait(self.driver, 10, 0.25)
wait.until(
lambda driver: driver.execute_script(
"return (window.jQuery != null) && (jQuery.active === 0);"
)
)
self.log.info("Page has finished loading")
except:
e = sys.exc_info()[0]
self.log.error(
"### Exception occurred whilst waiting for page to load: %s", e
)
Now that I am using Cypress, I don't know how to basically run the return line. I've searched google but so far no good.
I've played around with the following but no joy.
pageLoaded() {
Cypress.$(document).ajaxStop(function () {
})
}
You may call the window object using cypress command cy.window().
cy.window().then(win => {
// do something with win
});
But I believe it would be best to use commands cy.intercept() with cy.wait
// before the start of your test:
cy.intercept('GET', '/path/to/api/calls/1').as('apiCall1');
// During your test:
cy.visit('yourUrl');
cy.wait('@apiCall1');