Cypress-等待所有jQuery请求完成,然后再继续下一步



我来自Selenium/Python背景,现在正在学习Cypress。

简而言之,我们有一个视觉回归工具,它必须等待页面上的所有内容都完全加载,然后才能进行屏幕截图。

在我以前的框架中,我能够使用以下代码来等待一个具有jQuery请求的页面完全加载,并且它起作用了。

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
)

现在我正在使用Cypress,我不知道如何基本上运行返回线路。我在谷歌上搜索过,但到目前为止都不好。

我和下面的人玩过,但没有快乐。

pageLoaded() {
Cypress.$(document).ajaxStop(function () {
})
}

您可以使用cyprus命令cy.window()调用窗口对象。

cy.window().then(win => {
// do something with win
});

但我认为最好使用命令cy.intercept()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');

最新更新