Forum Discussion

Margaret_Grün-K's avatar
Margaret_Grün-K
New Contributor
15 years ago

Loading testcase properties from the command line

Reading the documentation (http://www.soapui.org/userguide/properties.html) about loading properties from files I am missing following information:

I would like to specify both project and testcase properties and have them loaded from a properties file from the command line.
The SOAP request has following fields:
      ${#Project#prop1}
      ${#TestCase#prop2}1


1) Is it possible to set prop1 and prop2 from a properties file specified on the command line?
2) If yes what should the contents of the properites file be?

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Margaret,


    It is possible to load global properties from the command-line by specifying -Dsoapui.properties=global-custom.properties option. Properties loaded from the specified .properties file will then show up in Preferences->Global Properties dialog and be available everywhere (i.e. all of your test projects/suites/cases/steps).

    Alternatively, if you need finer control over the scope of loaded properties, you would need to program property loading manually in Groovy.
    Here's one way to do it: define a command-line property that specifies the name of the .properties file which you would then access from a Groovy script and set the test case's properties like this:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def propFileName
    Properties extraProps
    try {
    log.info "About to access 'extraPropsFile' property"
    propFileName = groovyUtils.expand('${#Project#extraPropsFile}')
    if (!propFileName)
    throw new IllegalArgumentException("Property 'extraPropsFile' not set!")
    log.info "String propFile = '$propFileName'"
    FileInputStream propFileInput = new FileInputStream(propFileName)
    extraProps = new Properties()
    extraProps.load(propFileInput)
    log.info "Loaded extra, command-line props: $extraProps"
    // Set the pre-defined properties in this case's test step. You can loop through all loaded properties.
    // groovyUtils.setPropertyValue("Extra Properties", "someProp", propValue)
    } catch (e) {
    log.warn "Error: $e"
    }


    If you're using Project scope for the .properties file name as i did above, you would need invoke test runner from the command-line option:

    testrunner.bat myproject.xml -c MyTestCase -PextraPropsFile=project-custom.properties


    I guess this is what you needed.


    Cheers!
    /Nenad Nikolic