添加有关如何运行从同一请求驱动的数据的另一个答案:
创建一个名为“csv”的环境变量并复制以下内容并将其粘贴为值:
username,password,error_message,error_code
username1,password1,errormessage1,errorcode1
username1,password1,errormessage1,errorcode1

现在在 pr-request 中添加:
if (!pm.variables.get("index")) {
const parse = require('csv-parse/lib/sync')
//Environmental variable where we copy-pasted the csv content
const input = pm.environment.get("csv");
const records = parse(input, {
columns: true,
skip_empty_lines: true
})
pm.variables.set("index", 0)
pm.variables.set("records", records)
}
records = pm.variables.get("records")
index = pm.variables.get("index")
if (index !== records.length) {
for (let i of Object.entries(records[index])) {
pm.variables.set(i[0], i[1])
}
pm.variables.set("index", ++index)
pm.variables.get("index")===records.length?null:postman.setNextRequest(pm.info.requestName)
}
现在,您可以运行针对该特定请求的数据驱动:
例如收集:
https://www.getpostman.com/collections/eb144d613b7becb22482
使用与环境变量内容相同的数据,现在使用 collection runner 或 newman 运行集合
输出
