4

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?

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
Sneha Shukla
  • 373
  • 1
  • 4
  • 19

2 Answers2

8

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)' }
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Peter can you tell how do we print request body? to confirm whats going in the request ? * print request does not work – Gaurav Khurana Mar 08 '21 at 14:08
  • 1
    @Gauravkhurana maybe you are looking for `karate.prevRequest` - https://stackoverflow.com/a/62510900/143475 – Peter Thomas Mar 08 '21 at 15:46
  • @PeterThomas sir can you add ready to use variables that like generate email, string, or fullName like postman, it will really help us – roudlek Aug 07 '23 at 10:11
  • @roudlek read the docs please: https://github.com/karatelabs/karate#commonly-needed-utilities – Peter Thomas Aug 07 '23 at 10:12
0

check below example

Feature: Create User Name

Scenario: UserName with unique Name

  • def getDate = """ function(){ return java.lang.System.nanoTime() } """

    • def time = getDate()

    • def userName = 'createUser' + time + '_Test'