Ask a Question

Grab the Results of a Count Assertion and Pass to a Properties step?

SOLVED
richie
Community Hero

Grab the Results of a Count Assertion and Pass to a Properties step?

Hi,

 

I have 2 different json requests  - that 'should' return the same data. I was thinking of an easy way to compare them to prove they are identical is to ensure they bring back the same number of records.

 

the way I've done this (or similar) before is I would grab the count attribute value from one response and pass it to a properties step, grab the count attribute value from the other response, pass it to a properties step and then run some groovy that @nmrao gave me a while back with compares the contents of the Properties steps against each other and assert they are identical.

 

HOWEVER - my 1st response (response1) includes a count attribute and value, my 2nd response (response2) does NOT include a count attribute to compare against - so I'm struggling - there isn't a count attribute value to pass to the Properties step for response2

 

I can do a count assertion on the containing array attribute - but I was wondering if there is any way to pass the results of an assertion to a Properties step???  I've never done this before - but I think it could be quite handy occasionally. 

 

Would anyone know how to do this?  i.e. to pass the results of an assertion to a property?  

I've been awake for a couple of days now - so I could be missing something stupidly obvious!

 

 

I've attached the 2 example

 

Cheers 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
4 REPLIES 4
nmrao
Champion Level 3

@richie 

 

Assuming that both request steps in the same test case.

Add Groovy Script test step after the second request test step with below conent and change the test step names accordingly and it should be able to check if the record counts are matching.

 

Note that, not required to have any property test steps.

 

import groovy.json.JsonSlurper

def getJsonByStepName = { name ->
	def step = context.testCase.getTestStepByName(name)
	new JsonSlurper().parseText(step.httpRequest.responseContentAsString)
}

def json1 = getJsonByStepName('Name of the first REST Request step')
def json2 = getJsonByStepName('Name of the second REST Request step')
assert json1.value.size() == json2.value.size(), 'Records count does not match'


Regards,
Rao.
richie
Community Hero

@nmrao always saving my life

 

if I could give you more than one Kudos point I would!

 

thanks for all the help fella! 🙂

 

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
nmrao
Champion Level 3

Hope you need time to test and then mark it as solved.


Regards,
Rao.
richie
Community Hero

I was up all night testing....works great!
Again, thankyou

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
cancel
Showing results for 
Search instead for 
Did you mean: