在Postman中,單個請求的腳本執行順序以下:json
對於一個集合裏的請求,將按如下順序執行session
集合pre → 夾pre → 請求pre → Request → Response → 集合Tests → 夾Tests → 請求Tests函數
var jsonData = JSON.parse(responseBody);//獲取body中返回的參數
var userId = jsonData.data.userId;//獲取resoponse中userId
console.log('userId: 'userId)post
tests["userId"] = jsonData.data.userId == 1100820blog
var userIdMd5 = CryptoJS.MD5(userId.toString()).toString();//放入md5函數轉化MD5值
console.log("userIdMd5:" +userIdMd5);
ip
var session = postman.getResponseHeader("x-hf-learn-session-id");
console.log('session-id:' +session)md5
pm.environment.set("userId",userId);
pm.environment.set("userIdMd5",userIdMd5);//設置轉化後MD5的userI爲環境變量
pm.environment.set("session", session);get
var pwd1 = CryptoJS.MD5('undefined').toString();io
console.log(pwd1);console
var pwd2 = CryptoJS.MD5('undefined').toString();
console.log(pwd2);
var passwd = CryptoJS.MD5(pwd1 + pwd2).toString() ;
console.log('passwd',passwd);
pm.environment.set("passwd",passwd);
var jsonData = JSON.parse(responseBody);//獲取body中返回的參數
var studentId = jsonData.data.students[0].studentId;//獲取resoponse中studentId
console.log('studentId: '+studentId)
pm.environment.set("studentId",studentId);