How to call endpoint several times for each json request from array

Viewed 38

I need to call feature from another with passing array of jsons requests and call it several times for each json in array.

Example:

default payload.json:
{request.json}
arrayPayloads.json:
[{request.json},{request.json}]

When I calling another feature:

* def payload = read ('file: src/../arrayPayloads.json')
* def ex = call read ('..example.feature') payload

example.feature:
Background:
* def payload = karate.get('payload', read('file: src/../payload.json'))

Given path URL
And request karate.forEach(payload, )
When method post
1 Answers

You have some fundamental mistakes in your code. Please spend some time reading the docs and examples.

See this answer for example: https://stackoverflow.com/a/52019349/143475

Please don't have a space after read. It should be like this:

* def ex = call read('example.feature') payload

And this is completely wrong and won't work:

And request karate.forEach(payload, )

This doesn't make any sense at all:

* def payload = karate.get('payload', read('file: src/../payload.json'))

If you are still stuck, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

Related