最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Postman getting random UserName inside Pre-Request Scripts - Stack Overflow

programmeradmin5浏览0评论

I'm wanting to generate a random user to be created using the API, every time I run the request.

I have an email environment variable which I want to be set to a random email every time the user create request is sent.

I currently have:

pm.environment.set("Email", pm.globals.get("$randomUserName") + "@myDomain.co.uk");

I'm wanting to get a random user name from $randomUserName

However, I can't seem to find out how to get a value from $randomUserName in the Pre-Request Scripts section.

I'm wanting to generate a random user to be created using the API, every time I run the request.

I have an email environment variable which I want to be set to a random email every time the user create request is sent.

I currently have:

pm.environment.set("Email", pm.globals.get("$randomUserName") + "@myDomain.co.uk");

I'm wanting to get a random user name from $randomUserName

However, I can't seem to find out how to get a value from $randomUserName in the Pre-Request Scripts section.

Share Improve this question edited Mar 6, 2020 at 17:52 Leon W asked Mar 6, 2020 at 17:19 Leon WLeon W 1571 gold badge2 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 15

You can use the .replaceIn() method in the sandbox.

You could do something like this:

let userName = pm.variables.replaceIn("{{$randomUserName}}")
pm.environment.set("Email", `${userName}_${Date.now()}@myDomain.co.uk`)

More info can be found here:

https://learning.postman./docs/postman/scripts/postman-sandbox-api-reference/#pmvariables

发布评论

评论列表(0)

  1. 暂无评论