0

i am using Postman and I have some tests(assertions) in my request. When any test fails, i get an error like the following:- AssertionError: expected response to have status code 400 but got 200

I want to store this exact error text in a string variable i-e my variable should have the value

MyVariable = AssertionError: expected response to have status code 400 but got 200

I was expecting a postman built-in variable which stores this error but didnt find any.

1 Answers1

0

Using try catch

let error;
pm.test("Status code is 200", function () {
    try {
        pm.response.to.have.status(200);
    }
    catch (err) {
        error = err
    }

});


const {message} = error;
console.log(message)

After that you can set a variable as

pm.environment.set("message",message)
Rebecca
  • 11
  • 2