Comparison of Two Property Values In Two Different Properties Steps
I created a test a long time ago that always passed - essentially I had two REST requests and I wanted to compare an attribute value from each of these REST requests to confirm they were identical. I couldn't find any OTB functionality to support a comparison of results from separate test steps so I used a bit of groovy. HOWEVER - my test always passes and I've realised its actually incorrect and I don't know why - so would like some guidance please?
OK - my test case hierarchy is as follows:
PropertyTransfer (grabs GUIDProcCode from REST1 result and passes it to Properties1 step
Properties1 step (holds Propertyname= GUIDProcCode, Propertyvalue=Xs45-cvs78)
PropertyTransfer (grabs WEIRDGUIDCode from REST2 result and passes it to Properties2 step
Properties2 step (holds Propertyname= WEIRDGUIDCode, Propertyvalue=Xs45-cvs78)
GroovyStep - details as follows:
def fn = testRunner.testCase.getPropertyValue('GUIDProcCode') def fn2 = testRunner.testCase.getPropertyValue('WEIRDGUIDCode') assert fn == fn2, "values are identical, SoapUI is great"
Now I always thought the test executed fine cos tbh i could see the groovy step passed and I could also see the values written to the 2 different properties steps were identical.
HOWEVER - I've just started looking at this script cos I need to do something similar and I've realised this groovy step ISN'T doing what I think it's doing.
When I run the groovy debugger I noticed it saying
fn (java.lang.Object) = null
fn2 (java.lang.Object) = null
so I'm guessing its not finding those property values after all!
I was wondering about the following lines
def fn = testRunner.testCase.getPropertyValue('GUIDProcCode') def fn2 = testRunner.testCase.getPropertyValue('WEIRDGUIDCode')
first thing I notice is that I'm not specifying WHICH Properties steps - the GUIDProcCode is in Properties 1 step, the WEIRDGUIDCode is actually stored in Properties 2 step. I did try storing them in the one step, but the script didn't execute properly and SmartBear told me I had to split them out due to the sequence of execution.
I've had a read of various soapui.org pages and they dont appear to state I need to specify the actual Properties step name, however groovyguy helped me out yonks ago and gave me some code as follows:
def propertiesStep = context.testCase.testSteps["Properties"];
and I tried altering the script to the following:
def propertiesStepGUIDProcCode = context.testCase.testSteps["Properties1"]; def fn = testRunner.testCase.getPropertyValue('GUIDProcCode') def propertiesStepWEIRDGUIDCode = context.testCase.testSteps["Properties2"]; def fn2 = testRunner.testCase.getPropertyValue('WEIRDGUIDCode') assert fn == fn2, "values are identical, SoapUI is great"
And it didn't work! not surprising considering my coding skills
Can anyone advise? am I totally on the wrong track here? am mI missing somethign totally stupid?
Many thanks to all!
(4) Steps could be reduced in the test case provided both response are available. Access the both responses of rest request steps, extract required values and compare them in a single groovy script.
Any ways, below script does the comparison the way you wanted.
Please follow the comments provided in the script below: