Properties file: properties
file used for storing some general information and can be reused in any java
file (class) just by loading it. The following statements need to be used in
that particular class
Properties p=new Properties();
FileInputStream i=new
FileInputStream("path of the properties file");
Note: we need keep \\ each and every
place
p.load(i);
e.g.: Properties p=new Properties();
FileInputStream i=new FileInputStream("C:\\Users\\BUJJI\\workspace\\webdriverproject\\src\\pack1\\objrep");
p.load(i);
Note: after pasting
path of the properties file, here we need to use \\ instead of (or in place of)
\. (In java programming directories are separated by \\)
To retrieve any value from the Properties file we
need to follow the below syntax
p.getProperty(“property name”);
Object Repository: in selenium there is no object repository
concept but we will store all the objects information in the properties file
and will treat it as object repository
The same way how we load the properties file we
can load the object repository.
The same way how we use the properties file we can
use the object repository.
Navigation for creating properties file:
Right click on package
Go to new then click on other or CRTL+N
Click on General expand it then select File
Click on next
Specify the name then click finish.
TELUGU MATRIMONY
public static void main(String[] args) throws InterruptedException,
IOException {
WebDriver wd=new FirefoxDriver();
wd.get("http:telugumatrimony.com");
Properties p=new Properties();
FileInputStream
fis=new FileInputStream("D:\\sel\\wd\\src\\aki");
p.load(fis);
wd.findElement(By.name(p.getProperty("a"))).sendKeys("myself");
wd.findElement(By.name(p.getProperty("b"))).sendKeys("akhil");
wd.findElement(By.name(p.getProperty("c"))).click();
wd.findElement(By.name(p.getProperty("d"))).sendKeys("24");
wd.findElement(By.name(p.getProperty("e"))).sendKeys("apr");
wd.findElement(By.name(p.getProperty("f"))).sendKeys("1984");
wd.findElement(By.name(p.getProperty("g"))).sendKeys("hindu");
wd.findElement(By.name(p.getProperty("h"))).sendKeys("telugu");
wd.findElement(By.name(p.getProperty("i"))).sendKeys("Adi Andhra");
wd.findElement(By.name(p.getProperty("j"))).sendKeys("india");
wd.findElement(By.name(p.getProperty("k"))).sendKeys("+91");
wd.findElement(By.name(p.getProperty("l"))).sendKeys("9440592994");
wd.findElement(By.name(p.getProperty("m"))).sendKeys("akhilreddyhyd@gmail.com");
wd.findElement(By.name(p.getProperty("n"))).sendKeys("akhil");
wd.findElement(By.xpath(".//*[@id='hp-regform-new']/div[4]/input[6]")).click();
}
GMAIL
NAME
package pack1;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class propertyfile {
public
static void main(String[] args) throws IOException {
WebDriver
wd=new FirefoxDriver();
wd.get("http:gmail.com");
Properties
p =new Properties();
FileInputStream
ip = new FileInputStream ("C:\\Documents and
Settings\\srss\\ravi\\webdriver1\\src\\pack1\\akkki");
p.load(ip);
wd.findElement(By.name(p.getProperty("un"))).sendKeys("akhilreddyhyd@gmail.com");
wd.findElement(By.name(p.getProperty("pwd"))).sendKeys("venkanna143");
wd.findElement(By.name(p.getProperty("login"))).click();
}
No comments:
Post a Comment