Reputation: 2072
I am attempting to compare two JSON responses from two separate test steps to determine if they are exactly equal to each other (successful case means that they are) using the following Groovy Script:
def response1 = context.expand( '${GetPatientProfileById#Response#}' )
def response2 = context.expand( '${GetPatientProfileById#Response2#}' )
log.info(response1)
log.info(response2)
assert response1 == response2
How that just always signals a pass and returns the following info:
Mon Oct 05 11:41:33 CDT 2015:INFO:
Mon Oct 05 11:41:33 CDT 2015:INFO:
What am I missing? I under the impression that response1 and response2 would hold the JSON string value from the response of their respective test steps but I am clearly missing something.
Upvotes: 0
Views: 1624
Reputation: 2072
This is what I ended up using:
import groovy.json.JsonSlurper
responseContent = messageExchange.modelItem.testCase.getTestStepByName("TestStepName").getPropertyValue("response")
slurperresponse = new JsonSlurper().parseText(responseContent)
responseContent2 = messageExchange.modelItem.testCase.getTestStepByName("TestStepName2").getPropertyValue("response")
slurperresponse2 = new JsonSlurper().parseText(responseContent)
log.info (slurperresponse)
log.info (slurperresponse2)
assert slurperresponse == slurperresponse2
Upvotes: 2
Reputation: 18517
You're not getting the response
property of your test step
called GetPatientProfileById
due the last #
.
This is why context.expand( '${GetPatientProfileById#Response#}' )
is returning blank. To correct it remove the last #
as follows: context.expand( '${GetPatientProfileById#Response}' )
.
Also as @SiKing comment note that you're getting the same test step response for your both variables.
Hope this helps,
Upvotes: 1