How do I print a variable value along with the string in the Test results

I want to print the variable value along with the string in the Test Results. How should I do that?
I tried different ways but I want to append that variable along with the string in pm.test

Hi @jagrutiwani0 ,

You are trying to print the variable value in the test name is it?

It’s the same way, you can access using pm.environment.get(“LeadID”)

pm.test("Response body contains the ID as " + pm.environment.get("LeadID"), function () {
          var jsonData = pm.response.json();
        pm.expect(jsonData.Id).to.eql(pm.environment.get("LeadID"));
    });

“+” is used to append the values in the Test name.

Please try this and let me know if you are facing any issue :blush:

1 Like

Hi @bpricilla ,

Thank you so much :slight_smile: It worked.

1 Like

Similar topic is discussed here. You can use replaceIn as well like,

pm.test(pm.variables.replaceIn("Response body contains the ID as {{LeadID}}"), function () {
          var jsonData = pm.response.json();
        pm.expect(jsonData.Id).to.eql(pm.environment.get("LeadID"));
    });
2 Likes

Okay, thanks!! I Will try with the replaceIn method also.

1 Like