It is always advised to use a config file in your test automation. The purpose of having a config file is to have few variables outside of code so that if you can change variables' values without changing your code.
To use a config file in Java, Apache's common configuration jar is very popular and easy to use.
Download the latest version of these jar and add them to Project's Build Path.
To use a config file in Java, Apache's common configuration jar is very popular and easy to use.
Download the latest version of these jar and add them to Project's Build Path.
commons-lang-2.6.jar
commons-configuration-1.10.jar
Here is the sample code to read config:
Copy the below line in a notepad and save it with some valid extension. qaURL is the variable being called in above program. This will serve the purpose of a config file.
## is used to comment the line.
Sample:
## Please provide the URL here:
qaURL = https://www.google.com
commons-configuration-1.10.jar
Here is the sample code to read config:
public static void InitializeConfiguration()
{
PropertiesConfiguration propertyConfigFile;
try
{
propertyConfigFile = new PropertiesConfiguration();
String config = "/config/config.txt"; //Location of config file
propertyConfigFile.load(config);
//Read variable from config
String url = propertyConfigFile.getProperty("qaURL").toString();
}
catch(ConfigurationException e)
{
System.out.println("Error Occured While Reading Config File");
}
}
Copy the below line in a notepad and save it with some valid extension. qaURL is the variable being called in above program. This will serve the purpose of a config file.
## is used to comment the line.
Sample:
## Please provide the URL here:
qaURL = https://www.google.com