如何比较邮递员中的响应与全局变量(How to compare response with global variable in postman)
我有一个在邮递员中定义的全局变量,我正在发布一个帖子请求。 我想知道响应是否包含我在全局变量中设置的值。
pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include({{sample_message}}); });sample_message是全局变量
我怎么比较? 提前致谢
I have a global variable defined in postman and I am making a post request. I would like to know whether the response will contain the value that I had set in the global variable.
pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include({{sample_message}}); });sample_message is the global variable
How can I compare?? Thanks in advance
最满意答案
我在网上进行了大量的研究后得到了解决方案
pm.test("Body matches string", function () { pm.expect(jsonData.data.message_content).to.eql(pm.environment.get("sample_message")); });这个pm.environment.get("sample_message")将获取全局变量的值
资料来源: Postman编写测试
I got the solution after lot of research in web
pm.test("Body matches string", function () { pm.expect(jsonData.data.message_content).to.eql(pm.environment.get("sample_message")); });This pm.environment.get("sample_message") will fetch the value of the global variable
Source : Writing tests in Postman
更多推荐
发布评论