Forum Discussion

richie's avatar
richie
Community Hero
6 years ago
Solved

Comparison of Two Property Values In Two Different Properties Steps

Hey,

 

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:

 

REST1 step

PropertyTransfer (grabs GUIDProcCode from REST1 result and passes it to Properties1 step

Properties1 step (holds Propertyname= GUIDProcCode, Propertyvalue=Xs45-cvs78)

REST2 step

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!

 

richie

 

 

 

 

 

11 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    Can we get a bit more detail? Seeing a screen shot of the project an the properties steps will help me out.

    • richie's avatar
      richie
      Community Hero

      Hey groovyguy

       

      I've created a number of images (14) providing all the config and results on each of the test steps so you can see where I'm coming from.  This is actually from an old project and old client that I'm not working on anymore - but I need to use the same approach of comparing attribute values from 2 different responses in my current project.

       

      I was going to embed the images - but the images dont render as I'd like so I've attached rather than embedded them.  They are all numbered in sequence - I'm real sorry - I may have given you too much info - but too much is better than too little- right? (hehehe probably not in this case)

       

       

      Anyway - any help/assistance/guidance is as always most appreciated!

       

      nice one,

       

      richie

       

      • richie's avatar
        richie
        Community Hero

        Hey Guys,

         

        I know it's been a while since I was looking at this, but I'm still stuck I'm afraid.

         

        Essentially I have 2 REST requests that return 2 values - I save those two values into separate properties steps and then use the following groovy to compare the values (they should be identical)

         

        The groovy is as follows:

         

        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"

         

        The groovy isn't working for some reason - I'd welcome anyone's more practiced eye to see if they can spot what I'm doing wrong?  Thanks so much - I'm at a standstill with this,

         

        thanks,

         

        richie

  • nmrao's avatar
    nmrao
    Champion Level 3
    Do you want to compare values form requests? or from response?
    • richie's avatar
      richie
      Community Hero

      There are 2 REST requests and each of the 2 REST requests generate a GUID attribute in the response.

       

      I needed to confirm the 2 values from each response were identical to each other and there's no OTB functionality to compare values from different responses.

       

      I did a bit of research and the easiest way for a noncoder (me!) was to store the values in properties step and then have a subsequent groovy code snippet to actually do the comparison.

       

      HOWEVER - the groovy comparison isn't/wasnt' working and I don't know why.

       

      thanks,

       

      richie

       

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        richie,
        Sample of the messages along with what data needs to be compared would help to understand better.

        It is very much possible to access both step data (either request or responses) directly from a Groovy Script step (assuming in the same test case) without even creating additional properties steps.