Ask a Question

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

SOLVED
madhu_112
Occasional Contributor

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 available balnce) - both are coming from json response

now my question is i'm writing a script to check whether the prevavailbalance is correct or not? i'm stuck here how to set this thing up.

 

2 REPLIES 2
richie
Community Hero

Hey @madhu_112,

I think we're gonna need some more info to help you.

You mention you need to assert that the prevavailbalance is correct but you dont indicate what makes it correct (i.e. what is the underlying requirement youre trying to verify?)

Looking at your post's subject header it appears you want to assert that preavailbalance is updated when the curravailbalance is updated, is that right? You could do this with a simple if/then bit of groovy.
People will need either the full jsonpath to the relevant attributes (i.e. the curravailbalance and prevavailbalance) or the actual payload so they can determine the jsonpath to build the groovy you need.

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
aaronpliu
Frequent Contributor

@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

cancel
Showing results for 
Search instead for 
Did you mean: