Showing posts with label soapui read from file. Show all posts
Showing posts with label soapui read from file. Show all posts

Friday, March 12, 2010

Some Groovy on Soapui tests :)

Write some entry in a file like below.

[serkans@serkanslnx ~] cat /home/serkans/phoneNumbersOnly.txt
9001234560
9001234561
9001234562
9001234563
9001234564
9001234565
9001234566
9001234567
9001234562
9001234568
9001234562
9001234569

Create a test step , right click on it , Select add new Step , Select Groovy Script.Enter the following lines to it.Play Run button on the window to execute it.Do some customization to run it.File path etc..



// read the file as a properties file, but it is not :)we will get only keys from it
def properties = new java.util.Properties();
properties.load( new java.io.FileInputStream("/home/serkans/phoneNumbersOnly.txt" ));
//get a random index acc. file's line size
Random r = new Random();
def randomIndex  = r.nextInt(properties.size());
            def valueFromFile = (String) properties.entrySet().toArray()[randomIndex].toString();
            valueFromFile = valueFromFile.toString().replaceAll("=","");
log.info(valueFromFile);
return valueFromFile;


After than you need to transfer this value by using another type of Steps in soapui.
Select add new Step , Select "Property Transfer" ,Select GroovyScript as Source and select result as Property to transfer on it,Select your "Test Request" as destination and select Request as Destination.And write "//par1[@*]" to the target window.
     Look at the picture for better understanding.That is why i prefer to watch rather than reading generally:)

It will provide you Random values from file.You can use in your load tests.Enjoy!


Visit soapui page for more.