Forum Discussion

richie's avatar
richie
Community Hero
5 years ago
Solved

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 numbe...
  • nmrao's avatar
    5 years ago

    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'