Request Body
{
"StudentInfo":{
"Student":[
{
"StudentId":"001"
}
}
}
Response Body
{
"Studentinfo":{
"Student":[
{
"StudentId":"001",
"firstname":"John",
"Lastname":"Tac",
"DOB":"2015-02-10"
}
}
}
How can I write the validation on tests from the response body. In the test result I need to view the output parameters like below
PASS "StudentID": 001
PASS "DOB":2015-02-10
Update:
Thank you for your answers. If I need to read from response body and put dynamically in test how can we achieve this instead of passing hard code values?
pm.test("Student ID validation", function () {
// Parse the response body to JSON object
var jsonData = pm.response.json();
// Validate Student ID
pm.expect(jsonData.Studentinfo.Student[0].StudentId).to.eql(**":"**);
// Log the result
pm.log("Student ID: " + jsonData.Studentinfo.Student[0].StudentId);
});
pm.test("DOB validation", function () {
// Parse the response body to JSON object
var jsonData = pm.response.json();
// Validate DOB
pm.expect(jsonData.Studentinfo.Student[0].DOB).to.eql(**""**);
// Log the result
pm.log("DOB: " + jsonData.Studentinfo.Student[0].DOB);
});