Posts

Showing posts with the label JSON Respnse

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 { ...

Comparing JSON responses using JsonAssert Library - Lenient Mode

Image
  In one of the earlier post, we studied about Extracting a JSON Response with RestAssured ,  before following this tutorial, I would recommend reading the previous blogs.  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 . In this post, we will learn about comparing JSON Responses using JSONAssert . Once the response is extracted we will store it into Response class and later verify the entire response using a single assert statement instead of comparing specific attributes. The disadvantage of directly comparing the response as string without JSONAssert is as follows: If we compare two jsons by simply comparing the json string then it fails to let us know where exactly the comparison has failed. It will also mark json as failed if the order of array elements in json is different.  However if use JSONAssert Library, it will  let us know th...

Popular posts from this blog

Using RequestSpecBuilder in Rest Assured ( Code Reuse )