Postman Runtime
This is a low-level library used as the backbone for all Collection running & Request sending functionality, in
the Postman App, and allied systems (Postman Monitoring,
Newman)
If you are looking to execute collections, you should be using Newman, this is very low level.
Options
Postman Runtime supports a lot of options to customize its behavior for different environments and use-cases.
var runner = new runtime.Runner();
var collection = new sdk.Collection();
runner.run(collection, {
data: [],
timeout: {
request: 30000,
script: 5000
},
iterationCount: 1,
stopOnError: true,
abortOnError: true,
stopOnFailure: true,
abortOnFailure: true,
environment: new sdk.VariableScope(),
globals: new sdk.VariableScope(),
localVariables: new sdk.VariableScope(),
entrypoint: {
execute: 'folderName',
lookupStrategy: 'path',
path: ['grand_parent_folder_idOrName', 'parent_folder_idOrName']
},
delay: {
item: 1000,
iteration: 1000
},
fileResolver: require('fs'),
requester: {
cookieJar: jar,
followRedirects: true,
followOriginalHttpMethod: false,
maxRedirects: 10,
maxResponseSize: 1000000,
protocolVersion: 'http1',
useWhatWGUrlParser: true,
removeRefererHeaderOnRedirect: false,
strictSSL: false,
insecureHTTPParser: false,
timings: true,
verbose: false,
implicitCacheControl: true,
implicitTraceHeader: true,
systemHeaders: { 'User-Agent': 'PostmanRuntime' }
extendedRootCA: 'path/to/extra/CA/certs.pem',
network: {
hostLookup: {
type: 'hostIpMap',
hostIpMap: {
'domain.com': '127.0.0.1',
'ipv6-domain.com': '::1',
}
},
restrictedAddresses: {'192.168.1.1': true}
},
agents: {
http: {
agentClass: http.Agent,
agentOptions: { keepAlive: true, timeout: 399 }
},
https: new https.Agent({ keepAlive: true })
},
authorizer: {
refreshOAuth2Token: function (id, callback) {
},
}
},
script: {
serializeLogs: false,
packageResolver: function ({ packages /* sdk.Script.packages */ }, callback) {
return callback(null, {
pkg1: {
data: 'packagedata'
},
pkg2: {
error: 'Failed to get package'
}
});
}
},
proxies: new sdk.ProxyConfigList(),
systemProxy: function (url, callback) { return callback(null, {}) },
ignoreProxyEnvironmentVariables: false,
certificates: new sdk.CertificateList(),
systemCertificate: function() {}
}, function (err, run) {
console.log('Created a new Run!');
run.start(callbacks);
});
Callbacks
You can pass a series of callbacks for runtime to execute as a collection is being executed.
runner.run(collection, { }, function(err, run) {
run.start({
assertion: function (cursor, assertions) {
},
start: function (err, cursor) {
},
beforeIteration: function (err, cursor) {
},
iteration: function (err, cursor) {
},
beforeItem: function (err, cursor, item) {
},
item: function (err, cursor, item, visualizer, result) {
},
beforePrerequest: function (err, cursor, events, item) {
},
prerequest: function (err, cursor, results, item) {
},
beforeTest: function (err, cursor, events, item) {
},
test: function (err, cursor, results, item) {
},
beforeRequest: function (err, cursor, request, item) {
},
request: function (err, cursor, response, request, item, cookies, history) {
},
responseStart: function (err, cursor, response, request, item, cookies, history) {
},
responseData: function (cursor, data) {
},
response: function (err, cursor, response, request, item, cookies, history) {
},
exception: function (cursor, err) {
},
done: function (err) {
console.log('done');
},
console: function (cursor, level, ...logs) {},
io: function (err, cursor, trace, ...otherArgs) {
}
});
});