Reputation: 6354
I am using some of the auto generated parameters in my request body in a postman request(i.e: {{$guid}}
).
I would like in my test to retrieve the request that was sent to the server to compare what this variable value was, and what the response parroted back to me me in my request.
for example, my request's body looks like this:
{
"Description": "testing this {{$guid}}"
}
and I would in the tests be able to do:
var req = JSON.parse(requestBody);
var resp = JSON.parse(responseBody);
test['description should match'] = req.Description === resp.Description;
is this doable?
Upvotes: 2
Views: 2220
Reputation: 1107
This is possible.
But you have several small syntax errors.
To access the request body data use:
var req = JSON.parse(request.data);
I named the variable req
to not be confused with the predefined request
variable. You can log the result like this:
console.log(req.Description);
In the tests tab make sure you reference the correct variable tests
with "s". Also you pass the test case name as a string e.g. "description should match"
.
var res = JSON.parse(responseBody);
console.log(res.Description);
tests["description should match"] = req.Description === res.Description;
Upvotes: 2