Karate: How to paste and run scenario for each param from array response inside scenario?

Viewed 42

I have a range of values, like taskId, extracted from DB.

* def getTasks = db.readRows('SELECT task_id from tasks t WHERE t.status = \'IN_PROGRES\' 
')
* def getIds = get getTasks[*].task_id

* 'task', 'setUser'
* request 
"""
[{
  "task_id": " ",
  "assignedUser": {
    "user": "someValue"
}
}
]
"""
* method post
* status 200
* def responseResult = 
"""
{
"totalCount": '#number',
"successCount": '#number',
"skippedCount": '#number',
"failedCount": '#number',
}
"""
* match response == responseResult

I need to get each value from the list response and paste in into a "task_id" Could you please clarify this case?

1 Answers

If you mean trying to create a JSON array from a bunch of values that is easy.

* def response = { foo: 1, bar: 2 }
* def task_ids = []
* task_ids.push(response.foo)
* task_ids.push(response.bar)
* match task_ids == [1, 2]

When it comes to JSON manipulation, think of Karate as just like JavaScript.

Related