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
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'