1

I want to match multiple response of an API. Please find below Scenario Outline.

Background:
* def kittens = read('../sample.json')

Scenario Outline: Create Test1
Given url url
And request <Users>
When method POST
Then status 200
And match response.success.name == <expectedName>
And match response.success.contact.mobile == <expectedMobile>

Examples:
  |Users|expectedName|expectedMobile|
  |kittens.User1|'Micheal'|'123456'|
  |kittens.User2|'Steve'|'998877'|

In the above case, I am able to match for 2 fields but I want to validate for more fields, but it is increasing pile of code that I do not want.

Multiple response of an API:

"success": {
   "name": "Micheal",
   "addr": "Tesla road",
   "contact": {
      "mobile": 123456,
      "phone": 4422356
    }
}


"success": {
   "name": "Steve",
   "addr": "Karen Road",
   "contact": {
      "mobile": 998877,
      "phone": 244344
    }
 }

I am looking for minimizing the lines of code.

Can you please tell me another way where I can load entire response into expected and then I will traverse in the example section?

Please help me. Thank you !!

Madhur
  • 51
  • 3

1 Answers1

-1

I strongly recommend you don't do this, and the reasons are explained in detail here: https://stackoverflow.com/a/54126724/143475

Also note instead of going field-by-field, you can use the whole JSON in the Examples column, or even pull from a file, see examples.feature.

You will actually end up with a much more "increasing pile of code" if you go down this path in my sincere opinion.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248