How to handle dynamically changing response code when using data file?

Hi,

I have a requirement where I need to run a request with multiple data. So I created data.json file and running the test like this in command line - newman run test.json -d data.json

I need to check the response for each iteration and that is proving difficult because the response code changes for every iteration.

For example -

Iteration 1 using 1st set of data
This is good scenario and I expect status code to be 200.

Iteration 2 using 2nd set of data
This is bad scenario and I expect status code to be 400.

Iteration 3 using 3nd set of data
This is bad scenario and I expect status code to be 422.

I am not sure how to handle this.

Any suggestions would be very much appreciated.

Thanks in advance.

@Swaroop_Varma

You could code something like this …

if ( pm.info.iteration == 0  && pm.response.code == 200 ) {
     ....
}  
else if ( pm.info.iteration == 1  && pm.response.code == 400 ) {
    ....
} 
else if ( pm.info.iteration == 2  && pm.response.code == 422 ) {
    ....
} 
else {
    ....
}
2 Likes