Forum Discussion

RaMup29's avatar
RaMup29
Occasional Contributor
9 years ago

how can I give a variable in my load test,

I have Soap request which I will be using in LoadTest
But the problem is LoadTest will run the same query again n again in the loop

I want the loadtest to have a variable assigned, so the variable should take the value from the defined range ..

 

Example:

Below is my SOAP request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.apertio.com/webservice/TmoUsEIRSoap/v1">
   <soapenv:Header/>
   <soapenv:Body>
      <v1:DeviceQueryReq>
         <transactionId>12345</transactionId>
         <vendorId>29</vendorId>
         <userEquipmentInfoType>imeisv</userEquipmentInfoType>
         <userEquipmentInfoData>444999334567890</userEquipmentInfoData>
                 </v1:DeviceQueryReq>
   </soapenv:Body>
</soapenv:Envelope>

 

 

In the above request, I want to give "userEquipmentInfoData" input as a variable
Something like
 <userEquipmentInfoData>"$IMEI"</userEquipmentInfoData>

where IMEI=444999334560000-444999334570000

 

So that the loadTest will run take the values from this range when it run each time.

  • Hi,

     

    So to generate a random number every time (with the same number of digits that you have in your example) you can use:

     

    ${= ((String)(int)(Math.random()*10000000000000)).padLeft(14,'0')}

    This would generate something like:

     

    00002147483647

     

    Breaking the one-liner down:

     

    (int)(Math.random()*10000000000000) //generates a random integer >0 and <10000000000000

    Then, to get the right number of digits every time, I padded the number with zeros from the left:

     

    .padLeft(14,'0')

    Will this do?

     

    Regards,

    Rup

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    If the value to substitute can be random, then maybe you could try something like:

    ${=(int)(Math.random()*1000000000)}

    You can always append prefix string etc.

     

    If you would like a sequential number (unique across TestCase executions when run by a load test), then you need to make sure you store the number somewhere shared e.g. a counter property stored against the TestSuite and incremented when the TestCase is run.

     

    I am in the process of blogging something that has an example of a sequential number generator. Not quite finished yet, but let me know if its useful and I'll finish it off (actually may go beyond what you need):

     

    http://rupertanderson.com/blog/1-how-to-develop-add-and-use-a-custom-groovy-library-in-soapui/

     

    You can also take data items from a shared datasource e.g. database or file, using a Groovy TestStep in the TestCase. A bit harder to explain in a sentence, let me know if you want more info on this.

     

    Basically there's a few good options depending on your exact requirement.

     

    Regards,

    Rupert

     

    • RaMup29's avatar
      RaMup29
      Occasional Contributor

      Hi Rupert

       

      Many thanks for the quick reply

       

      I am okay to have a random number for each run.

       

      I am a new to SoapUI, can you please help me in getting the exact syntax pls

       

      for the line below:

      <userEquipmentInfoData>11122233344455</userEquipmentInfoData>

       

      the 111222333344455, I want to have this value generated randomly

       

       

      Or pls help in writing the code to take the numbers from the text file on my computer.

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi,

         

        So to generate a random number every time (with the same number of digits that you have in your example) you can use:

         

        ${= ((String)(int)(Math.random()*10000000000000)).padLeft(14,'0')}

        This would generate something like:

         

        00002147483647

         

        Breaking the one-liner down:

         

        (int)(Math.random()*10000000000000) //generates a random integer >0 and <10000000000000

        Then, to get the right number of digits every time, I padded the number with zeros from the left:

         

        .padLeft(14,'0')

        Will this do?

         

        Regards,

        Rup