In my JAVA+cucumber framework I have the flexibility to change the base URL by passing the parameter -Dwebdriver.base.url=
in CLI. I want similar flexibility to set @DefaultUrl
also.
To achieve this - I will be using a properties file, if this property file is present use it else use default ones.
But question is: How to pass URL from properties file in @DefaultUrl
annotation? Page class which is extending base class doesnt understand the properties variable.
I wanted to do it like :
@DefaultUrl(properties.getProperty("homepage"))
public class homePage extends BasePage {
// TO DO
}
E.g.
@DefaultUrl("http://jira.mycompany.org")
@NamedUrls(
{
@NamedUrl(name = "open.issue", url = "http://jira.mycompany.org/issues/{1}")
}
)
public class JiraIssuePage extends PageObject {
...
}
I have below function in base class to read properties file:
public static String value(String propKey) {
if (prop == null) {
prop = new Properties();
try {
FileInputStream fis = new FileInputStream(
System.getProperty("user.dir") + "properties.properties");
properties.load(fis);
} catch (Exception e) {
e.printStackTrace();
}
}
String pvalue = properties.getProperty(propKey);
if (properties.containsKey(propKey) == false) {
logger("key not correct")
} else {
return pvalue ;
}
return pvalue;
}