postman常用JS语法
注册
var timestrip= Math.round(new Date()/1000).toString()
console.log(timestrip)
pm.environment.set("env_username","test"+timestrip)
注册名
pm.test("Status code is 200", function () { pm.response.to.have.status(200); pm.response.to.be.ok; pm.response.to.be.withBody; pm.response.to.be.json; }); pm.test("Body matches string", function () { // pm.expect(pm.response.text()).to.include("login success"); pm.expect(jasonData.msg).to.equal("login success!"); pm.expect(jasonData.token).to.lengthOf("40"); pm.expect(jasonData.code).to.eql(0); pm.response.to.have.status(200) }); 待续:。。。
jasonData=pm.response.json() pm.environment.set("token", jasonData.token); console.log(jasonData) console.log(jasonData.msg)
pm.test("Status code is 200", function () { pm.response.to.have.status(200); pm.response.to.be.ok; pm.response.to.be.withBody; pm.response.to.be.json; }); pm.test("Body matches string", function () { // pm.expect(pm.response.text()).to.include("login success"); pm.expect(jasonData.msg).to.equal("login success!"); pm.expect(jasonData.token).to.lengthOf("40"); pm.expect(jasonData.code).to.eql(0); pm.response.to.have.status(200) }); 待续:。。。