Forum Discussion

yarab's avatar
yarab
Occasional Contributor
15 years ago

Re: help: property as function of another property

Hi,

please help

I have this request:


 

 
     
        2
        24
     

 


I want the crsNum to be random between 1 and 4, I did that using property expansion: ${=(int)(Math.random()*10)}
Q: I want StudentAge to be function of crsNum, how to do it in soapUI Pro?
Ex: if crsNum=1, then StudentAge= 10 to 20
      if crsNum=2, then StudentAge= 20 to 30
      and so on

Another example If I have property t1=current time, How to set another defined property t2=t2-t1

thank you in advance ..

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    The easiest way to do this would be to have a separate Groovy TestStep before the actual request where you set these as Test Properties in for example the TestCase. For instance:


    def crsNum = (int)(1 + Math.random()*4)
    def studage = (int)(crsNum*10 + Math.random()*10)

    testRunner.testCase.properties['crsNum'].setValue( (String)crsNum )
    testRunner.testCase.properties['StudAge'].setValue( (String)studage )


    And then in your request use the property expansions as follows:


    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ejb="http://EJBcourse.sun.com/">
      <soapenv:Header/>
      <soapenv:Body>
          <ejb:checkAgeFull>
            <crsNum>${#TestCase#crsNum}</crsNum>
            <StudAge>${#TestCase#StudAge}</StudAge>
          </ejb:checkAgeFull>
      </soapenv:Body>
    </soapenv:Envelope>


    You will need to first create the two Test Properties in the TestCase for this to work.

    Regards,
    Dain
    eviware.com