Why do I get an assertion error about status code?

I am getting the following errors:
There was an error in evaluating the test script: AssertionError: expected response to have status code 200 but got 409

I thought the following lines would cover that scenario?

if (pm.response.to.have.status(200)){
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    })
} else if (pm.response.to.have.status(409)){
    pm.test("Status code is 409", function () {
        pm.response.to.have.status(409);
    })
}

Hey @ameenjafferie :wave:

You’ve used a Postman helper as your conditional check. I think you’re probably trying to do something like this:

if (pm.response.code === 200){
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    })
} else if (pm.response.code === 409){
    pm.test("Status code is 409", function () {
        pm.response.to.have.status(409);
    })
}
2 Likes

Thank you - worked like magic!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.