在邮递员中使用集合变量

编程入门 行业动态 更新时间:2024-10-27 00:25:52
本文介绍了在邮递员中使用集合变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

All the examples on learning.getpostman site show how to save variables at the global or environment level, in order to get a value from one request to another.

For example:

pm.environment.set(variableName:String, variableValue:String) pm.environment.get(variableName:String) pm.globals.set(variableName:String, variableValue:String) pm.globals.get(variableName:String)

respectively.

Is it possible to use Collections instead?

Reading the documentation about the pm. API doesn't give me much hope.

I am looking for something like this:

pm.collection.set(variableName:String, variableValue:String) pm.collection.get(variableName:String)

My goal is to be able to run two collections without cross-contamination.

解决方案

The latest Postman version available to update (7.9.0), ships with a new pm.collectionVariables function, this gives users more control over the way that they interact with Variables, at the Collection level.

Previously, you could only manually add these variables and then access them in the sandbox environment using the pm.variables.get("var_name") function.

The new pm.collectionVariables API method comes with the follows functions:

.get("var_name") .set("var_name", "var_value") .has("var_name") .unset("var_name") .clear() .toObject()

An example of the syntax would be this:

pm.collectionVariables.set("collectionVariable", "My Awesome New Collection Level Variable");

This is a basic example of setting a Collection level Variable from the Tests tab:

更多推荐

在邮递员中使用集合变量

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

发布评论

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

>www.elefans.com

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