【问题标题】:Cypress - cy.wait() timed out waiting 5000ms for the 1st request to the route赛普拉斯 - cy.wait() 等待 5000 毫秒以等待对路由的第一个请求
【发布时间】:2019-06-17 00:36:25
【问题描述】:

对赛普拉斯来说还算新,到目前为止一切顺利,直到我想伪造一个网络请求。代码是这样的:

describe('Some test', function(){
it('Can fake out an XHR response', function(){
    cy.server()
    cy.route('https://reqres.in/api/users', [{ id: 1, name: 'Pat' }]).as('getMessages')
    cy.request('https://reqres.in/api/users')
    cy.wait(['@getMessages'])

...

无论我尝试什么,我都会得到:

CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the first request to the route: 'getMessages'。从未发生过请求。

我在这里做错了什么?

编辑:我将代码更改为:

cy.server()
cy.route('https://reqres.in/api/users', [{ id: 1, name: 'Pat' }]).as('getMessages')
cy.request('https://reqres.in/api/users')
cy.wait(['@getMessages'])

但结果如下:

【问题讨论】:

标签: cypress


【解决方案1】:

从赛普拉斯 6.0.0 开始,cy.intercept()cy.route() 的继承者,可用于返回预期响应,如下所示:

cy.intercept('GET','/api/users', expectedResult).as('interceptedRequest');

cy.wait('@interceptedRequest');

https://docs.cypress.io/api/commands/intercept

【讨论】:

    猜你喜欢
    • 2020-03-10
    • 2020-05-09
    • 2020-08-23
    • 2021-02-16
    • 1970-01-01
    • 2022-10-02
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    相关资源
    最近更新 更多