Reputation: 944
I have a data file with over 10,000 requests and I need it to loop through each test.
Example of text file:
text1~text2~text3
text1~text2~text3
etc.
My test script is:
pm.test("Status code is 200", function ()
{
pm.response.to.have.status(200);
}
);
if ((pm.response.json()[0].ResultCode)===-1)
{
pm.test("ResultCode -1 Matched!", function ()
{
pm.expect(pm.response.json()[0].ResultCode).to.equal(-1);
});
}
if ((pm.response.json()[0].ResultCode)===-5)
{
pm.test("ResultCode -5 Matched!", function ()
{
pm.expect(pm.response.json()[0].ResultCode).to.equal(-5);
});
}
So the first test works and the second test works, but it stops testing furthermore.
The is my output of the tests tab:
I know that it has tested all the requests, as the body shows all the results; i.e.:
[
{
"ResultCode": -1
},
{
"ResultCode": -1
},
{
"ResultCode": 200,
...
},
...
]
Upvotes: 0
Views: 8011
Reputation: 944
I found out that I can use a while
loop:
var i = 1;
while (i <=10)
{
if ((pm.response.json()[i].ResultCode)===200)
{
pm.test("Line " + i +" ~ ResultCode 200 Matched!");
}
i++;
}
This has worked perfectly.
Reference: Javascript Tutorial
Upvotes: 1