Forum Discussion

SahithiAnirudh's avatar
SahithiAnirudh
Frequent Visitor
5 years ago

Can json attribute values be compared with values in properties for assertions

Is there a possibility to add assertion in a way that certain value to an attribute in the json should be equal to value in the properties (where value in the properties is dynamically populated when uploading data from the excel, so that is not a fixed value)

  • Definitely possible.

    If using properties, why am excel? Can't you use . properties file?

  • SahithiAnirudh :

     

    Yes this is absolutely possible by adding script assertion and parsing your response and asserting desired values.

    Refer below script for help:

     

    import groovy.json.JsonSlurper
    
    //getting data from response
    def response = messageExchange.responseContent
    //parsing data with JsonSlurper
    def jsonSlurper = new JsonSlurper().parseText(response)
    //Getting data from properties
    def tenure = context.expand('${Properties#tenure}')
    //getting data from response's particular node
    tenureResponse =  jsonSlurper.tenure
    
    //asserting both the data
    assert (tenure == tenureResponse) : "Value didn't match in properties : "+tenure+" in response : "+tenureResponse
    

     

    Hope it will help you 🙂

  • nmrao's avatar
    nmrao
    Champion Level 3
    Definitely possible.

    If using properties, why am excel? Can't you use . properties file?