How to generate a random Variable and Pass it into a request Payload


“Email”: “{{agentEmail}}”,
“BVN”: “{{agentBVN}}”,

I want to generate a random email, phone number, and BVn. Then pass it into a request payload for API testing.

So I don’t need to keep manually changing the variable.

The ultimate random field would be timestamp. In this case:

long ts = System.currentTimeMillis()

String email = ts + ""

String payload = '{"Email":"' + email + '","PhoneNumber":"' + ts + '","BVN": "' + ts + '"}'

Not sure what is expected in BVN, but you can include any substring there.

Thanks, @Marek_Melocik.

I really appreciate your feedback. My concern is where will I add the script that will generate the random variable, before adding the variable name in my request payload.

All I am trying to say is, the random value generator will run first before the actual payload.

example like pre-requisite in postman.

Oh, you have your request stored in Object Repository, right? I don’t think there is support for something like Pre-request script in Postman.

But you can still change request body from a test case before you fire it.

RequestObject request = findTestObject("Misc/WStest")
request.setBodyContent(new HttpTextBodyContent(payload))


Is it suitable for you?

Thanks @Marek_Melocik I will try this.

Will give the update when i’m done.