Given this test script in Postman that runs with a CSV data file containing two rows:
pm.test('Check user ID', () => {
pm.expect(pm.iterationData.get('userId')).to.be.oneOf(['101', '102']);
});What will be the result after running the collection with this CSV data?
pm.test('Check user ID', () => { pm.expect(pm.iterationData.get('userId')).to.be.oneOf(['101', '102']); });
Think about how Postman runs tests for each row in a data file.
Postman runs the test script once per data row. Since the CSV has two rows with userId values '101' and '102', and the test checks if the userId is one of these, the test passes twice.
You have a JSON data file with entries like {"username": "alice"}. Which assertion in the test script correctly checks that the username is 'alice' for the current iteration?
Remember the method to get data from the current iteration in Postman.
pm.iterationData.get('key') is the correct way to access data from the current iteration, regardless of CSV or JSON data files.
Consider this test script:
pm.test('Check email', () => {
pm.expect(pm.iterationData.email).to.include('@');
});When running with a JSON data file containing emails, the test always fails. What is the cause?
pm.test('Check email', () => { pm.expect(pm.iterationData.email).to.include('@'); });
Check how to properly access iteration data in Postman scripts.
pm.iterationData is a method object, not a plain object. You must use pm.iterationData.get('email') to access the value. Using pm.iterationData.email returns undefined, causing the assertion to fail.
Which step correctly describes how to run a Postman collection using a JSON data file?
Think about how Postman uses data files in the Collection Runner.
Postman Collection Runner allows you to select a data file (CSV or JSON) to run the collection multiple times with different data. You select the file in the runner before starting.
When using CSV and JSON data files in Postman Collection Runner, what is the key difference in how data is accessed in test scripts?
Consider the Postman API for accessing iteration data regardless of file type.
Postman abstracts data file format differences. Both CSV and JSON data files are accessed in test scripts using pm.iterationData.get('key').