How they Work
In the test data in the Excel sheet, you can write these nice property placeholders: *${foo.bar}. They are very convenient for making test data dependent on the current user (use ${user.name} or for placing the current time and date in your test case.
TODO: Image, Excel sheet with property placeholder
They work in much the same way as the PropertyPlaceholderConfigurer in the Spring Framework. DDSteps will replace these placeholders by...
- Looking for a system property with that key. (Java has a lot of default system proerpties, like ${user.name}).
- Looking up the key in the file ddsteps-placeholders.properties.
For example:
If you have an excel file with:
| text |
| Some *${foo.bar} here. |
And the system properties contain:
And the ddsteps-placeholders.properties file contains:
Then the text property in your test class will be injected with the String "Some fruit here", since the system properties takes precedence.
System properties
The system properties are checked first, so if you want to override something from Ant, just put it in the system properties, and that will be used first.
There are some good system properties that you may want to use:
| Property |
Contents |
| user.name |
The user login id |
| user.home |
The user's home directory |
The ddsteps-placeholders.properties file
DDSteps expects this file to be present in the root of your classpath. DDSteps uses the Java classloader to load it, so just put it in the default package (typically directly in the source folder in your IDE).
The file is called ddsteps-placeholders.properties and is a standard Java properties file - that means you have to quote characters. Read the JavaDocs for java.util.Properties.
Adding support for Property Placeholders
Already included!
Support is already included when you:
- Extend org.ddsteps.testcase.support.DDStepsExcelTestCase.
- Get your DataLoader from:
- org.ddsteps.data.support.DataLoaderFactory.getCachingExcelDataLoader() (DDSteps 1.1)
- org.ddsteps.data.excel.CachingExcelDataLoader.getInstance() (DDSteps 1.0, deprecated)
- new org.ddsteps.data.excel.CachingExcelDataLoader() (DDSteps 0.x, deprecated)
- Get your DataSetLoader from:
- org.ddsteps.dataset.support.DataSetLoaderFactory.getPropertyPlaceholderExcelDataSetLoader() (DDSteps 1.1)
- org.ddsteps.dataset.support.DataSetLoaderFactory.getCachingPropertyPlaceholderExcelDataSetLoader() (DDSteps 1.1)
Add support to your DataSetLoader
Scary technical details ahead!
Property Placeholders are added to your DataSet using the DecoratingDataSetLoader.
TODO: Beef up this doc.
If you want to roll your own DataSetLoader with PropertyPlaceholder support, look at the source here:
org.ddsteps.dataset.support.DataSetLoaderFactory.getCachingPropertyPlaceholderExcelDataSetLoader()
See also: [DataSetLoaders].