Forum Discussion

knaecke's avatar
knaecke
Occasional Contributor
13 years ago

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.


  • 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)

5 Replies

  • knaecke's avatar
    knaecke
    Occasional Contributor
    Yeah I have tried this too. But maybe I did something wrong.

    I have used option -D with my testrunner.sh (I work on Linux) but I never got a line saying "01:20:05,234 INFO [PropertyExpansionRequestFilter] Loaded 52 properties from [C:\workspace\core\project.properties]" neither an error telling my my parameter at -D could be wrong. There were also no changes within my properties. So I felt stuck and tried another way.
  • redfish4ktc2's avatar
    redfish4ktc2
    Super Contributor
    As far as I understand your script, you try to override properties of a given testcase.
    So if its name is MyTestCase1, adding the following parameter to the testrunner.sh script should work
    -Dsoapui.properties.MyTestCase1=myFile.properties

    The first example given in http://www.soapui.org/Scripting-Propert ... mmand-line (and the logs) does not apply as it should only be used if you want to override Global Properties (define for the whole Soapui application, not for any part of a specific project)
  • knaecke's avatar
    knaecke
    Occasional Contributor
    Thanks for the hint. Somehow I must have missed something before because i tried that too (on global/project level). But now I was able to overwrite the properties:
    11:33:13,343 INFO  [AbstractTestPropertyHolderWsdlModelItem] Overriding 36 properties [..]


    To load the values this way may be another possibility for me now.

    On the other hand I have more possibilities and flexibility using my small script if it comes to load only some values (e.g. with specific prefixes) or want to have them on special testcases only or if I have the same names for testcases in different test suites. I gonna have to work this out now which way will be best for my project.

    Thanks again for your help!
  • knaecke wrote:
    Yeah I have tried this too. But maybe I did something wrong.

    I have used option -D with my testrunner.sh (I work on Linux) but I never got a line saying "01:20:05,234 INFO [PropertyExpansionRequestFilter] Loaded 52 properties from [C:\workspace\core\project.properties]" neither an error telling my my parameter at -D could be wrong. There were also no changes within my properties. So I felt stuck and tried another way.


    I VERY MUCH agree with this comment. I am having the same issue and it is very frustrating. I have passed these "-D" args to my testrunner.bat :
    -D^"soapui.properties=%BIN_HOME%\soapui.properties^" -D^"soapui.home=%BIN_HOME%^"
    and YET they do not load and there is no message saying why. I am just about ready to code some Groovy to try working around it.