Parameterize properties file in Java
If you are using a properties file and passing key value pairs, there are instances when you would want to parameterize the values passed. In my case the dynamic xpaths need to be parameteized for more flexibility
Solution: MessageFormat
Steps to achieve this :
- Your properties file should have the key value as :
- HomePage.DynamicObject.Button=//*[@text=''{0}'' and @width>0]
- In the above statement {0} is the parameter
- In your class file that calls the property
- Properties obprop = new Properties();
- String Locator= MessageFormat.format(obprop.getProperty(Object_Identifier), params);
- where Object_Identifier is HomePage.DynamicObject.Button
- and params is the parameter you want to pass
Note: Within a String, a pair of single quotes can be used to quote any arbitrary characters except single quotes. For example, pattern string "'{0}'" represents string "{0}", not a FormatElement. ...
Any unmatched quote is treated as closed at the end of the given pattern. For example, pattern string "'{0}" is treated as pattern "'{0}'".
Comments
Post a Comment