【pre-request script】
//获取当前时间,并设置环境变量
eval(globals.format_time);
pm.globals.set("timeNow",timeNow);
//获取当前时间到时分秒
var dateNow = pm.globals.get("timeNow");
//切割当前时间,获取年月日,不要时分秒(8位)
var date = dateNow.split(" ")[0].split("-")[0]+
dateNow.split(" ")[0].split("-")[1]+dateNow.split(" ")[0].split("-")[2];
//切割当前时间,获取时分秒,不要年月日(6位)
var time = dateNow.split(" ")[1].split(":")[0]+
dateNow.split(" ")[1].split(":")[1]+dateNow.split(" ")[1].split(":")[2];
//切割当前时间,获取年月日+固定时分秒
var datetime = dateNow.split(" ")[0]+" 23:59:59";
//设置环境变量开始时间和结束时间
pm.globals.set("date",date);pm.globals.set("time",time);pm.globals.set("datetime",datetime);
console.log("当前日期:"+date,"当前时间:"+time,"--当前日期和时间:"+timeNow,datetime);
【Tests】
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
pm.test("Body matches string", function () {
pm.expect(pm.response.text()).to.include("北京");
});