Answers for "How do you verify a value in your Response body?"

0

How do you verify a value in your Response body?

● For exp: verify ID contains correct number
o Hamster Matcher is assertion library.
then().assertThat().body(“Id”,Matchers.equalTo(123));
o Parse into JsonPath and use getInt(), getList(), getString() methods to read Id value. 
And, I can use JUnit Assertion:
String body = ...thenReturn().body().asString(); 
JsonPath json = new JsonPath(body); 
assertEquals(123,json.getInt(“Id”));
o De-serialize into a (POJO) object (or Object Mapping)
POJO myPojo = … when().post(url).thenReturn().body().as(Pojo.class); 
assertEquals(123,myPojo.getId( ) );
And, I can use JUnit Assertion
Posted by: Guest on June-21-2021

Code answers related to "How do you verify a value in your Response body?"

Browse Popular Code Answers by Language