Heta Nanawala
Heta Nanawala

Reputation: 3

Set dynamic data for requestBody

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:

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

Upvotes: 0

Views: 1733

Answers (0)

Related Questions