创建一个文件以加载到 Postman Collection Runner,具有以下结构:
[{
"testSequence": ["First request name", "Second request name", "..." ],
"anyOtherData": "Whatever the request needs",
"evenMoreData": "Whatever the request needs",
"...": "..."
},{
"testSequence": ["Login", "Check newsfeed", "Send a picture", "Logout" ],
"username": "Example",
"password": "correcthorsebatterystaple",
},{
"...": "keep the structure for any other test scenario or request sequence"
}]
将所有测试序列放入该文件中,然后让 Postman 在每个请求后检查列表并决定接下来要执行什么。这可以做到 e。 G。在整个集合的“测试块”中:
// Use the mechanism only if there is a test scenario file
// This IF prevents the block from firing when running single requests in Postman
if (pm.iterationData.get("testSequence")) {
// Is there another request in the scenario?
var sequence = pm.globals.get("testSequence");
if ((sequence instanceof Array) && (sequence.length > 0)) {
// If so, set it as the next one
var nextRequest = sequence.shift();
pm.globals.set("testSequence", sequence);
postman.setNextRequest(nextRequest);
} else {
// Otherwise, this was the last one. Finish the execution.
postman.setNextRequest(null);
}
}
如果您的请求在不同的运行过程中需要使用不同的数据,您可以在输入文件中定义数据,并在请求中使用variables。