Earn Money in 10 days

Selenium Videos

Protractor In Selenium

Livechat

Showing posts with label Object Repository/Property File. Show all posts
Showing posts with label Object Repository/Property File. Show all posts

Tuesday, 4 November 2014

What is object repository/Property file in selenium.


Why we used property file in Selenium?
Whats the need of Property File/Repository??
Parameterization of a particular test is needed in order to avoid hard coding of values. The following Example actually demonstrates the usage of parameterization.
Let us assume that our test suite contains more than 1000 test cases and more than 50 different screens and we have thousands of objects on the application under test.  Multiple test cases may be (more than 10) using a particular screen.  If there is a change request from the client to enhance / change any of the object, then we need to update all the test cases. So its very difficult to change in Test cases.For avoiding updation in Testcases.We Create an Object Repository.If there are any changes in the application then we need to update only Object Repository.
What is Object Repository/Property File
In QTP, there is a concept called “Object Repository”.  All the objects are added to Object Repository.
So how we will do this in Selenium..You will used this object repository in framework a lot.
How to use Object Repository In selenium?
Step1:Create a new Project>Click on Finish
Step2:Make a package as config>Click on Finish


Step3:Now Right Click on config(Packagename)>New>Other

Step4:Click on other>ClickGeneral>Click on File
Step5:Now enter the name of propertyfile..or.properties>Click on Finish

Step6:Now Add the details in property file
propertyfile for gmail login..

How to use Property file
Create a new class as ReadingPropertyFile


//Here is the code for Reading property file
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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 ReadingPropertyFile {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
//For reading property file we have to create object
    //Create an object of property class
//import property files.
Properties prop = new Properties();
//Now make an object of file input stream
//import the files after creating object
FileInputStream ip = new FileInputStream("D:\\User\\workspace2\\PropertyDemo\\src\\config\\OR.properties");
prop.load(ip);
System.out.println("load all propeties");
//launch instance of any browser
WebDriver driver = new FirefoxDriver();
//now open gmail/browser
driver.get("http://gmail.com");
//now pass the xpath by property file
driver.findElement(By.cssSelector(prop.getProperty("username"))).sendKeys("ritu7180");

driver.findElement(By.cssSelector(prop.getProperty("password"))).sendKeys("password");

driver.findElement(By.cssSelector(prop.getProperty("signup"))).click();
}

}
Reading property file is very easy.
Just Follow four steps:
Step1:make an object of Property class 
Properties prop = new Properties();
Step2:Make an Object of InputStreamClass
FileInputStream ip = new FileInputStream ip();
Step3:Pass the path of propertyfile in the fileinputstream constuctor.

Step4:load the property file by..
prop.load(ip);

Popular Posts

 
subscribe
Subscribe Us
emailSubscribe to our mailing list to get the updates to your email inbox... We can't wait more to have your email in our subscribers email list. Just put your nice email in below box: