Include variable in pm.test

Hi all,

I am trying to display a variable {{OUTPUT}} to my test query.

pm.test("Status code is 202 {{OUTPUT}}", () => {

  pm.response.to.have.status(202);

});

The exported json output file would then display the status message followed by the output variable, as below.

"allTests": [
				{
					"Status code is 202 {{OUTPUT}}": true
				},

The variable is only contained within the request body / header and also within the file used for the runner.

Any help is much appreciated.

1 Like

@Col Welcome to the community :partying_face:

You can try this way:

pm.test("Status code is 202 " + pm.environment.get("OUTPUT"), function () {

    pm.response.to.have.status(202);
});

Change the scope of the variable you have used, if its not environmental variable. Please let me know if you have any issues :slight_smile:

2 Likes

you can try as @bpricilla mentione or can use replacein

  pm.test(pm.variables.replaceIn("Status code is 202 {{OUTPUT}}"), () => {

      pm.response.to.have.status(202);

    });
6 Likes