I'm using postman tests section to automate the APIs
If the response parameter is something like this "currency": "USD",
, then we assert this by pm.expect(jsonResponse.currency, 'USD');
But if the response parameter is something like this "super-card.DCC": "false",
, in which key has -
, .(dot)
in it.
Then asserting like this pm.expect(jsonResponse.postingAttributes.super-card.DCC, false);
is not working.
Its failing with ReferenceError: card is not defined
Can anybody help me here?
For JSON properties like these, you need to use bracket notation to access the value:
pm.expect(jsonResponse.postingAttributes["super-card.DCC"], false)
You're not actually asserting anything here though, as long as the property is in the JSON response structure, it will pass the "test", regardless of the value.
As an example, this endpoint returns the request information and I'm sending a GET
request here. Adding the same script as you have, you can see this is passing:
The second argument in the pm.expect()
function is an optional message that would be shown if the test failed.
You would need to use:
pm.expect(jsonResponse.postingAttributes["super-card.DCC"]).to.equal("false")