Forum Discussion

rlong98's avatar
rlong98
Contributor
10 years ago
Solved

Script Assertion adding two decimal values suddenly is failing

So this worked last week (no changes other than the WSDL did change)...

 

CODE (abbreviated)

I have 3 defined (context.expand) values that are all decimal 

def a = context.expand(<path>) as int // = 43680.59

def b = context.expand(<path>) as int // = 3000

response = context.expand(<path>) as int // = 46680.59

 

def total = a + b

assert total == response

 

Run Error = "For input string: "43680.59"

Why is this suddently not working?

 

IF I remove the "as int" - it runs but it's "combining"/"concatinating" a & b together as strings

 

Thanks for your hlep in advance

  • Well this is why I'm a rookie... the fix is stupid easy (unless i run into another hiccup)

     

    Just adding ".toBigDecimal()" after my context.expand lines did the trick.

     

    Of coruse the math equation i had to put "as String" in order for SoapUI to not compare the BigDecimal to the actual 2 decimal output

2 Replies

  • More information -

    I found out when orginally testing this I wasn't passing a deimal value.

    so the "as int" was working then - but not when I do pass a decimal it won't work and I get that error.

     

    So the question now is:  "How do I convert a def context.expand value so the script assertion can read it as a decimal value?"

     

    I searched many possibile ways but no syntax is working for me

    • rlong98's avatar
      rlong98
      Contributor

      Well this is why I'm a rookie... the fix is stupid easy (unless i run into another hiccup)

       

      Just adding ".toBigDecimal()" after my context.expand lines did the trick.

       

      Of coruse the math equation i had to put "as String" in order for SoapUI to not compare the BigDecimal to the actual 2 decimal output