【发布时间】:2019-12-23 19:03:02
【问题描述】:
我有一个场景,我需要将主体值传递给环境变量并在另一个 API 中使用这些值。在邮递员中
下面是身体,
{
"firstName" : "Firstname",
"lastName" : "lastname",
"email" : "{{timestamp}}@test.com",
"password" : "{{timestamp}}",
"country" : 8l16
}
下面是 Pre-req 脚本,
postman.setEnvironmentVariable("timestamp", (new
Date).getTime());
// I have copied the Bodyand paste it in a variable called Obj in
Pre-req
// Then i used the below script to get the body
pm.environment.set("rawBody", JSON.stringify(obj));
但 timestamp 、 email 和 password 的环境值如下。时间戳值正确,其他两个错误。
timestamp = 1566076106769
email = {{timestamp}}@test.com
password = {{timestamp}}
时间戳值没有被替换为电子邮件和密码,我希望将环境变量值设置为,
预期值,
email = 1566076106769@test.com
password = 1566076106769
那么如何将 body 元素值分配给环境/全局变量以在另一个 API 调用中使用?
【问题讨论】:
-
您使用的是哪个版本的 PostMan?您的代码按预期为我工作,除了行 pm.environment.set("rawBody", JSON.stringify(obj));
标签: postman postman-collection-runner