简体   繁体   English

postman jetpacks - 测试嵌套数据

[英]postman jetpacks - testing for nested data

I have a test in postman and the response comes back with 'nested' data. 我在postman中进行了测试,并且响应带有'嵌套'数据。 By that I mean we have a 'data' section of the response and a 'messages' section. 我的意思是我们有一个响应的“数据”部分和一个“消息”部分。 Inside data there are a ton of other fields and those are the ones I need to be verifying on with Jetpacks. 内部数据有很多其他字段,这些是我需要使用Jetpacks进行验证的字段。 How can I get to these fields? 我怎样才能到达这些领域?

this is what the json response looks like: 这就是json响应的样子:

{
  "Data": {
    "QRCode_ID": 168,
    "Repairer_ID": null,
    "AssignedToEmployee_ID": null,
    "TaskName": "003021919913",
    "DueDate": "2015-07-02T00:12:53.597",
    "DueDateTimeSpan": 1959471956224,
    "TaskStatus_ID": 1,
    "Description": "due 6/30, 5:00",
    "TaskUrgency_ID": null,
    "TaskType_ID": null,
    "DueDateDisplay": "2015-07-02 00:12",.......
      }
  },
  "Messages": [
    "success"
  ]
}

And this is what my postman test looks like: 这就是我的邮递员测试的样子:

var data = JSON.parse(responseBody);
tests["Verify QRCode_ID is correct"] = data.QRCode_ID === 168;

You can test for nested data much in the same way you test for data that is not nested (using dot notation) 您可以像测试未嵌套的数据一样测试嵌套数据(使用点表示法)

I created a really quick dummy service that returns the the following json: 我创建了一个非常快速的虚拟服务,返回以下json:

{
  "one": "1",
  "two": "2",
  "three": {
    "four": "4",
    "five": "5"
  }
}

In the following snippet I test (using dot notation) values in the nested object. 在下面的代码片段中,我在嵌套对象中测试(使用点表示法)值。 In particular I'm asserting that the object three has properties of four and five that are set to the values of "4" and "5" respectively: 特别是我声称对象3具有四个和五个属性,分别设置为“4”和“5”的值:

var data = JSON.parse(responseBody);
tests["4"] = data.three.four === "4";
tests["5"] = data.three.five === "5";

Here's my setup in postman with the corresponding json response: 这是我在postman中设置的相应json响应: 在此输入图像描述

Here are my test results: 这是我的测试结果: 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 POSTMAN中的Spring-data-rest测试 - Spring-data-rest testing in POSTMAN 用邮递员测试Drools DRL - Testing Drools DRL with postman 如何将嵌套的JSON数据导入Postman的收集运行器? - How to import nested JSON data into Postman's collection runner? Postman:发送嵌套JSON object - Postman: sending nested JSON object 如何从嵌套的JSON响应中获取数据并传递给邮递员中的下一个请求? - How to fetch data from nested JSON response and pass to next request in postman? 如何使用 postman 一起发送图像/文件和嵌套的 json 数据? - How can i send image/file and nested json data together using postman? 如何将 Postman 正文中带有嵌套数组字段的原始 JSON 转换为表单数据? - How to convert raw JSON with nested array field in Postman body into form-data? 如何在邮递员的同一请求中发送多部分/表单数据和嵌套的json? - How to send multipart/form-data and nested json in the same request in postman? 从邮递员发送带有图像/文件的嵌套 JSON 数据:Django REST 框架 - Send nested JSON data with image/file from postman: Django REST framework 邮递员:通过表单数据的嵌套 JSON 的 POST 请求不起作用(而通过原始数据可以) - Postman: POST request of nested JSON via form-data not working (while via raw-data ok)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM