Forum Discussion

madhu_112's avatar
madhu_112
Occasional Contributor
4 years ago

Update the previously available balance only when there is a change in available balnce

Hai, can someone help me with this problem..   I've availbalance = 123 and prevavailbalance = 121(this should only update when there is a change in availbalance, in this case 121 was previously ava...
  • aaronpliu's avatar
    4 years ago

    madhu_112 It should be easy to deal with it with groovy script.

    Since it retrieve available balance from json response, you may need to save it in properties (i.e test suite properties) and next time get new balance and compare them.

    For example:

    test suite properties: availbalance = 123

    in REST step:

     

    // add script in response
    import groovy.json.JsonSlurper
    
    def response = messageExchange.response.contentAsString
    def json = new JsonSlurper().parseText(response)
    // assume that you save availbalance in test suite level
    def availbalance = context.expand ('${#TestSuite#availbalance}').toInteger()
    // please replace with your json path
    def newbalance= json.availableBalance
    if (availbalance != newbalance) {
        messageExchange.modelItem.testStep.testCase.testSuite.setPropertyValue("availbalance ", newbalance.toString())
    }

     

     

    Thanks,

    /Aaron