Showing results for 
Search instead for 
Did you mean: 

Loading testcase properties from the command line

New Contributor

Loading testcase properties from the command line

Reading the documentation ( 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:

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?

Re: Loading testcase properties from the command line

Hi Margaret,

It is possible to load global properties from the command-line by specifying 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 context )
def propFileName
Properties extraProps
try { "About to access 'extraPropsFile' property"
propFileName = groovyUtils.expand('${#Project#extraPropsFile}')
if (!propFileName)
throw new IllegalArgumentException("Property 'extraPropsFile' not set!") "String propFile = '$propFileName'"
FileInputStream propFileInput = new FileInputStream(propFileName)
extraProps = new Properties()
extraProps.load(propFileInput) "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

I guess this is what you needed.

/Nenad Nikolic

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 12
2 nmrao 8
3 HimanshuTayal 3
Top Kudoed Authors