cancel
Showing results for 
Search instead for 
Did you mean: 

Comparison of Two Property Values In Two Different Properties Steps

SOLVED
Highlighted
Community Hero

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 @msiadak 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

 

 

 

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

@richie ,

 

(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:

https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/compare/ComparePropertiesValuesOfPro...

 

Selection_023.png



Regards,
Rao.

View solution in original post

11 REPLIES 11
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

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




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

Hey @msiadak

 

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

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

Do you want to compare values form requests? or from response?


Regards,
Rao.
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

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

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

@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.


Regards,
Rao.
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

Hi @nmrao

 

I have attached a single test case ReadyAPI! project.xml  with the one test case in which includes the comparison groovy script I've been trying to use - I created some VIRTs for each of the requests on the project so you should be able to load the project file in, start the VIRTs and execute the test case to see the requests and response - but just to make it clear in case I have provided screenshots of the relevant steps below as well

The test hierarchy is as follows:

 

 

REST POST(login) - to get an authorization token for later use
Datasource (directory - sourcing a single file)
POST (creating a new record in endpoint)
GET (queries endpoint to confirm POST created record correctly)
Prop Transfer1 (grabs value from the GET)
Properties1 (stores value grabbed from GET)
GET2 (queries endpoint)
Prop Transfer2 (grabs another value from GET2 response)
Properties2 (stores value grabbed from GET2)
Groovy (compares values stored in separate Properties steps)

 

 

 

This has been hanging over my head for a while - I found this approach to compare 2 discrete step responses via stackoverflow as it has minimal groovy - hence why I could really do with working out why this doesn't work properly.

 

Essentially when I run the groovy script it returns a null for the fn;s

 

 

Really, really appreciate any/all help anyone can provide - Im gonna need to use this step result comparison approach multiple times going forward, so I need to work out what I'm doing wrong!

 

thanks so much to all,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

@richie ,

 

(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:

https://github.com/nmrao/soapUIGroovyScripts/blob/master/groovy/compare/ComparePropertiesValuesOfPro...

 

Selection_023.png



Regards,
Rao.

View solution in original post

Highlighted
Community Hero

Re: Comparison of Two Property Values In Two Different Properties Steps

Thanks you for the screen shots.


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 9
2 nmrao 6
3 HimanshuTayal 3
Top Kudoed Authors