Forum Discussion

rohitvarsha12's avatar
rohitvarsha12
Contributor
8 years ago

Re: How to check non existence of a xml element?

This will not work if value of this property is ""(Blank).

 

I am facing this problem. Dont know how to fix it.

 

 

4 Replies

    • PaulMS's avatar
      PaulMS
      Super Contributor

      Rohit,

       

      If the expected result is blank then the JsonPath Match assertion should be similar to

       

      Expression

      $..YourPropertyName[0]

       

      Expected Result

      (leave blank)

       

      Otherwise try JsonPath Existence Match if the expected result is not always blank.

      • rohitvarsha12's avatar
        rohitvarsha12
        Contributor

        Below code worked for me:

         

        import groovy.json.JsonSlurper

         

        def slurper = new JsonSlurper()

        def i = 0

         

        responseContent = context.getProperty("Response")

        //log.info(responseContent)

         

        slurperresponse = new JsonSlurper().parseText(responseContent)

         

        if(slurperresponse.loanDetails.field) {

             log.info("Found")

        } else {

             log.info("Not Found")

        }

    • nmrao's avatar
      nmrao
      Champion Level 3
      Better you create a new topic in the forum with required details so that some one can understand. Encourage you not to cross posts.