问题描述
我使用赛普拉斯(v 4.12.1)为我的React App编写了一些集成测试。我在AWS上有一张CI / CD,需要将它们集成。涉及的产品是GitHub(源存储库),AWS CodePipeline,AWS CodeBuild。
如果必须测试一页的外观,则赛普拉斯测试成功。如果测试涉及一个API调用,而我必须使用cy.wait()
函数,那么我得到的错误是:
CypressError: `cy.wait()` timed out waiting `5000ms` for the 1st request to the route: `agreements`. No request ever occurred.
我检查了服务器日志,看到收到了API请求,因此问题是赛普拉斯无法理解是否进行了API调用。然后我在GitHub https://github.com/cypress-io/cypress/issues/3427上发现了这个问题,但是我发现的建议是我正在使用的建议:
context("Test Page",() => {
before(() => {
cy.server();
cy.route({
method: "POST",url: `https://myserver.com/${Cypress.env("ENV")}/login`,status: 201,}).as("login");
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
cy.visit("http://localtest.myserver.com:3000/test_page");
// dismiss cookie message
cy.get("[data-cy=dialog-actions]").find("button").click();
cy.log('Cookie message dismissed');
});
it("landed on the agreements page",() => {
cy.bypassLogin().then((xhr) => {
LOGIN_ID = xhr.body["loginId"];
cy.route({
method: "GET",url: `https://myserver.com/${Cypress.env("ENV")}/login/${LOGIN_ID}/agreements`,status: 200,}).as("agreements");
});
cy.wait("@agreements").then((xhr) => {
NUM_AGREEMENTS = xhr.response.body.length;
let requiredAgreements = [];
let notrequiredAgreements = [];
xhr.response.body.forEach((elem,idx) => {
elem.isrequired
? requiredAgreements.push(idx)
: notrequiredAgreements.push(idx);
});
IDX_required_AGREEMENTS = requiredAgreements;
IDX_NOT_required_AGREEMENTS = notrequiredAgreements;
expect(xhr.status).to.eq(200);
});
});
有人可以帮助我解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)