GUID是“全球唯一标识符”的缩写。GUID主要用于生成由连字符分隔的十六进制数字组,以实现唯一性,例如:
b3d27f9b-d21d-327c-164e-7fb6776f87b0
在Postman中,您可以使用此功能根据需要生成并发送随机GUID到您的API:
{
"id": "{{$guid}}",
}
发送将会生成以下内容(使用上述随机示例):
{
"id": "b3d27f9b-d21d-327c-164e-7fb6776f87b0",
}
{{$guid}}
在每个请求时都会改变。 - bytedev如果您想生成一个V4 GUID,将其设置为环境变量,然后可以在整个集合中使用,您可以在预请求脚本中执行以下操作:
var uuid = require('uuid');
postman.setEnvironmentVariable('guid', uuid.v4());
您可以在整个集合中的多个调用中使用环境变量guid。这在您想要为整个集合生成一次guid并需要在多个请求中保持不变时非常有用。
如果您希望每个请求都生成guid,则可以像其他答案已经解释的那样,在负载中直接使用{{$guid}}。
基于Osloan在Github上的有趣回答:https://github.com/postmanlabs/postman-app-support/issues/886
使用{{$randomUUID}}
这样的变量在每个请求中进行更改。
postman.setEnvironmentVariable("Port", "80"); 2). 对于像SessionIdentifier这样的动态变量,您必须从响应中捕获并在测试中添加全局变量。从片段中看起来像:从片段中添加 "设置环境变量"...
要使用随机生成器,请在 pre-Request 中使用以下代码
var text="shipment";
var charset = "abcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 8; i++ )
text += charset.charAt(Math.floor(Math.random() * charset.length));
postman.setEnvironmentVariable("awb", text);
获取详细说明,请参阅下面的链接
http://jmeterblogb.blogspot.in/2016/10/how-to-automate-rest-api-in-postman.html