有没有办法将多个环境变量输入 url 以在 Postman 上进行测试?

Is there a way to input multiple environment variables into a url for testing on Postman?

我正在使用这样的 url 在 Postman 中测试端点,{{api_url}}/Whosebug/help/{{customer_id}}/{{client_id}}。 我将 api_urlcustomer_idclient_id 存储在我的环境变量中。我想测试多个 customer_idclient_id 而不必每次都手动更改环境变量。我创建了一个 csv 来存储 customer_id 的列表和一个存储 client_id 的列表。当我转到 运行 collection 时,它只允许我添加一个文件。如果我想遍历我的测试以自动化它们,还有其他方法可以做到这一点吗?

您可以在一个 csv 文件中同时添加 customer_idclient_id。 Postman 将迭代 n 次(n = csv 行数,header 除外)

可以使用postman.setNextRequest来控制流量。下面的代码在 arr 变量

中运行具有不同值的请求

url:

{{api_url}}/Whosebug/help/{{customer_id}}/{{client_id}}

现在添加预请求:

// add values for the variable in an array
const tempArraycustomer_id = pm.variables.get("tempArraycustomer_id")
const tempArrayclient_id = pm.variables.get("tempArrayclient_id")

//modify the array to the values you want
const arrcustomer_id = tempArraycustomer_id ? tempArraycustomer_id : ["value1", "value2", "value3"]
const arrclient_id = tempArrayclient_id ? tempArrayclient_id : ["value1", "value2", "value3"]


// testing variable to each value of the array and sending the request until all values are used

pm.variables.set("customer_id", arrcustomer_id.pop())
pm.variables.set("client_id", arrclient_id.pop())

pm.variables.set("tempArraycustomer_id", arrcustomer_id)
pm.variables.set("tempArrayclient_id", arrclient_id)


//end iteration when no more elements are there
if (arrcustomer_id.length !== 0) {
    postman.setNextRequest(pm.info.requestName)
}