我正在使用react 16.8.1
,cypress 3.1.5
和firebase 5.5.3
进行e2e测试。
当前,我需要等待页面加载所有组件,然后运行测试,例如获得一个按钮并单击它。
在每次测试之前,程序都会检查用户是否已登录,如果已登录,它将等待firebase发送一些POST
和GET
请求。
不幸的是,赛普拉斯同时为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');
});
firestore仍然没有回应。我还检查了#1652和#2374与这个问题几乎相同。
以前有人遇到过这个问题吗?不胜感激
答案 0 :(得分:1)
您不应该依赖firestore或firebase来开始测试,因为它是您无法控制的外部服务
如果我们不了解,我们就不能指望赛普拉斯知道发生了什么事,因为它是一个框架。
相反,您可以只等待特定组件可用。默认情况下,cy.get命令具有a built-in timeout。在测试失败之前,它将等待呈现给定的组件。
在您的情况下,您可以增加第一个cy.get
的超时时间,我认为这是在deleteEvent()
中。另外,您需要消除所有cy.server & cy.wait
的不可靠和无用的Firestore。