- In below code filepath parameter will contain the path where we will keep the properties file and key parameter is the name of the value which we want fetch.
- public is the access modifier
- static so that we can access the class without creating object
- String is the return type of propertyReader function
============================
public static String propertyReader(String filePath,String key)
{
String value = null;
//Inputstream is required while loading into properties
try (InputStream input = new FileInputStream(filePath))
{
// object creation for Property class
Properties prop = new Properties();
// load a properties file
prop.load(input);
//getProperty will fetch the value according to the key
value=prop.getProperty(key);
} catch (IOException ex) {
ex.printStackTrace();
}
return value;
}
- How to setup API automation framework with gradle from scratch?
Click Here for Steps - How to generate Random String at runtime?
Click Here For Code
*************************************************
API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign
Java Related Interview Question Set
https://automationreinvented.blogspot.com/search/label/Java
GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT
Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions
Note: If anyone need help in designing framework or virtual support for Automation work then reach out to me @sidharth.shukla19@gmail.com/9619094122
***********************************
For training check the Training link as below:
Training Details
More content for Interview preparation:
How to add execution status to Extent Report
what is best case to use properties file in industry
ReplyDeleteproject settings and configuration data with database configuration
DeleteThis comment has been removed by the author.
ReplyDelete