1、设置全局变量
pm.globals.set("variable_key", "全局变量");
2、设置环境变量
pm.environment.set("environment_variable_key", "环境变量");
3、获取全局变量
pm.globals.get("URL");
4、获取环境变量
pm.environment.get("environment_variable_key");
5、获取变量
pm.variables.get("variable_key");
6、清除全局变量
pm.globals.unset("variable_key");
7、清除环境变量
pm.environment.unset("environment_variable_key");
8、发送一个请求
8.1、发送不带参数的get请求
pm.sendRequest("https://postman-echo.com/get", function (err, response) {
console.log(response.json());
});
8.2、发送带Json参数的post请求
// 构造请求
const CreateOrder = {
url: 'https://xxx/lumos/InitOrder/CreateOrder',
method: "POST",
header: {"Content-Type": "application/json", "entid": "UAT01", "shopno": "BU-00002", "userid": "ID-000035"},
body: {
mode: 'raw',
raw: JSON.stringify({'orderType': 'L','storeName': '南瓜店','username': '南瓜'})
}
};
// 发送请求
pm.sendRequest(CreateOrder, function (err, response) {
console.log(err ? err: response.json());
});
8.3、发送带params参数的post请求
// 构造请求
const CreateOrder = {
url: 'https://xxx/lumos/InitOrder/CreateOrder',
method: "post",
header: {"Content-Type": "application/json", "entid": "UAT01", "shopno": "BU-00002", "userid": "ID-000035"},
body: {
mode: 'urlencoded',
urlencoded: "storeName=南瓜店&username=南瓜"
}
};
// 发送请求
pm.sendRequest(CreateOrder, function (err, response) {
console.log(err ? err: response.json());
});