Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a random string everytime a test runs in karate dsl

Tags:

dsl

karate

The json request I am sending is:

Given url applicationURL

And path 'applications'

And header Authorization = subscribeToken

And request:

    {
      "throttlingTier": "Unlimited",
      "description": "sample app description",
      "name": "TestbyKarate",
      "callbackUrl": "https:/apistore-dev-dev-a878-14-ams10-nonp.qcpaws.qantas.com.au/callback"
    }

When method post

Then status 201

* def applicationId = response.applicationId

* print 'applicationId is ', applicationId

I am sending the name in my request as TestbyKarate but I want to send a unique value every time my test runs.

Is there any way to do it?

like image 616
Sneha Shukla Avatar asked Jan 28 '23 11:01

Sneha Shukla


1 Answers

Can you please read the docs once. It will really benefit you.

https://github.com/intuit/karate#commonly-needed-utilities

So in the Background or common feature, you have:

* def now = function(){ return java.lang.System.currentTimeMillis() }

Then you can do this:

* def name = 'Test-' + now()
* request { name: '#(name)' }
like image 183
Peter Thomas Avatar answered Jan 31 '23 20:01

Peter Thomas