I am making a post call and after post call the object goes into array at random position so how can I assert for that object.without knowing it's response. message[position?].
Please suggest me what can I do.
CodePudding user response:
Use JsonPath. Here is one example: https://stackoverflow.com/a/64373344/143475
Keep in mind there are plenty of ways to extract data from JSON that ignores the exact path or position. For example:
* def response = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def extracted = $..e
* match extracted contains 5
If you are just concerned about arrays, use contains
: https://github.com/karatelabs/karate#match-contains