Forum Discussion

Loli's avatar
Loli
Occasional Contributor
3 years ago
Solved

How to verify response content

Hello,I have to verify the response content dynamically using groovy but I really don't know how to do it.I am currently using the script assertion to verify the contents.Can anyone help me out? Using the Rest

 

  • Regariding the groovy list of values.

    You could insert that list into a single property and then split each value from the list into individual values using the split() metho maybe? This would include using a list but again make things tidier if just using properties. Just a thought. Going yo bed now

    Ta

    Rich.

19 Replies

  • richie's avatar
    richie
    Community Hero
    Hey Loli,

    For each of the responses can you confirm what you actually need to verify?

    I.e. are you trying to assert a specific attribute has a specific value or something else? Some of the attributes in the responses have nulls do you want to assert that these fields display nulls? Do you want to verify the structure of responses? Do you want to verify the datatypes (string? Numeric? Boolean? Null?) of the attributes in the responses? The content in the responses....do any of the attribute values in the response relate directly to the parm values submitted in the request? (This would allow you to avoid hardcoding the response values and base your assertion results on the request inputs)

    Anyone that tries helping you with this is gonna need at least this minimal information before they can sort you out.

    The more info you provide the more effectively people will be able to help you,

    Cheers,

    Rich
    • Loli's avatar
      Loli
      Occasional Contributor

      Yes sorry for such a bland explonation.For an example when i put the first request in this response comes in.I need to validate the response values with the assertion that this came in.I tried using this method: 

      def slurper = new groovy.json.JsonSlurper()
      def result = slurper.parseText('{"code": "1200","message": "UserName and Password required."}')

      assert result.code == "1200"
      assert result.message == "UserName and Password required."

       

      But i do think that it is not dynamic so i want to change it.Thanks for the replies&help

       

      • richie's avatar
        richie
        Community Hero
        Hey Loli,

        Where did you get the code from?

        Reason i ask is that youre declaring a 'result' variable that youre not actually using.

        Also, would you mind attaching the screenshot rather than embedding it please? I cant actually see the content properly with embedded screenshots. I can only see attached screenshots instead.


        Also, your code has multiple assertions. If youre including this code in a single script assertion or groovystep this means if one assertion fails the whole teststep will fail. Its adviseable to split out your assertions into individual teststeps UNLESS youre sure that if one assertion within a teststep passes then they all will pass.

        Ta

        Rich