Friday, April 15, 2016

How to generate random strings or number from Jmeter

While testing soap services, most of the time we may need jmeter scripts to generate random string or numbers as a service parameters.
I had a soap service to send the name (string value) and age (integer value) contentiously and each value should not be repeatable need to be random unique values. I used Random and RandomString functions to generate these values. Following Jmeter scrips may help you to do that.

Please find the SOAP/XML RPC request which I used here.

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <dat:inputOP>  
      <dat:age>${__RandomString(5,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,)}</dat:age>  
      <dat:name>${__Random(5,0123456789,)}</dat:name>  
    </dat:inputOP>  
   </soapenv:Body>  
 </soapenv:Envelope>  


It will send SOAP request as below.

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <dat:inputOP>  
      <dat:age>X7NQH</dat:age>  
      <dat:name>97593961</dat:name>  
    </dat:inputOP>  
   </soapenv:Body>  
 </soapenv:Envelope>  


No comments: