knaecke
13 years agoOccasional Contributor
Different property files for continuously builds/tests
Hello everybody,
I am more or less new to soapUI but already started to like it very much
After creating lots of test suites/cases/steps for different webservices I was looking for a possibility to use the same project file with different input values.
There's the nice possibility within the GUI to save and load properties from a file. That way it is possible to have different properties for the same test scenarios (e.g. different zipcodes or currencies if you have project in different countries). But I didn't want to use the button in the GUI for manual tests only but I desperately needed to have the same functionality for automatic testing (via Jenkins).
So I came to build my own pretty easy and extendible solution I want to share with you.
Explanation: Of yourse this is the most elemental part of it only. In line 2 the file myproperties.txt will be loaded, in line 10 each property and its value will be stored (or even created if not done yet) to the current TestCase from which the Groovy Script will be executed. That's it! ( Check http://www.soapui.org/Scripting-Properties/tips-a-tricks.html#1-1-get-and-set-properties to see where else you can save the values).
But you probably want to add some more features like a check if the file is available:
or want to have the results sorted, since the enumeration returns the properties randomly:
There's also the possibility to use global properties for your file names which you may set using
Have fun trying it and tell me your suggestions. Or tell everybody else here about your extensions
Best regards,
knaecke (Ben)
I am more or less new to soapUI but already started to like it very much

After creating lots of test suites/cases/steps for different webservices I was looking for a possibility to use the same project file with different input values.
There's the nice possibility within the GUI to save and load properties from a file. That way it is possible to have different properties for the same test scenarios (e.g. different zipcodes or currencies if you have project in different countries). But I didn't want to use the button in the GUI for manual tests only but I desperately needed to have the same functionality for automatic testing (via Jenkins).
So I came to build my own pretty easy and extendible solution I want to share with you.
- Set up your properties within the gui as you need them.
- Save them to a file in the same directory as your project file using the GUI, e.g. myproperties.txt.
- Now create a Groovy Script at the part of the project where you need the properties to be loaded. It should contain the following code:
groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
file = new File(groovyUtils.projectPath + '/myproperties.txt')
props = new java.util.Properties ()
props.load (new FileInputStream (file ))
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
testRunner.testCase.setPropertyValue( key , props.getProperty(key))
}
return
Explanation: Of yourse this is the most elemental part of it only. In line 2 the file myproperties.txt will be loaded, in line 10 each property and its value will be stored (or even created if not done yet) to the current TestCase from which the Groovy Script will be executed. That's it! ( Check http://www.soapui.org/Scripting-Properties/tips-a-tricks.html#1-1-get-and-set-properties to see where else you can save the values).
But you probably want to add some more features like a check if the file is available:
if (file.size() == 0)
{
log.error("file does not exist!")
return
}
or want to have the results sorted, since the enumeration returns the properties randomly:
import com.eviware.soapui.impl.wsdl.MutableTestPropertyHolder;
import com.eviware.soapui.model.support.TestPropertyUtils;
[..]
TestPropertyUtils.sortProperties( ( MutableTestPropertyHolder )testRunner.testCase );
There's also the possibility to use global properties for your file names which you may set using
testrunner.sh -Pmyfilename=myproperties.txt
Have fun trying it and tell me your suggestions. Or tell everybody else here about your extensions
Best regards,
knaecke (Ben)