i cant do my download/upload file-requests via collection runner, because i manually have to choose a file in body everytime before.
This leads to two different ideas of getting this problem done:
1: Is it possible to set Body-Key/Value(File) via Pre-Request script?
For example:
Before request, do:
set Value to Key âcontentâ, Value âFile - please Chooseâ to "C:âŠ"
Then do the request
Then do Test
Because if this would be possible i could do my automated testing via Postman Runner without newmanÂĄ
Idea 2 of getting this problem done: Use Newman.
I tried. its Newman run âCOLLECTIONâ -e âENVIRONMENTâ --globals âGLOBALSâ
I linked my collection, env and globals in it and newman starts its run. My tests in Postman contain a lot of variables which i fill during the test. Every Testcase in newman crashes because every variable (which runs perfectly fine via postman) is âundefinedâ in newman and the test is failedâŠ
Maybe someone can give me a tip if my idea with the pre-request-script is possible (and how, cause i triedâŠ) and/or where my mistake is with my approach to newman.
Looking at the responses, when a JSON responseBody is returned, it does not contain a âresultsCountâ variable so therefore ⊠var resultCount would be âundefinedâ.
the code i provided in the first place with a lot of variables was NOT for a upload or download endpoint. this is just a simple âget 200 activities and list them for meâ endpoint. which works perfectly fine in postman, and the variables are filled in postman - but not in newman. I would love to know why.
The other problem i have is that i want to automate upload-endpoints in postman (which is technically kinda impossible) but my idea would be to set the file in the request-header (which should be uploaded) via pre-request script. is this possible?
This is a hunch, javaScript is funky compared to straight java ⊠Try this âŠ
var request = JSON.parse(responseBody);
var resultCount = request.resultsCount;
var result1 = "";
var result2 = "";
var result3 = "";
if (resultCount > 0) {
result1 = ", " + request.result[0].description;
}
if (resultCount > 1) {
result2 = request.result[1].description;
}
if (resultCount > 2) {
result3 = ", ...";
}
I believe that defining the same variable names using âvarâ within the âifâ constructs causes those variables to be âlocalâ only to the code within the construct so if you get rid of the âvarâ declaration, it will use the "vars"s that are defined globally to the program.
As far as your âuploadâ problem, Iâm not sure if POSTMAN can handle that depending upon how the endpoint is designed and where it looks for the file to upload.
Here i have to choose manually before the execution of the request. its not possible to set this damn variable (the file-adress) via pre-request script?