我是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));
});
});
});
测试失败,日志为:
CypressError:超时重试:cy.wait()超时,等待5000ms的第一个请求到路由:“ route_login”。从未发生过请求。
请问有什么可以帮助的吗?
答案 0 :(得分:0)
尝试一下:
describe('Login test', function () {
it("Test description", () => {
cy.server();
cy.route({
method: "POST",
url: '/login'
}).as("login");
cy.wait("@login", {timeout: 15000});
cy.visit("login");
cy.get('#username')
.type(Cypress.env('Account'));
cy.get('#password')
.type(Cypress.env('Password'));
cy.get('#login')
.click();
cy.get("@login").then(xhr => {
cy.log(JSON.stringity(xhr.response.body));
});
});
});