1、6位随机数生成
需要用到for循环:
var Num="";
for ( var i=0;i<6; i++ )
{
Num += Math.floor(Math.random() * 10);
}
var Num = Math.floor(Math.random() * 10);
console.log(Num);
参考资料:https://stackoverflow.com/questions/4959975/generate-random-number-between-two-numbers-in-javascript
2、生成格式化时间:
方法一:
var moment = require('moment');
var data = moment().format(" YYYYMMDDHHmmss");
console.log(data);
方法二:
var myDate=new Date();
var year = myDate.getFullYear();
var month = myDate.getMonth() + 1;
var date = myDate.getDate();
var hours = myDate.getHours() + 1;
var min = myDate.getMinutes();
var seconds = myDate.getSeconds();
hours = hours < 10 ? "0" + hours : hours;
min = min < 10 ? "0" + min : min;
seconds = seconds < 10 ? "0" + seconds : seconds;
var date = year + "" + month + date + hours + min + seconds;
3、关联参数化
var jsonData = pm.response.json();
console.log(jsonData);
pm.globals.set("jwt",jsonData.jwt);
4、获取HTML页面的参数
const $ = cheerio.load(responseBody);
console.log($('input[name=lt]').val());
pm.globals.set("lt", $('input[name=lt]').val());
pm.globals.set("exc", $('input[name=execution]').val());
console.log($('input[name=execution]').val());
5、根据请求后的结果进行断言
pm.test("获取产品类型管理", function () {
var jsonData = pm.response.json();
pm.expect(jsonData[0].text).to.eql("产品类型管理");
console.log(jsonData[0].text);
});
6、异常和正常断言