Monday 8 February 2016

How to read data from object repository in selenium

How to read data from object repository in selenium:
========================================

Object Repository:
====================

Object Repository is a place where we can store all the web element identifications like xpaths,ids and names etc....

In general in order to convey a file as object repository we need to save that file as .properties extension.

file name can be any thing but convention sake we used to save that file as OR.properties

//sample example on object repository
==============================
OR.properties:
----------------

element_Username         =    //*[@id='Email']

element_Next        = //*[@id='next']

element_Password       = //*[@id='Passwd']

element_Signin       = //*[@id='signIn']


ObjectRepoDemo.java:
-------------------------------
package files;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ObjectRepoDemo {

public static void main(String[] args) throws IOException, InterruptedException {

FileInputStream fileInputStream = new FileInputStream("D:\\ramesh\\sampleproject\\src\\files\\OR.properties");

Properties properties = new Properties();

properties.load(fileInputStream);

String gmailUserName  = properties.getProperty("element_Username");

String gmailNext  =  properties.getProperty("element_Username");

String gmailPassword  =  properties.getProperty("element_Username");

String gmailSignin  =  properties.getProperty("element_Username");

WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.manage().deleteAllCookies();

driver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);


driver.get("https://www.gmail.com");
WebElement element_Username = driver.findElement(By.xpath(gmailUserName));
element_Username.clear();
element_Username.sendKeys("rameshat914@gmail.com");


WebElement element_Next = driver.findElement(By.xpath(gmailNext));
element_Next.click();

Thread.sleep(3000);

WebElement element_Paswword = driver.findElement(By.xpath(gmailPassword));
element_Username.clear();
element_Username.sendKeys("rameshat914@gmail.com");


WebElement element_Signin = driver.findElement(By.xpath(gmailSignin));
element_Next.click();
}

}

No comments:

Post a Comment