在Linux下使用Postman编写自动化脚本主要有以下两种方式:
pm.test("Status code is 200", function() { pm.response.to.have.status(200); });
用于验证状态码。pm.environment.set("变量名", "值");
设置环境变量,在请求中使用{{变量名}}
引用。npm install -g newman
。run - tests.js
,内容为const newman = require('newman'); newman.run({ collection: 'path/to/your/collection.json' }, function(err, summary) { if (err) { console.error(err); return; } console.log(summary); });
。node run - tests.js
。