简体   繁体   中英

How do I get my Postman tests to pass using response body as the results?

I am attempting to write tests in Postman for the first time. I am using the pm.test method containing pm.expect .

Here is my test:

//contract details tests
pm.test("Contract data is correct", function() {
        pm.expect(pm.response.json().results.contractNb).to.equal("00002");
        pm.expect(pm.response.json().results.progSrvcNm).to.equal("009");
});

My response appears like so:

{
    "contractNb": "00002",
    "progSrvcNm": "009",
    "contractPartyNm": "testContract",
    "terms": 30,
    "startDt": "2018-01-01"
}

Given your response body data - If you just remove the .results part of the expect statement, the check will pass.

pm.test("Contract data is correct", () => {
    pm.expect(pm.response.json().contractNb).to.equal("00002")
    pm.expect(pm.response.json().progSrvcNm).to.equal("009")
})

邮差

The correct code was as Danny Dainton posted.

pm.test('Contract details are correct for the passed in contract ID', () => {
    pm.expect(pm.response.json().contractNb).to.equal("00002");
    pm.expect(pm.response.json().progSrvcNm).to.equal("009");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM