Trying to do some calculations within the script

Hello Team,

I am trying to do some calculations within the script but I am noticing weird issues.

Below is the script: This If Statement is a part of another If Statement

if (pdp_product_price >= 50) {

    WebUI.verifyElementText(findTestObject('7_Payments_Page/Value_Shipping'), 'Free')

    assert (ca_pm_subtotal + ca_pm_taxes).equals(ca_pm_total)
}

This will validate that If the Product Price is greater than or equal to 50 then Shipping should be free and then validates the total using Variables ca_pm_subtotal ca_pm_taxes and then matching it with the variable ca_pm_total . These all variables are already in BigDecimal

The script is automatically removing ( and ) from assert (ca_pm_subtotal + ca_pm_taxes) and leaves it as assert ca_pm_subtotal + ca_pm_taxes.equals(ca_pm_total) when I switch to Manual Mode and do some changes.Because of this auto change, I am getting error

03-15-2019 10:18:56 AM assert ca_pm_subtotal + ca_pm_shipping + ca_pm_taxes.equals(ca_pm_total)

Elapsed time: 0.015s

if (IsRegionCA) FAILED.

Reason:

groovy.lang.MissingMethodException: No signature of method: java.math.BigDecimal.plus() is applicable for argument types: (java.lang.Boolean) values: [false]

Possible solutions: plus(), plus(java.math.MathContext), plus(java.lang.Character), plus(java.lang.Number), plus(java.lang.String), ulp()

Hi,

you have typing issue in your code,
what types your variables are?

I’d do two things:

  1. Stay the hell away from Manual view :rofl:
    1.1 Scary things happen in there - unseen hands on your code!
  2. Add the first pair of vars first:
BigDecimal total =  ca_pm_subtotal + ca_pm_taxes
assert total.equals(ca_pm_total)

@Russ_Thomas I am not sure why Katalon Manual Mode is doing that. But I am able to execute the script using :

if (pdp_product_price >= 50) {

    WebUI.verifyElementText(findTestObject('7_Payments_Page/Value_Shipping'), 'Free')

    def ca_pm_total_expected = ca_pm_subtotal + ca_pm_taxes

    WebUI.verifyEqual(ca_pm_total_expected, ca_pm_total)
}

if (pdp_product_price < 50) {

    WebUI.verifyTextNotPresent('Free', false)

    ca_pm_shipping_1 = WebUI.getText(findTestObject('7_Payments_Page/Value_Shipping')).replace('$', '')

    BigDecimal ca_pm_shipping = new BigDecimal(ca_pm_shipping_1)

    def ca_pm_total_expected = (ca_pm_subtotal + ca_pm_shipping) + ca_pm_taxes

    WebUI.verifyEqual(ca_pm_total_expected, ca_pm_total)
}