当用户通过Cypress run
命令运行所有测试时,Cypress似乎出现了一个与cy.reguest相邻的错误。但是,当我们从赛普拉斯UI(cypress open
)运行相同的测试时,一切正常……
因此,在我的代码中,第二个和第三个POST请求将被忽略(赛普拉斯run
命令(yarn cypress run --browser chrome --config-file=./cypress.json
)没有任何反应。
C柏打开-[链接] [1] 赛普拉斯奔跑-[link] [2]
Promise.all([
assertFile(`./cypress/fixtures/questionnaire/${val}_submission.json`),
assertFile(`./cypress/fixtures/questionnaire/${val}_finalize.json`),
])
.then(([submissionBody, finalizeBody]) => {
expect(submissionBody).not.null;
expect(finalizeBody).not.null;
cy.request({
method: 'POST',
url: buildApiUrl(Cypress.env('questionnaireConfigurationPath')),
headers: {
PHPSESSID: sessionId,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json, text/plain, */*',
},
body: {},
}).then(configurationResponse => {
expect(configurationResponse.status).to.eq(200);
configurationBody = configurationResponse.body;
const { questionnaireId } = configurationBody.submission;
const uniqueSubmissionBody = Object.assign({}, submissionBody, {
questionnaireId,
});
const uniqueFinalizeBody = Object.assign({}, finalizeBody, {
questionnaireId,
});
cy.request({
method: 'POST',
url: buildApiUrl(Cypress.env('questionnaireSubmissionPath')),
headers: {
PHPSESSID: sessionId,
'cache-control': 'no-cache',
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json, text/plain, */*',
},
body: uniqueSubmissionBody,
}).then(submissionResponse => {
expect(submissionResponse.status).to.eq(200);
cy.request({
method: 'POST',
url: buildApiUrl(Cypress.env('questionnaireFinalizePath')),
headers: {
PHPSESSID: sessionId,
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json, text/plain, */*',
},
body: uniqueFinalizeBody,
}).then(finalizeResponse => {
expect(finalizeResponse.status).to.eq(200);
expect(finalizeResponse.body.fundingSearchId).greaterThan(0);
cy.writeFile('./testDataApi.json', {
profileId: finalizeResponse.body.fundingSearchId,
});
});
});
});
})
.catch(err => cy.log(err));
});```
[1]: https://ibb.co/CzG7h6M
[2]: https://ibb.co/YtvDZJ1