-
Place the files you want to upload in a location.
Say, I want to upload below two json files from C:\here
prod.json
str.json -
Create a csv data file ( file.csv ) and place the file names you want to upload as shown below
- In your Pre-request script, add set a variable as shown below
pm.environment.set(“filepath”,data._filepath);
- Open your collection.json file and you will find the below formdata where you have selected the file location as shown below
“method”: “POST”,
“header”: ,
“body”: {
“mode”: “formdata”,
“formdata”: [
{
“key”: “File”,
“type”: “file”,
“src”: “/C:/here/prod.json”
}
here, modify “src”: “/C:/here/prod.json” to “src”: “{{filepath}}”
- Now navigate to the path where you have the files and want to upload. So, in my case I navigated to C:\here and launched cmd from here and executed below command.
newman run --insecure <collection_path>\Products.postman_collection.json -d \file.csv -r htmlextra --reporter-htmlextra-export “<Report_path>\Fileupload.html” --reporter-htmlextra-title “<Report_Name>”
Now my test will run with two iteration as shown below
Iteration1 - you will find the Request body as
{
“File”: “prod.json”
}
Iteration2 - you will find the Request body as
{
“File”: “str.json”
}
Hope, this solution helps us in not selecting a static file and upload all the desired files from selected location