简体   繁体   English

邮递员 - 在另一个测试中使用来自一个测试的部分响应数据

[英]Postman - Use part of the response data from one test in another test

I require help to execute a postman test which requires a response output from another test. 我需要帮助来执行邮递员测试,该测试需要来自另一个测试的响应输出。 I have checked with various forums but a solution is not available for this particular scenario. 我已经检查了各种论坛,但是没有针对此特定方案的解决方案。

Example

Test 1 response: 测试1响应:

{
"items": [
    {
        "email": "archer+qa01@gmail.com",
        "DocumentName": "tc",
        "type": "URL",
        "url": "https://localhost:8443/user/terms?statusno=a5f2-eq2wd3ee45rrr"
     }
  ]
}

Test 2: 测试2:

I need to use only the a5f2-eq2wd3ee45rrr part of the response data from Test 1 , this can be seen in the url value above. 需要使用Test 1的响应数据的a5f2-eq2wd3ee45rrr部分,这可以在上面的url值中看到。 I need to use this value within Test 2 我需要在Test 2使用此值

How can I make this work with Postman? 我怎样才能与Postman合作?

Not completely sure what the response data format is from the question but if it's a simple object with just the url property, you could use something simple like this: 不完全确定问题的响应数据格式是什么,但如果它是一个只有url属性的简单对象,你可以使用这样简单的东西:

var str = pm.response.json().url
pm.environment.set('value', str.split('=', 2)[1])

This will then set the value you need to a variable, for you to use in the next request using with the {{value}} syntax in a POST request body or by using pm.environment.get('value') in one of the test scripts. 然后,这将为变量设置所需的值,以便在下一个请求中使用POST请求正文中的{{value}}语法或在其中一个中使用pm.environment.get('value')测试脚本。

邮差

Edit: 编辑:

If the url property is in an array, you could loop through these and extract the value that way. 如果url属性在数组中,您可以遍历这些并以这种方式提取值。 This would set the variable but if you have more than 1 url property in the array it would set the last one it found. 这将设置变量,但如果您在数组中有多个url属性,它将设置它找到的最后一个属性。

_.each(pm.response.json(), (arrItem) => {
    pm.environment.set('value', arrItem[0].url.split('=', 2)[1])
})

邮差

If you get JSON response and then send JSON in body, I would do the following: 如果你得到JSON响应,然后在体内发送JSON,我会做以下事情:

1) In test script(javascript): 1)在测试脚本(javascript)中:

var JsonBody = pm.response.json();
var strToParse = JsonBody.url;
var value = strToParse.slice(indexOf("?status=")+"?status=".length);//parse string 
//manually but you can google for a better solutions.
pm.environment.get("varName" , value) 

2) You can use it! 2)你可以使用它! In scripts like: pm.environment.get("varName") , and everywhere else using {{varName}} 在诸如: pm.environment.get("varName")类的脚本中,以及使用{{varName}}其他任何地方

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

相关问题 如何在邮递员测试主体的另一个请求测试主体中使用来自一个请求的变量? - How to use variable from one request in another request test body in postman test body? 在另一个请求的正文中使用来自一个请求的响应对象[邮递员] - Use response object from one request in body of another [postman] Postman,测试 Graphql 响应 - Postman, test Graphql response Postman:如何从一个 API 获取响应数据并在另一个 API 中使用它(如果我在一个集合中有两个 API) - Postman: how to fetch response data from one API and use it in another API (if I have two APIs in one collection) 在 Postman 测试中使用哪个片段来验证标头值的一部分 - Which snippet to use in Postman test to validate a part of a header value 如何编写邮递员测试来将响应 json 与另一个 json 进行比较? - How to write a postman test to compare the response json against another json? 验证 Postman 测试脚本中的响应 - Validate response in Postman test script 简单的 Postman 响应时间测试 - Simple Postman response time test 如何从外部 JSON 文件中读取测试数据并与 postman 响应进行比较? - How to read test data from external JSON file and compare with postman response? 邮递员测试中的访问响应大小 - Access response size in postman test
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM