Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run a Postman collection using Newman.
Postman
newman.run({ collection: require('[1]') }, function (err) { if (err) { throw err; } console.log('Collection run complete!'); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the file extension .json
Using just the collection name without path
Using a directory path instead of a file
✗ Incorrect
You need to provide the path to the collection JSON file. './mycollection.json' is the correct relative path with file extension.
2fill in blank
mediumComplete the code to specify an environment file when running a collection with Newman.
Postman
newman.run({ collection: require('./mycollection.json'), environment: require('[1]') }, function (err) { if (err) { throw err; } console.log('Run complete with environment!'); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing './' at the start of the path
Omitting the .json extension
Using a wrong filename
✗ Incorrect
The environment file path must be relative and include the .json extension, so './environment.json' is correct.
3fill in blank
hardFix the error in the code to run a collection with a timeout option.
Postman
newman.run({ collection: require('./mycollection.json'), timeout: [1] }, function (err) { if (err) { throw err; } console.log('Run complete with timeout!'); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number in quotes making it a string
Using a string like '5s' which is invalid
Using a small number like 5 which is 5 milliseconds
✗ Incorrect
Timeout must be a number representing milliseconds, so 5000 without quotes is correct.
4fill in blank
hardFill both blanks to run a collection and export the run summary to a file.
Postman
newman.run({ collection: require('[1]') }, function (err, summary) { if (err) { throw err; } require('fs').writeFileSync('[2]', JSON.stringify(summary)); console.log('Summary saved!'); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a filename without './' for collection
Saving summary as .txt instead of .json
Using inconsistent paths
✗ Incorrect
The collection path must be a JSON file with relative path './mycollection.json'. The summary file should be saved as './summary.json' to keep consistent relative path and JSON format.
5fill in blank
hardFill all three blanks to run a collection with environment and iteration count options.
Postman
newman.run({ collection: require('[1]'), environment: require('[2]'), iterationCount: [3] }, function (err) { if (err) { throw err; } console.log('Run complete with iterations!'); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using environment path without './'
Putting iteration count in quotes
Using wrong filenames
✗ Incorrect
The collection and environment paths must be relative with './' and .json extension. Iteration count is a number, so 3 is correct.