使用赛普拉斯和火烧店测试反应应用程序显示超时重试:cy.wait()



我正在使用react 16.8.1cypress 3.1.5firebase 5.5.3进行e2e测试。

目前,我需要等待页面加载所有组件,然后运行测试,例如获取按钮并单击它。

在每次测试之前,程序都会检查用户是否已登录,如果是,它将等待Firebase发送一些POSTGET请求。

不幸的是,赛普拉斯对GET和POST请求都显示CypressError: Timed out retrying: cy.wait() timed out waiting 100000ms for the 1st response to the route: 'googleGETRoute'. No response ever occurred.,这使得单击或继续测试变得不可能。

在每个请求之前,我运行以下内容:

beforeEach(function () {
    cy.server().route({ url: /https://.*google.*/, method: "POST" }).as("googleRoute");
    cy.server().route({ url: /https://.*google.*/, method: "GET" }).as("googleGETRoute");
    cy.visit('/event');
    cy.wait('@googleRoute', xhr => {
        cy.url().then((url) => {
            if (url === 'http://localhost:3000/login') {
                cy.loginByForm(testUserAccount, testUserPassword);
            }
        });
    });
});

要删除事件,请执行以下操作:

it('should deleteEvent', function() {
    cy.wait('@googleGETRoute', { responseTimeout:100000, log:true });
    cy.wait('@googleRoute', { responseTimeout: 100000, log:true });
    deleteEvent(event);
    cy.contains(event.title).should('not.be.visible');
});

火堆仍然没有回应。我还检查了#1652和#2374,它们与此问题几乎相同。

以前有人遇到过这个问题吗?将不胜感激任何帮助

您不应该依赖firestore或firebase来启动测试,因为它是您无法控制的外部服务,尤其是

  • 这些 Firestore 请求何时发送?
  • 这些请求是为了什么?
  • 它们是如何工作的?

如果我们不理解,我们就不能指望赛普拉斯知道发生了什么,因为它是一个框架。

相反,您可以等待特定组件可用。默认情况下,cy.get 命令具有内置超时。它将等待给定组件呈现,然后测试失败。

在您的情况下,您可以增加第一个cy.get的超时,我认为这是deleteEvent().此外,您需要摆脱所有不可靠和无用的消防cy.server & cy.wait

最新更新