Set dynamic data for requestBody

1.3k Views Asked by At

I am unable to read request body while running a feature file:

Details:

user.json contains:

{"userId": "", "user":           {            "userName": ""          }}

I am setting these values to some random data generation using func:

util -> common-utilis.featurefunction() {return Java.type('util.Utilities').generateRandomString(4);}

Feature file to set up random values:

setupData.feature

Feature: Set random dataScenario: Set data* def requestBody = read('classpath:../template/user.json')

  #random data generation
* set requestBody.userId = "User_ID" + "_" + randomString()
* set requestBody.user.userName = "UserName" + "_" + randomString()

set up header details in seperate feature file:

header.featureFeature: Run Check

Scenario: Run Check* url BASE_URLGiven path 'user'And header Content-Type = 'application/json'And request requestBodyWhen method post

Scenario file:

userTest.feature

Feature: As a user, I want user service to support async call

Background: Setup

* def requestBody = callonce read('../template/setupData.feature')
* print requestBody
* def result = callonce read('../header.feature')
* print result
* def response = result.response
* def responseHeaders = result.responseHeaders

Scenario: Successful response for a request Then assert result.responseStatus == 200

What I tried so far:

  • I ran setupData.feature and can see system creates request body with random data successfully
  • I ran userTest.feature but system is displaying extra {} set

here is o/p while executing my feature file: (request body)

{"requestBody": {"userId": "User_Id_CsmY","user": {"userName": "UserName_PNKP"}}}

I can see extra {} and requestBody text

Not sure why these extra things are populated

0

There are 0 best solutions below