本文为霍格沃兹测试开发学社学员学习笔记分享
原文链接:https://ceshiren.com/t/topic/27801
//获取响应数据的json对象
var jsonData = pm.response.json();
//从json对象中提取token值
var token = jsonData.data.token;
//把token值设置为测试集变量
pm.collectionVariables.set("token", token);
// 构造登录请求
const loginRequest = {
url: 'http://litemall.hogwarts.ceshiren.com/wx/auth/login',
method: "POST",
header: 'Content-Type: application/json',
body: {
mode: 'raw',
raw: JSON.stringify({'username': 'user123', "password": "user123"})
}
};
// 发送请求
pm.sendRequest(loginRequest, function (err, response) {
if (err) {
console.log(err);
} else {
console.log(response.json());
pm.collectionVariables.set("token", response.json().data.token);
}
});