Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

How to read properties file?

Category: Selenium WebDriver
Create a new file and give file name as Object_Repo (depends on you)with extension .properties

// Specify the file location I used . operation here because
//we have object repository inside project directory only

File src=new File("".Object_Repo.properties"");
// Create  FileInputStream object
FileInputStream fis=new FileInputStream(src);

// Create Properties class object to read properties file
Properties pro=new Properties();
// Load file so we can use into our script
pro.load(fis);
System.out.println(""Property class loaded"");

// Open FirefoxBrowser
WebDriver driver=new FirefoxDriver();
// Maximize window
driver.manage().window().maximize();
// Pass application
driver.get(""http://www.facebook.com"");
// Enter username here I used keys which is specified in Object repository.
// Here getProperty is method which
// will accept key and will return value for the same
driver.findElement(By.xpath(pro.getProperty(""facebook.login.username.xpath""))).
sendKeys(""Selenium@gmail.com"");

Leave a Reply

Your email address will not be published. Required fields are marked *