Runner, CSV, and automating response testing

Hi everyone, through extensive Googling I have discovered how to insert CSV columns into runner rows - simple in the end - but I cannot get response testing to work.

The runner CSV contains 76 columns of which 24 are mapped for inputs using the {{CaseSensitiveColumnName}} syntax in the request body.

I have used the following to be able to map the response body to the variables I need:

pm.test(“Test JSON response is correct”, ()=> {
let results = pm.response.json().outputs[0].results;
pm.expect(results.TotalPrice).to.equal(“{{TotalPrice}}”);
};

Using the console I can see that results.TotalPrice is parsed correctly, however I cannot get the test to replace {{TotalPrice}} with the value from the CSV. I have confirmed that there are no duplicate columns, and in the CSV TotalPrice is set to 220.54.

Any tips? What obvious and stupid thing am I doing wrong??

Thanks in advance!!!

You can’t reference variables using the handlebars method in scripts.

Have a look at the following…

Using variables in scripts - Postman Learning Center

and in particular…

Using data variables - Postman Learning Center

pm.expect(results.TotalPrice).to.equal(pm.iterationData.get("TotalPrice"));

You can also use the special data variable which contains a JSON representation of the current iterations data.

pm.expect(results.TotalPrice).to.equal(data.TotalPrice);

1 Like

Superstar!

I wasn’t expecting a different object/syntax for response parsing but I can confirm that switching to data.ColumnName works as expected.

Thank you!

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