Friday, January 17, 2014

How to read the properties from property file using java in Selenium


package TestNG;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import jxl.read.biff.BiffException;
import org.openqa.selenium.By;
import org.openqa.selenium.NotFoundException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import Claims.FetchExcelData;
public class secondfile {
public static void main(String[] args) throws IOException, NotFoundException, BiffException, InterruptedException
{
       System.setProperty("webdriver.ie.driver", "C:\\Selenium Automation\\IeServerDriver\\IEDriverServer.exe");
       WebDriver wd = new InternetExplorerDriver();
       wd.get(FetchExcelData.Fetch("C:\\Selenium Automation1\\Test data\\TestData.xls", "URL"));
Properties p=new Properties();
FileInputStream f=new FileInputStream("C:\\Selenium Automation1\\SeleniumPro\\src\\TestNG\\prop.properties");
p.load(f);
wd.findElement(By.name(p.getProperty("username"))).sendKeys("admin");
wd.findElement(By.name(p.getProperty("password"))).clear();
wd.findElement(By.name(p.getProperty("password"))).sendKeys("admin");
wd.findElement(By.name(p.getProperty("Login"))).click();
 
    }
}

No comments:

Post a Comment

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...