In selenium WebDriver software automation testing tool, There Is non whatsoever built In facility to create object repository. So maintenance of page objects(Page chemical component division locators) becomes real difficult If you lot volition write all objects of page on code level. Let me plow over you lot 1 elementary illustration - You convey 1 search push on page of software spider web application as well as you lot convey used It(Using Id locator) In many of your attempt cases. Now supposing individual has changed Its Id In your application as well as thus what you lot volition do? You volition cash inward one's chips for replacing Id of that chemical component division In all attempt cases wherever It Is used? It volition practise overhead for you. Simple solution to take this overhead Is creating object repository using properties File back upward of coffee software evolution language. In properties file, First nosotros tin lavatory write chemical component division locator of software spider web chemical component division as well as and thus nosotros tin lavatory operate It In our attempt cases.
Let us travail to practise object repository for elementary estimator application given on THIS PAGE as well as and thus volition travail to practise attempt instance for that calc software application using object repository..
How to practise novel properties file
To practise novel properties file, Right click on your projection packet -> New -> Other .
It volition opened upward New wizard. Expand General folder In New sorcerer as well as guide File and click on Next button.
Give file name objects.properties on adjacent window and click on Finish button.
It volition add together object.properties file nether your package. Now re-create glue bellow given lines inward objects.properties file. So at in 1 lawsuit this objects.properties file Is object repository for your spider web application page calc.
objects.properties file
#Created unique primal for Id of all spider web elements. # Example 'one' Is primal as well as '1' Is ID of spider web chemical component division push 1. one=1 two=2 three=3 four=4 five=5 six=6 seven=7 eight=8 nine=9 zero=0 equalsto=equals cler=AC result=Resultbox plus=plus minus=minus mul=multiply
In to a higher house file, Left side value Is primal as well as correct side value Is chemical component division locator(by Id) of all spider web elements of spider web calculator. You tin lavatory operate other chemical component division locator methods besides similar xpath, css ect.. VISIT THIS LINK to thought dissimilar chemical component division locator methods of webdriver.
Now allow us practise webdriver attempt instance to perform roughly operations on calculation. In bellow given example, All the chemical component division locators are coming from objects.properties file using obj.getProperty(key). Here primal Is reference of chemical component division locator value inward objects.properties file.
package ObjectRepo; 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; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; world degree CalcTest { WebDriver driver = novel FirefoxDriver(); @BeforeMethod world void openbrowser() throws IOException { driver.manage().window().maximize(); driver.get(" "); } @AfterMethod world void closebrowser() { driver.quit(); } @Test world void Calc_Operations() throws IOException{ //Create Object of Properties Class. Properties obj = novel Properties(); //Create Object of FileInputStream Class. Pass file path. FileInputStream objfile = novel FileInputStream(System.getProperty("user.dir")+"\\src\\ObjectRepo\\objects.properties"); //Pass object reference objfile to charge method of Properties object. obj.load(objfile); //Sum functioning on calculator. //Accessing chemical component division locators of all spider web elements using obj.getProperty(key) driver.findElement(By.id(obj.getProperty("eight"))).click(); driver.findElement(By.id(obj.getProperty("plus"))).click(); driver.findElement(By.id(obj.getProperty("four"))).click(); driver.findElement(By.id(obj.getProperty("equalsto"))).click(); String i = driver.findElement(By.id(obj.getProperty("result"))).getAttribute("value"); System.out.println(obj.getProperty("eight")+" + "+obj.getProperty("four")+" = "+i); driver.findElement(By.id(obj.getProperty("result"))).clear(); //Subtraction functioning on calculator. //Accessing chemical component division locators of all spider web elements using obj.getProperty(key) driver.findElement(By.id(obj.getProperty("nine"))).click(); driver.findElement(By.id(obj.getProperty("minus"))).click(); driver.findElement(By.id(obj.getProperty("three"))).click(); driver.findElement(By.id(obj.getProperty("equalsto"))).click(); String j = driver.findElement(By.id(obj.getProperty("result"))).getAttribute("value"); System.out.println(obj.getProperty("nine")+" - "+obj.getProperty("three")+" = "+j); } }
Run to a higher house given illustration In your eclipse as well as uncovering execution.
Now supposing I convey many such attempt cases as well as roughly 1 has changed Id of whatsoever push of calc application as well as thus what I convey to do? I convey to modify all attempt cases? Answer Is No. I simply postulate to modify objects.properties file because I convey non operate element's Id straight In whatsoever attempt instance but I convey Used simply Its primal reference In all attempt cases.
This agency you lot tin lavatory practise object repository of all your software spider web elements In 1 .properties file. You tin lavatory VIEW MORE TUTORIALS close selenium webdriver.
http://www.software-testing-tutorials-automation.com/