如何比较邮递员中的响应与全局变量(How to compare response with global variable in postman)

编程入门 行业动态 更新时间:2024-10-07 05:22:58
如何比较邮递员中的响应与全局变量(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

更多推荐

本文发布于:2023-07-09 10:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮递员   全局变量   compare   response   variable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!