小编Aut*_*Dev的帖子

cy.wait() 等待第一个路由请求超时 5000 毫秒

我是新手Cypress,正在检查 HTML 页面。我需要测试登录身份验证并记录XHR正文。所以,我写了一个测试,如下所示:

describe('Login test', function () {

    it("Test description", () => {
        cy.server();
        cy.visit("login");

        cy.route({
            method: "POST",
            url: '/login'
        }).as("login");

        cy.get('#username')
            .type(Cypress.env('Account'));

        cy.get('#password')
            .type(Cypress.env('Password'));

        cy.get('#login')
            .click();

        cy.wait("@login").then(xhr => {
            cy.log(JSON.stringity(xhr.response.body));
        });

    });
});
Run Code Online (Sandbox Code Playgroud)

测试失败,日志为:

CypressError:重试超时:cy.wait() 等待第一个路由请求 5000 毫秒超时:“route_login”。从未发生过任何请求。

有人可以帮忙吗?

javascript cypress

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

cypress ×1

javascript ×1