I am trying to test a SOAP webserver with Postman and I was able to, but now I need to automate it.
Pre-Request Script
On pre-request script, I create a JSON structure to be possible to create more than one test at the same time and then I create a copy of that structure and update the values what I need and put that in a environments variables
Very nice setup! From what I see, I don’t think you can do what you are trying to achieve.
First, it looks like your proper syntax would be {{body.name}} or {{body.description}}. However, in the case when using for your XML body for your POST request, you can’t reference variable values in that same way. In a Pre-Request Script or Tests section, you can, but not here.
The variable reference pulls out strings, and not JSON objects, when being used in the raw request body.
I would suggest creating a “bodyName” variable, and a “bodyDescription” variable, which should then resolve this issue.
I will need to do that but I will try something more dynamic…I am thinking to create a function on global variables to create the environment variables for me…something like this…with this will be easier to send the values for the “postman body”
(jsonObject) => {
for ( var parameter in jsonObject ){
pm.environment.set(parameter, jsonObject[parameter]);
}
}
I think thats a good idea and should suffice. You can even do value teardown if you’d like in the tests section. This I believe would solve your issue where you need dynamic values.
You would just need to parse the jsonObject in the pre-request script using var jsonObject = JSON.parse(globalEnvJsonString) and then you can reference it as a json object natively.
Additionally, from your current example, you shouldnt have to loop through your jsonObject, unless there was an array, to assign the variable you can just use the following: