小编Kru*_*iya的帖子

使用 cypress 进行 API 测试时,出现“expected { Object (message, detail) } to have property 'count'”错误

我想断言从响应中收到的总数。

这是我的代码:

cy.request({
        method:'GET',
        url:'https://ibis-qa.droicelabs.us/api/practice/orders/?q=&limit=100',
        failOnStatusCode: false,
        headers:{
            accept: "application/json"
        }
    }).then(Response => {
        let body = JSON.parse(JSON.stringify(Response.body))
        cy.log(body)
        expect(body).has.property('count','27')
   })
Run Code Online (Sandbox Code Playgroud)

这是我遇到的错误

在此输入图像描述

响应体

rest web-api-testing cypress

0
推荐指数
1
解决办法
2439
查看次数

我想使用 cypress 中的 cy.intercept 从 API 响应中获取 OrderID

我想从 API 响应中获取订单 ID。当我单击“创建订单”按钮时,它将发送 POST API 请求并返回我想要保存在 JSON 文件中的 ID。

这是我的订单创建代码。

cy.clickOnElement(practicePageSelectors.CreateOrder).click(); // click on add Rx button
cy.readFile('cypress/fixtures/Data.json').then((profile) => {
   cy.searchPatients(practicePageSelectors.searchPatient1, profile.Patient_fullName);
})
cy.searchDoctors(); // search for the doctor
cy.clickOnElementUsingXpath(practicePageSelectors.nextButtonId); // click on the next button
cy.clickOnElement(practicePageSelectors.createOnetimeOrder)
cy.searchMedicine() //search for Medicine
cy.clickOnElementUsingXpathfirst(practicePageSelectors.addMedicine); // click on add button
cy.clickOnElementUsingText(practiceData.paymentButtonName, practiceData.buttonTag); // click on skip payment button
cy.clickOnElementUsingXpath(practicePageSelectors.submit_CreateOrderButton)
Run Code Online (Sandbox Code Playgroud)

我尝试过这样的事情

cy.intercept({
      method: 'POST',
      url: 'https://ibis-dev.droicelabs.us/api/dispenser/orders/',
    }).then((responce)=>{
      let body = JSON.parse(responce.body)
      cy.log(body)
    })
Run Code Online (Sandbox Code Playgroud)

我不知道如何使用intercept。请指导我

automated-tests web-api-testing cypress

0
推荐指数
1
解决办法
682
查看次数

标签 统计

cypress ×2

web-api-testing ×2

automated-tests ×1

rest ×1