Mod 14, part 2... The video did not show example of 'Find' | Rest Assured Forum
C
charles japhe Posted on 04/07/2019

At the end there was example of 'FindAll', but I want to see example of 'Find'....   And how to extract single value....  Map, List, etc...

 

Thank you,

Charles


A
Ashish Thakur Replied on 05/07/2019

Hi Charles,

See both 'find' and 'findAll' have almost similar functionality, both search through the list to match the values passed.
Their syntax is also same. Just that find will extract single value whereas findAll will find all the matching values in the list.

I'll give you a simple example here only, you can implement it by yourself.

Let's say we have this sample JSON:

{
  "name" : "abc",
  "items" : [
    {
     "itemName" : "table",
     "cost" : 50
    },
    {
     "itemName" : "chair",
     "cost" : 75
    },
   {
     "itemName" : "table",
      "cost" : 40
   }
  ]
 }

Now, on this JSON we'll use both find and findAll

HashMap<Object,Object> item = resp.then().extract().path("items.find{it.itemName == 'table'}");

Output: {"itemName":"table , "cost":50}

Whereas,

ArrayList<HashMap<Object,Object>> item = resp.then().extract().path("items.findAll{it.itemName == 'table'}");

will give output as:

[{"itemName":"table , "cost":50}, {"itemName":"table , "cost":40}]


C
charles japhe Replied on 05/07/2019

Thank you!  :)


A
Ashish Thakur Replied on 10/07/2019

No problem! :)