while i put assertion on this request i am getting error as it says it does not match the value of statusCode and when i console the json response its giving me different response
Below is my assertion test
pm.test("Validate status message 'ER_BAD_FIELD_ERROR'", function () {
var responseJSON = actualResponse.json();
console.log(responseJSON, "error")
pm.expect(responseJSON.statusCode).to.equal("ER_BAD_FIELD_ERROR");
});
Would you be able to confirm what actualResponse.json() is referencing in that test?
Wouldn’t this work for you:
pm.test("Validate status message 'ER_BAD_FIELD_ERROR'", function () {
var responseJSON = pm.response.json();
console.log(responseJSON, "error")
pm.expect(responseJSON.statusCode).to.equal("ER_BAD_FIELD_ERROR");
});
As i have used this response in a function parameter as below
function invalidAddress(actualResponse){
pm.response = actualResponse
pm.test("Validate status message 'Resource Not Found'", function () {
var responseJSON = actualResponse.json();
pm.expect(responseJSON.statusMessage).to.be.oneOf(["Resource Not Found", "Validation Error" ])
});
}
I don’t really have the full script or context here.
Could you include all the relevant information please?
Is that single request used to test multiple different error scenarios? How’s the function being called? Do you have repeated variable usage in that script and the console message is from elsewhere?
You are passing in a parameter called actualResponse.
The next line “pm.response = actualResponse” appears to be backwards.
pm.response is a Postman function and is unmutable. You’re trying to overwrite it with the actualResponse value.
I think you meant…
let actualResponse = pm.response
But you can’t really do that either, as you are already passing in a parameter called actualResponse, so it can’t have the same name.
With the info provided so far, I can see no good reason for this to be a function as you don’t seem to be using the parameter you are passing into the function.
Create this is a normal test before you try to create a re-usable function.