Good day! I'm having some trouble with assertions. Currently I have a JSON response below:
<Response xmlns="URL">
<code null="true"/>
<message null="true"/>
<status>Success</status>
<data>
<providerType>Medical</providerType>
<providerNumber>AAAAA</providerNumber>
<providerName>NAME</providerName>
<registrations>
<e>
<dateOn>30/10/1995</dateOn>
<dateOff/>
<state>NSW</state>
<status>PracticeActiveOpen</status>
<bulkPayIndicator>NoBulkPayment</bulkPayIndicator>
</e>
</registrations>
<specialityCodes>
<e>
<code>33</code>
<dateOn>01/07/1997</dateOn>
<dateOff/>
</e>
<e>
<code>104</code>
<dateOn>02/01/1987</dateOn>
<dateOff/>
</e>
</specialityCodes>
<supplements>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff/>
</e>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
</e>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
</e>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
</e>
</supplements>
</data>
</Response>
How can I have assertions for each of the below elements using the DB value? The elements can be dynamic as we can add or delete a particular hospital type.
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
Thanks for the inputs.
Hello @richie,
Thank you for taking time to respond to my question.
To answer your questions,
1. here is the JSON response. I copied and paste the XML. Apologies for the confusion.
{
"code" : null,
"message" : null,
"status" : "Success",
"data" : {
"providerType" : "Medical",
"providerNumber" : "AAAAAAAA",
"providerName" : "NAME",
"registrations" : [
{
"dateOn" : "30/10/1995",
"dateOff" : "",
"state" : "NSW",
"status" : "PracticeActiveOpen",
"bulkPayIndicator" : "NoBulkPayment"
}
],
"specialityCodes" : [
{
"code" : 33,
"dateOn" : "01/07/1997",
"dateOff" : ""
},
{
"code" : 104,
"dateOn" : "02/01/1987",
"dateOff" : ""
}
],
"supplements" : [
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : ""
},
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : "23/02/1998"
},
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : "23/02/1998"
},
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : "23/02/1998"
}
]
}
}
2. I am currently trying to validate the value from the JSON response versus the Database values that we have.
3. Thirdly. I "think" what you are asking for is that certain attributes/tags may have different values depending on certain conditions....is that right? - Yes, this is correct.
Hi binsalgado,
You may parse JSON with groovy.json.JsonSlurper to get JSON object, and then loop.
For example(In Groovy Script step):
def request = testRunner.testCase.testSteps["YourStepName"].testRequest
def response = request.response.contentAsString
def slurper = new groovy.json.JsonSlurper().parseText(response)
slurper.supplements.each{
// add your script to verify
// log.info it.hospitalType
}
Subject | Author | Latest Post |
---|---|---|