The Properties file lets you store the keywords for data driven tests. Here, the Properties file acts as a data-source; it is used to handle small data files.
1| Open Eclipse IDE
2| Expand the project you are working
3| Right click on the src folder
4| New > Other... > General > File
5| Name the file with extension .properties. e.g., config.properties
6| Copy & paste the following and replace the keywords
search=keyword1,keyword2,keyword3
7| Save the properties file now.
Snippet
import java.util.ResourceBundle;
import java.util.StringTokenizer;
driver = new FirefoxDriver();
baseUrl = "http://xyz.com";
ResourceBundle bundle = ResourceBundle.getBundle("config");
String Channel = bundle.getString("search");
StringTokenizer st = new StringTokenizer(Channel, ",");
while (st.hasMoreTokens()) {
String value = st.nextToken();
driver.get(baseUrl + "/");
driver.findElement(By.id("")).click();
driver.findElement(By.id("")).sendKeys(value);
}
Alternate way to fetch Properties file
#Example1
import java.io.FileInputStream;
import java.util.Properties;
driver = new FirefoxDriver();
driver.get("http://xyz.com/");
FileInputStream fs = new FileInputStream("C:\\config.properties");
Properties prop = new Properties();
prop.load(fs);
String value = prop.getProperty("search");
System.out.println(prop.getProperty("search"));
driver.findElement(By.id("")).click();
driver.findElement(By.id("")).sendKeys(value);
#Example2
import java.io.FileInputStream;
import java.util.Properties;
driver = new FirefoxDriver();
driver.get("http://xyz.com/");
FileInputStream fs = new FileInputStream("C:\\config.properties");
Properties prop = new Properties();
prop.load(fs);
System.out.println(prop.getProperty("path"));
String dd = prop.getProperty("search");
System.out.println(prop.getProperty("search"));
driver.findElement(By.id(prop.getProperty("path"))).click();
driver.findElement(By.id("")).sendKeys(dd);
Let the config.properties File be
path=//*[@id=’clickme’]
search=keyword1
Thanks for the great information in your blog Selenium Training in Chennai
ReplyDeleteI have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Java Training in Chennai | Core Java Training in Chennai
Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes
Java Training Institutes in Chennai Java Training in Chennai
It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai
ReplyDeleteThis comment has been removed by the author.
ReplyDelete