Mopparthy Ravindranath
Mopparthy Ravindranath

Reputation: 3308

postman collection testing - how to use different test for different data rows

I am very new to the postman chrome application. Having understood a few basics, I have created a runnable collection with datafile (csv).

I am trying to test a simple GET request with one single param

localhost:4502/accserver/balance?userid={{userid}}

My CSV data file has 3 rows as below:

userid (header row)

root

rvnath

chacha420

My requirement is to test for different response status codes based on the data in the row. For example, if the data is 'root', the expected response is 200. For other rows, it should return 404.

As of nwo, I have written a simple test script as below:

tests['shd return 404 for non-existing user'] = responseCode.code === 404;

No clue, how to write test cases in such a way that they can test results based on data rows.

Any help?

Upvotes: 1

Views: 1125

Answers (2)

Sai Ram Reddy
Sai Ram Reddy

Reputation: 1089

You can do it like this. This worked for me

if (responseCode.code === 200) {
     // Tests if response code is 200

}

if (responseCode.code === 404) {
    // Tests if response code is 404
}

Thank you.

Upvotes: 0

Mopparthy Ravindranath
Mopparthy Ravindranath

Reputation: 3308

Since bob made a comment asking about the status of this qn, here is the answer.

Yes it is possible. With help from POSTMan support team, I was able to achieve this. The key to this is to create a CSV or JSON file, where one of the fields in each row contain the expected return codes.

For example, in my case the CSV file would be:

user,rcode
root,200
rvnath,404
chacha420, 404

The user name and response code would be available in my test scripts as variables, so I can write a test case such as:

tests['shd return 404 for non-existing user'] = responseCode.code === {{rcode}};

Upvotes: 1

Related Questions