无法在邮递员中执行if语句

时间:2018-07-31 02:52:58

标签: postman

我已经在测试脚本下面创建了,目标是验证对测试的响应主体。但是我的问题是每次我发送请求时都没有测试响应。预先感谢

if (pm.response.text() === "length must not be less than 3")
{
    pm.test("length must not be less than 3", function () {
        pm.expect(pm.response.text()).to.include("length must not be less than 3");
    });
}else if (pm.response.text() === "Record already exists.")
{
    pm.test("Record already exists.", function () {
        pm.expect(pm.response.text()).to.include("Record already exists.");
    });
}else if (pm.response.text() === "Username already exists.")
{
    pm.test("Username already exists.", function () {
        pm.expect(pm.response.text()).to.include("Username already exists.");
    });
}else if (pm.response.text() === "success")
{
    pm.test("success", function (text) {
        pm.expect(pm.response.text()).to.include("success");
    });
}else
{
    pm.test("Invalid Token", function () {
      pm.expect(pm.response.jsonData()).to.include("Failed to connect.");
    }); 
}

1 个答案:

答案 0 :(得分:0)

此代码段中缺少jsonData。

请声明:

var jsonData = pm.response.com();