【问题标题】:Validate response in Postman test script在 Postman 测试脚本中验证响应
【发布时间】:2019-08-23 07:24:24
【问题描述】:

我在邮递员中插入数据。我想在测试脚本中应用 post 方法的验证。我是邮递员的新手,我无法理解。

这是 JSON。

{
  "firstname": "pradeep",
  "lastname": "tiwari",
  "mobile_no": 9911844349,
  "email": "pradeep@gmail.com",
  "user_type": 4,
  "password": "pradeep1",
  "confirmPassword":"pradeep1",
  "dob":"nanana",
  "u_org":25,
  "isfoundingpartner":"undifine",
  "gender":1
}

【问题讨论】:

    标签: postman postman-testcase


    【解决方案1】:

    您可以使用内置的 sn-ps for starters 来验证您的基本响应消息。 https://learning.getpostman.com/docs/postman/scripts/test_examples/

    【讨论】:

    • 感谢回复我收到回复:{“result”:{“code”:200,“status”:true,“message”:“用户成功注册”}}我想显示在“测试结果”中回复“消息”我是如何做到的
    • pm.test("正文匹配字符串", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search"); });只需使用它并打印您想要在测试中打印的任何结果。
    • 让结果 = pm.response.json().result; if(result.status === false){ pm.test(result.message) } else{ pm.test(result.message) } 感谢@Arslan 的帮助,我使用它,我得到了我想要的
    【解决方案2】:

    为了对您的响应进行验证,您首先需要使用以下方法将数据解析为 JavaScript 对象

    var jsonData = pm.response.json();  
    

    您可以使用以下代码检查响应正文中的特定值

     pm.test("Verify Json values", function () { 
      pm.expect(jsonData.firstname).is.to.equal("pradeep"); 
      pm.expect(jsonData.lastname).is.to.equal("tiwari"); 
        pm.expect(jsonData.gender).is.to.equal(1); `
    });
    
    
    
    
     
    

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 2020-10-23
      • 2018-09-10
      • 2018-03-11
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 2023-02-03
      相关资源
      最近更新 更多