如何验证邮递员中的JSON数组值?

时间:2019-11-27 05:23:21

标签: postman web-api-testing postman-testcase

{
    "success": {
        "text": "successfully! deleted Records"
    }
}

要验证文本值是否为“成功!已删除的记录”

我尝试过

pm.test("Your test name", function () {
    var jsonData = pm.response.json();

    pm.expect(jsonData[0].text).to.eql("successfully! deleted Records");
});

1 个答案:

答案 0 :(得分:1)

您正在尝试从JSON对象而不是数组中检索数据。因此,应如下所示。

pm.test("Your test name", function () {
    var jsonData = pm.response.json();    
    pm.expect(jsonData.success.text).to.eql("successfully! deleted Records");
});