Reputation: 85
I am trying to create Karate feature file for API Testing. It is a post request and we have to pass random number for 1 field i.e. order in request payload every time. Now, I am trying to use this function in the same feature file to pass that random generated value in json payload before sending post request.
Could someone please have a look at my feature file and help. Thanks
Also, Is there a way if i want to pass this same random value for a json payload created as a separate request.json payload file
Upvotes: 1
Views: 760
Reputation: 58078
Your requestPayload
is within double quotes, so it became a string.
Here's an example that should get you going. Just paste it into a new Scenario
and run it and see what happens.
* def temp1 = 'bar'
* url 'https://httpbin.org/anything'
* def payload = { foo: '#(temp1)' }
* request payload
* method post
And please read the documentation and examples, it will save a you a lot of time.
Upvotes: 1