***********************************
Reading property file made easly with Owner library
***********************************
In test automation we need to read properties from external source as a
file. In many cases you need to override some properties when doing integration
testing and sometime we need to change the property value at runtime. Here Owner
library is the best suited for managing the properties.
Let’s imagine we will use a property file to manage the different data
and/or configuration for a web test. We have this file as an example:
How to Implement:
1.
Import the Owner library.
<script
src="https://gist.github.com/swapnil358/3da4902d00e261395e91852d5a16301c.js"></script>
1.
Create an interface and extends Config
from package ‘org.aeonbits
.owner.Config
’
2.
Define the properties file location
3.
Define the properties with the same name we have in
the properties file.
Owner will do the trick
automatically it will map the property automatically with property name defined
in property file as shown in above code snippet.
For example:
If you defined String browser() attribute
in the class same as property in properties file.
4.
@DefaultValue annotation
will be used to if you do not have property defined in the file but you want to
use the property then you can use this annotation.
5.
@Key this annotation will map the attribute name
with poperty file key.
6.
In case if you have composite name url.base
you can use the @Config.Key annotation
to associate the property in the FrameworkConfig.properties file
into the class.
How to read the values from the properties file
<script
src="https://gist.github.com/swapnil358/ae20123936dde2481eed53c9bf9be03f.js"></script>
1. FrameworkConfig class and attribute receiving
the ConfigFactory.create(FrameworkConfig.class).
This line will tell Owner to load the FrameworkConfig.properties file
and associate all the properties and values to the FrameworkConfig
class.
2. We are using the attribute FrameworkConfig to read the properties values. Each method
will return the corresponding property value.
3. Below Screenshot, we are merging two property
file