

This is done using the grep() method (very similar to the Unix command). They come in the array form (working with arrays has been covered above). Performing a search for a specific string of charactersįinally, instead of looking for exact attribute or element value matches, we can also filter on substrings. As you can see, the JSON Path Extractor captures both elements by a single query. To do this, we can simply traverse the XML tree until we get to the right element, using the index to select the first car in the list: void checkCountryForFirstCar(). Say I want to check that the first car in the list is made in Italy. The syntax for JsonPath is very, very similar, except for the obvious lack of support for attributes in JsonPath (JSON does not have attributes).Įxtracting a single element based on its index The examples in this post are all based on the following XML response: Here are a couple of tricks I learned since and worked into the exercises that’ll be part of the workshop from now on. While preparing my REST Assured workshop for the Romanian Testing Conference next month, I ran into a subject I feel I didn’t cover enough in the previous times I hosted the workshop: how to effectively use JsonPath and XmlPath to extract specific elements and element groups in RESTful API responses before verifying them. Using JsonPath and XmlPath in REST Assured
