1. newman 命令行方式運(yùn)行Collection
- 選中Collection --》 點(diǎn)擊... ---》Export ---》選擇Collection Format钦扭。(導(dǎo)出之后是 .json格式坤按,例如:OpenAPI-Gists.postman_collection.json)或者選中Collection--》Share---》Collection Link---》復(fù)制link
- 下載所有環(huán)境變量文件Download Environment
- 下載全局變量文件Download as JSON
# 安裝 newman
npm install -g newman
newman --version # 3.5.2
npm update -g newman # 升級(jí)到最新的版本3.8.3
# newman命令行運(yùn)行導(dǎo)出的collection.json或者collection link
newman run OpenAPI-User.postman_collection.json -e gitee.com.postman_environment.json
# -e <source> --environment, Specify an environment file path or URL 指定測(cè)試環(huán)境
# --global-var 指定全局變量锦庸,可以指定多個(gè)例如:--global-var "key1=value1" --global-var "key2=value2"
- 報(bào)錯(cuò)1: .json文件中postman請(qǐng)求中引用的環(huán)境變量和全局變量找不到---》通過(guò)添加參數(shù)指定環(huán)境變量和全局變量解決。
- 報(bào)錯(cuò)2: ReferenceError:pm is not defined---》通過(guò)升級(jí) newman 到最新版本后解決了另患。
2. Using Newman as a NodeJS module
var newman = require('newman'); //加載newman模塊
// call newman.run to pass `options` object and wait for callback
// options對(duì)象盏袄,由很多屬性鍵值對(duì)組成
newman.run({
collection: require('./sample-collection.json'), // 加載Colllection文件
reporters: 'cli', // Available reporters: cli, json, html and junit. 指定輸出方式
environment: require('./gitee.com.postman_environment.json'), //加載環(huán)境文件
globals: require('./globals.postman_globals.json'), //加載全局變量文件
iterationCount: 1 //重復(fù)次數(shù),默認(rèn)1
}, function (err) {
if (err) { throw err; }
console.log('collection run complete!'); // 始終輸出此結(jié)束語(yǔ)
});
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者