I'm working with API project and writing test cases with Postman for automation to check API status. Here I have one upload method in which user has to upload a file to the server and need to check if the server returns an appropriate response.
Upload method accepting the request with multipart/form-data, from Postman I'm passing as below screen:
I believe that in order to write a test case, I need to write a pre-request script.
pm.sendRequest({
url: pm.environment.get("baseURL") + '/document/upload',
method: 'POST',
header: [{
"key": "Authorization",
"value": pm.environment.get("authorization"),
"type": "text",
}],
body: {
mode: 'formdata',
formdata: [{
"key": "file",
"type": "binary",
"src": "C:\Users\Desktop\api.pdf"
}]
}
}, function(err, res) {
console.log(res);
});
However, the method is getting hit two times, any thoughts to make it correct and hit only once?