最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Run several requests with different number of data from csv on Postman - Stack Overflow

programmeradmin4浏览0评论

I have one .csv file with some data for my Postman like this:

Name,City
Jhon,New York
Lucy,London
Adam,
Alex,

and i have one collection with 2 reqs:

 - GetAge
{
{{Name}}
}


- GetInfoCity
{
{{City}}
}

How can i run my collection with .csv file to run first 4 times req1 (GetAge) and then 2 times req2 (GetInfoCity), using a data for my .csv file?

Thanks

I have one .csv file with some data for my Postman like this:

Name,City
Jhon,New York
Lucy,London
Adam,
Alex,

and i have one collection with 2 reqs:

 - GetAge
{
{{Name}}
}


- GetInfoCity
{
{{City}}
}

How can i run my collection with .csv file to run first 4 times req1 (GetAge) and then 2 times req2 (GetInfoCity), using a data for my .csv file?

Thanks

Share Improve this question asked Mar 17 at 17:16 Oren DiazOren Diaz 1438 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

I'll post the same answer that I put on the Postman forum.

As you will always have the name, you don’t need to do anything particular with the first request. You just let it run normally.

You can use the skipRequest() function to skip the City request if the data is missing from the CSV file.

let currentCity = pm.iterationData.get("City");

if (currentCity === undefined || currentCity === null || currentCity === '') {
    console.log(`${pm.info.requestName} : No City - skipping request`)
    pm.execution.skipRequest();

} else {
    pm.environment.set("City", currentCity);
    console.log(`${pm.info.requestName} : ${pm.environment.get("City")}`)
}
发布评论

评论列表(0)

  1. 暂无评论