Complete the code to load a CSV data file in Postman.
pm.test('Load CSV data file', function () { const data = pm.iterationData.[1](); pm.expect(data).to.not.be.undefined; });
In Postman, pm.iterationData.toJSON() converts the CSV or JSON data file row into a JSON object for easy access.
Complete the code to access the 'username' field from the current data row in Postman.
const username = pm.iterationData.get('[1]');
The key used to access the username field must match the column header in the CSV or JSON data file, which is 'username'.
Fix the error in the code to correctly iterate over data rows in Postman tests.
pm.test('Check data rows', function () { for (let i = 0; i < pm.iterationData.[1]; i++) { const email = pm.iterationData.get('email'); pm.expect(email).to.include('@'); } });
The pm.iterationData object has a length property to get the number of data rows. Using length() or other terms causes errors.
Fill both blanks to create a test that checks if the 'status' field equals 'active' for each data row.
pm.test('Status is active', function () { const status = pm.iterationData.get('[1]'); pm.expect(status).to.be.[2]('active'); });
The field name is 'status' and the assertion method is equal to check exact equality.
Fill all three blanks to create a test that verifies the 'age' field is greater than 18 for each data row.
pm.test('Age check', function () { const age = parseInt(pm.iterationData.get('[1]'), 10); pm.expect(age).to.be.[2]([3]); });
The field name is 'age'. The Chai assertion method to check greater than is above. The value to compare is 18.