Posts

Showing posts with the label JSON path

Extracting a JSON Response with Rest-Assured

Image
In the earlier post, we studied about Testing GET Requests and their Responses using Rest Assured , before following this tutorial, I would recommend reading the previous one. In this post, we will learn about extracting JSON Response using Rest Assured. Once the response is extracted we will store it into Response class and later various tests can be performed to check whether extracted response is correct. I would assume that everyone following this tutorial has knowledge of Java and TestNG. If you need help then please follow tutorials on Java and TestNG . Now let's look at an example where we will search for a particular Railway Station in Mumbai City and print the response. import org.testng.annotations.BeforeClass ; import org.testng.annotations.Test ; import io.restassured.RestAssured ; import io.restassured.http.ContentType ; import io.restassured.response.Response ; import static io. restassured . RestAssured .*; public class GetJsonResponseTest { ...

Beautify JSON and directly copy JSON Path using this chrome extension

Image
Beautify JSON Generally the JSON that we get when we hit an API is in raw format and difficult to read as follows { "error" : false , "category" : "Programming" , "type" : "single" , " joke" : "Two C strings walk into a bar.\nThe bartender asks \ "What can I get ya?\"\nThe first string says \"I'll have a gin and tonic. \"\nThe second string thinks for a minute, then says \"I'll take a tequila sunriseJF()#$JF(#)$(@J#()$@#())!*FNIN!OBN134ufh1ui34hf9813f8h8384h981h3984h5F!##@ \"\nThe first string apologizes, \"You'll have to excuse my friend, he's not nu ll-terminated.\"" , "flags" :{ "nsfw" : false , "religious" : false , "political" : false , "racist" : false , "sexist" : false , "explicit" : false }, "id" : 28 , "safe" : true , "lang" : "en" } Either...

Update values in Post Data using Json Path in Rest Assured

Image
In the previous post we studied about how to validate json schema in Rest Assured. In this post we will study about how to update values in Post Data (JSON) using Json Path in Rest Assured. When we have multiple dynamic values in POST Data which will change every time  then we need to read those values from previous request and use those values to update the POST Data (JSON). This is specifically used when the hardcoded values in JSON Data like specific ID's won't work. For example in following POST Data : { "id" : 1 , "name" : "ashwin" , "surname" : "karangutkar" , "details" :{ "City" : "Mumbai" }} If I need to change City then Json Path that we will use is details.City . Before having a glance at code, we will need to import  Jayways JsonPath .  Following is the maven import: <!-- https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path --> <depende...

Popular posts from this blog

Extracting an XML Response with Rest-Assured