2

我正在开发一个使用赛普拉斯实现自动化的项目。在这个项目中,我需要为患者创建一个订单。当我单击提交按钮时,它将https://ibis-dev.droicelabs.us/api/dispenser/orders/使用 POST 方法调用以下 API 并返回我想要获取的唯一订单。

我已经cy.intercept像这样在我的测试之上注册:

cy.intercept({
    method: 'POST',
    url: 'https://ibis-dev.droicelabs.us/api/dispenser/orders/',
}).as('ordersCall')

当单击提交按钮时,我使用了:

cy.clickOnElementUsingXpath(practicePageSelectors.submit_CreateOrderButton); // click on submit button
cy.wait('@ordersCall')
    .its('response.body')
    .then((body) => {
        // parsing might be not needed always, depends on the api response
        const bodyData = JSON.parse(body)
        cy.log(bodyData)
    })

但它返回以下错误:

Timed out retrying after 5000ms: cy.wait() timed out waiting 5000ms for the 1st request to the route: ordersCall. No request ever occurred in cy.wait('@ordersCall')

谁能帮我获取orderID?有没有其他方法可以获取 orderID?

4

1 回答 1

2

检查问题评论中提供的图像后,错误如下:您的 Cypress 测试中的拦截命令正在等待向您的 DEV 环境发出请求,但是在 Cypress 测试运行器中从控制台查看您的最后一个图像正在向 QA 环境发出请求。

所以你要么必须像这样调整你的拦截器:

cy.intercept({
    method: 'POST',
    url: 'https://ibis-qa.droicelabs.us/api/dispenser/orders/',
}).as('ordersCall')

或者考虑使用 API 调用的相对路径独立于环境:

cy.intercept({
    method: 'POST',
    url: '/api/dispenser/orders/',
}).as('ordersCall')
于 2022-01-20T06:56:45.577 回答