Forum Discussion
DB Column names are same as JSON Response elements
I need to compare the DB response column values with Json Response Column values dynamically based on Statement ID
Here is the sample JSON Structure(Like this have different array objects and array elements). Below is the sample array object
"STMT_BK_ADDR_LINE": {
"STMTID": 10,
"BK_ADDR1": "VALUE"
"BK_ADDR2": "VALUE",
"BK_ADDR3": "VALUE",
"CRET_TMSP": "VALUE",
"CRET_PGM_ID": "VALUE",
"CRET_USER_ID": "VALUE"
}
What is the best method for validating the response with DB result dynamically
Currently I have created one property element for each JSON element and DB element (I.,e STMT_ID(for JSON) and STMT_ID for DB-as per my earlier post)
How can I refresh the property value if I use the for loop for validating all data elements
Thanks!!
Assuming that you want to validate all data from the first row of the JDBC response, you could use a script like this to loop through each of the children
def xml = new XmlSlurper().parseText(context.expand( '${JDBC Request#ResponseAsXml}' ))
xml.ResultSet.Row[0].children().each {
Name = it.name();
DBResponse = it.text();
JsonResponse = context.expand( '${REST Request#Response#$..' + Name + '}' )
Result = (DBResponse == JsonResponse) ? "pass" : "fail"
//either write each result to Excel or set property values
//context.testCase.setPropertyValue("DBResponse" + Name,DBResponse)
//context.testCase.setPropertyValue("JsonResponse" + Name,JsonResponse)
//context.testCase.setPropertyValue("Result" + Name,Result)
}
Related Content
- 2 years agojerry91