我正在尝试验证响应正文,包括邮递员中的错误.如何验证下面的响应和文本?
I am trying to validate response body including errors in postman. How can I validate the response and text below?
{
"responseHeader": {
"publisherId": "12345",
"responseId": "abbcb15d79d54f5dbc473e502e2242c4abbcb15d79d54f5dbc473e502e224264",
"errors": [
{
"errorCode": "1004",
"errorMessage": "XXXX Not Found"
}
]
}
}
这些是我失败的测试:
tests['response json contains responseHeader'] = _.has(responseJSON, 'responseHeader');
tests['response json contains errors'] = _.has(responseJSON, 'responseHeader.publisherId');
tests["Response has publisher id"] = responseJSON.publisherId === 10003;
在测试"选项卡中,将您的响应正文解析为一个对象,然后使用 JavaScript 执行您的测试.
In the "Test" tab, parse your response body into an object, then use JavaScript to perform your tests.
var data = JSON.parse(responseBody);
tests["publisherId is 12345"] = data.responseHeader.publisherId === "12345";
看看 Postman 网站上的测试示例:
Take a look at the test examples at the Postman site:
https://www.getpostman.com/docs/postman/scripts/test_scripts
https://www.getpostman.com/docs/postman/scripts/test_examples
上一篇:令牌已过期或被撤销 - Google Ads令牌、已过期、Ads、Google
下一篇:我应该使用哪个凭证来生成令牌,然后使用 Postman 在 Keycloak DB 中创建用户?令牌、凭证、用户、Postman