如何验证邮递员的回复? [英] How to validate response in Postman?

查看:118
本文介绍了如何验证邮递员的回复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证响应正文,包括邮递员中的错误。如何验证下面的响应和文本?

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/脚本/测试脚本

https://www.getpostman.com/docs/postman/scripts/test_examples

这篇关于如何验证邮递员的回复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆