Rest Assured- Different ways to read response

Rahul
2 min readFeb 8, 2020

--

  1. By converting the response as string : In this way you will get the whole response

2. By extracting the response (extract.response)

3. By using extract.path you can use certain parts of response

This will have ‘url’ stored in href variable and then you can assert it

4.

These above approaches do the same thing as 3rd does but in a single line

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

  1. Extracting response by Json Path Class:

Json path takes string as input and then converts into JSON and helps to parse JSON.

{
"dashboard":{
"purchaseAmount":910,
"website":"rahulshettyacademy.com"
},
"courses":[
{
"title":"Selenium Python",
"price":50,
"copies":6
},
{
"title":"Cypress",
"price":40,
"copies":4
},
{
"title":"RPA",
"price":45,
"copies":10
}
]
}
1. Print No of courses returned by APIJsonPath js = new JsonPath(payload.CoursePrice());
int count = js.getInt("courses.size()");
2. Print Purchase Amountint totalAmount = js.getInt("dashboard.purchaseAmount")3. Print Title of the first courseString titleFirstCourse = js.get("courses[0].title");4. Print All course titles and their respective Prices5. Print no of copies sold by RPA Course
6. Verify if Sum of all Course prices matches with Purchase Amount
4. Print all course titles
5. No of copies by RPA
Verify if sum of all courses

--

--

No responses yet