我正在使用一个用于创建和测试虚拟机的私有云平台。它们有丰富的API,允许我创建VM:
{
"name": "WIN2016-01",
"description": "This is a new VM",
"vcpus": 4,
"memory": 2147483648,
"templateUuid": "sdsdd66-368c-4663-82b5-dhsg7739smm",
...
}我需要通过简单地迭代-01部件来自动化创建机器的过程,因此它变成了:
我试着使用Postman并构建工作流workflows/,但是没有运气--不确定我需要在测试选项卡中使用什么语法。
发布于 2019-01-24 09:30:16
这是一种方法。
创建一个集合和发布请求。
在pre-request中添加以下内容:
/* As this will be run through the Collection Runner, this extracts
the number of the current iteration. We're adding +1, as the iteration starts from 0.*/
let count = Number(pm.info.iteration) + 1;
//Convert the current iteration number, to a '00' number format (will be a string)
let countString = ((count) < 10) ? '0' + count.toString() :
count.toString();
//Set an environment variable, which can be used anywhere
pm.environment.set("countString", countString)在您的帖子请求体中,可以这样做:
{
"name": "WIN2016-{{countString}}",
...
}现在,通过'Collection Runner‘运行您的集合,并输入迭代的次数(例如,您希望您的集合运行多少次)。您还可以添加一个延迟,如果您的API施加了速率限制。
最后,单击Run。
https://stackoverflow.com/questions/54325589
复制相似问题