Forum Discussion

stippareddy's avatar
stippareddy
New Contributor
14 years ago

Script Assertion

Hi,

I am using soapUI pro 4.0.1 and I am trying to a use script assertion to validate one of the values in the response. This is how my script looks:
-----------------------------
def quota = context.expand( '${getQuotaStatusPrimary#quota}')
def secquota = context.expand( '${getQuotaStatusSecondary#Response#//ADOMO[1]/QUOTA[1]}' )
log.info(quota * (3))
log.info(secquota)
assert secquota == quota * 3
------------------------

I see that the loginfo is printing the quota value 3 times(280028002800) instead of multiplying it with 3(8400). How does the multiply operator work in this case?

Thanks
Sushmita

2 Replies

  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    Hi Sushmita,
    you would get a string but not an Integer, so one string multiply that is equal to length of the string. just like you define a="hello", and you log.info (a*3), then you see that "hellohellohello", the solution is to convert it using toInteger() method.

    def quota = context.expand( '${getQuotaStatusPrimary#quota}')
    def a = quota.toInteger()
    def secquota = context.expand( '${getQuotaStatusSecondary#Response#//ADOMO[1]/QUOTA[1]}' )
    log.info(a * (3))
    log.info(secquota)
    assert secquota == a

    thanks,
    Aaron
  • Hi Aaron,

    Thanks for your reply. I was able to covert it to integer by doing the following:

    int quota = Integer.parseInt(context.expand( '${getQuotaStatusPrimary#quota}'))

    For some reason .toInterger() did not work in groovy.

    Thanks
    Sushmita