Running a collection with a Json file

I am trying to pass data from a JSON file, which has two data objects. In the test script in postman I select them through index positions. But when I run the tests through the runner I see the first iteration passes but in the output it would run the second index data which would show as failed. Is there anyway in the test output to not show the second tests under the first iteration results?

This is the actual response from the API

This is the json file I upload to the runner
JsonfileScreenshot

This is the result from the first iteration which includes the second iteration results as well (failed ones)

This is the result from the second iteration which includes the first iteration results as well (failed ones)

pm.test("Verify Person Name - Borrower", () => {
  const responseJson = pm.response.json();
  pm.expect(responseJson.response.validAccounts[0].firstName).to.eql(pm.iterationData.get('firstName'));
});

pm.test("Verify Account Number - Borrower", () => {
  const responseJson = pm.response.json();
  pm.expect(responseJson.response.validAccounts[0].accountNumber).to.eql(pm.iterationData.get('accountNumber'));
});

pm.test("Verify Account Number 14 - Borrower", () => {
  const responseJson = pm.response.json();
  pm.expect(responseJson.response.validAccounts[0].accountNumber14).to.eql(pm.iterationData.get('accountNumber14'));
});

pm.test("Verify Person Name - Co Borrower", () => {
  const responseJson = pm.response.json();
  pm.expect(responseJson.response.validAccounts[1].firstName).to.eql(pm.iterationData.get('firstName'));
});

pm.test("Verify Account Number - Co Borrower", () => {
  const responseJson = pm.response.json();
  pm.expect(responseJson.response.validAccounts[1].accountNumber).to.eql(pm.iterationData.get('accountNumber'));
});

pm.test("Verify Account Number 14 - Co Borrower", () => {
  const responseJson = pm.response.json();
  pm.expect(responseJson.response.validAccounts[1].accountNumber14).to.eql(pm.iterationData.get('accountNumber14'));
});

Hi @automationtester2496

You could probably get around it with an if statement… maybe…

pm.info.iteration would give you the current iteration number (starting at 0). So maybe you could do something like this;

1 Like

Thank you that was it.

1 Like