How to use a counter to increament its value everytime

Hi,
I am new to Katalon and we are trying to automate the regression pack in our company. My query is, I want to deposit some amount, eg. £5 and then check that everytime I deposit £5, my balance is updated by 5 in the balance box. Do I use a variable to store this value and use a counter, not sure how I should go ahead with this, if anyone can help please?

So, after I deposit my amount, I should be able to see the updated balance in this section below and should be able to verify that ‘previous value+£5=new value’

image

I have written steps until here:

This is in no way “perfect” but maybe it is something that you can review and see concepts of what you need to do. You seem to work in the Manual tab whereas the following is code that can be put into the Script tab. Play with it along with doing some “Google Time”…

Maybe like:
"put this after Login_btn"
def bankBalance = 0.0
def amount = 0.0

"getting beginning bank balance (so you HAVE to be on that page)"
bankBalance = WebUI.getAttribute(findTestObject('Login_balance box'), "value")

"compare the two values"
WebUI.verifyEqual(amount.toString(), bankBalance)

for (int cnt = 0; cnt < 4; cnt++) {
    
    WebUI.click(findTestObject('depositamount_5'))
    WebUI.click(findTestObject('Cashier_deposit now_btn'))
    "add 5 euros to amount"
    amount += 5.0

    WebUI.waitForElementVisible(findTestObject('deposit successful_play now_btn'), 10)
    WebUI.click(findTestObject('deposit successful_play now_btn'))

    WebUI.waitForElementVisible(findTestObject('Login_balance box'), 10)
    WebUI.click(findTestObject('Login_balance box'))
    
    "get the balance amount"
    bankBalance = WebUI.getAttribute(findTestObject('Login_balance box'), "value")

    "compare the two values"
    WebUI.verifyEqual(amount.toString(), bankBalance)
}

"final bank balance"
WebUI.comment("final bank balance is ${bankBalance}")
println("final bank balance is ${bankBalance}")

I am not sure why do you need a counter.
You can simply do it in few steps:

  • get the current amount
  • deposit 5
  • get again the amount
  • check if the current amount it is prev_amount + 5

Thanks, but do we need to define any variables to store these values?

Thanks,will try this :+1: