ObjectRepo (Autosaved) - 2
ObjectRepo (Autosaved) - 2
As per the rule of the automation, we should not hardcode[fixed]elements with in test
Scripts instead, we should get elements from Object Repository , because in Agile process due to
frequent requirement changes , modification & maintenance of elements is tedious job
5. Why POM ?
It’s a well-organized structured design pattern, where we can maintain all the web elements in
page wise, due to POM design pattern maintains & modification is easy & faster.
6. Advantages of POM:
1. Well organized structure
2. Handle stale element exception.
3. maintains & modification of element is easy
4. We can directly store Web Elements in java class
5. Better fit for Agile processes
6. Support Auto healing feature
7. Why @FindBy & @Findall annotation instead of driver.findElement(“locator”)
Ans : to avoid staleElementReferenceException & also we can use Auto heling feature in
@findAll annoation
8. What is staleElementReferenceException ?
It’s one of selenium Exception , whenever webdriver try to identify an element , element
was available in GUI, but at time of performing an action on the elements element was
not recognized due to page got refreshed or elements may become old or element not
attached to page in such case we get staleElementReferenceException
9. Rules of POM
Rule 1 : create separte java class for every page in a application & class name should be same page
name
Rule 2 : Identify all the elements using @findBy & @findAll , @findbys annotations & store them in
speific pom / java class (Element declartion)
Rule3 : For Every POM class create Constructor to get an Object of the POM class , inside the
Constructor use Pagefactory.initElement() to initialize the Page Elements at the time Object
creation, in order to initialize all the page Elements we should use Pagefactory.initElement()
(Element initialization)
Rule 4 : declare all the WebElements as private & provide getters methods to accesses elements in
testScripts class [this processes is called Encapsulation]
Note : to create getters mtds inside the java class fallow below steps
=>place cursor inside the class🡺 Right click🡺source 🡺generate getters & setters 🡺 select the
getters check box 🡺 click on ok button
Rule 5 : Go to every Page & identify the reusable business libraries & implement them in same POM
class [Utilization]
There are two ways , we can utilize the POM elements in testScropts
POM is java design pattern, where will maintain all the Web element locator in well-
organized manner
Pagefactory it’s an extended design pattern of POM , which is used to create an Object to POM
classes , & at the time of object creation it will execute all @findBy @findbys annotation then
initialize all the elements
All annotation available in Selenium webdriver, its traditional ways to identify the elements in GUI.
@findBy : used to identify the element using one locator or one condition
@findAll : it contains multiple @findBy annotation , it mean we can identify the same element using
multiple locator (multiple conditions) , it will use OR condition during execution of locator
AutoHealing : during execution , if one locator fails to identify the element , it will retry to identify
the same element using another locator
@FindBys : it contains multiple @findBy annotation , it mean we can identify the elements using
multiple locator (multiple conditions) , it will use AND condition to during execution of locator
Project Structure
Pom Classes : Login
package com.crm.comcast.pomrepositoryutility;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.crm.comcast.genericutility.WebDriverUtlity;
/**
* @author Deepak
*/
WebDriver driver;
this.driver = driver;
PageFactory.initElements(driver, this);
return productLnk;
@FindBy(linkText = "Contacts")
@FindBy(linkText = "Campaigns")
@FindBy(xpath = "//img[@src='themes/softed/images/user.PNG']")
@FindBy(linkText = "Organizations")
private WebElement orgLink;
@FindBy(linkText = "More")
@FindBy(linkText = "Vendors")
@FindBy(linkText = "Products")
return driver;
return orgLink;
return contactLnk;
return moreDropDownMenu;
return campaginLnk;
return signOutLnk;
/**
*/
mouseOverOnElement(driver, adminImg);
signOutLnk.click();
mouseOverOnElement(driver, moreDropDownMenu);
waitForElement(driver, campaginLnk);
campaginLnk.click();
/**
*/
mouseOverOnElement(driver, moreDropDownMenu);
waitForElement(driver, vendorsLnk);
vendorsLnk.click();
========================Products=============
package com.crm.comcast.pomrepositoryutility;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
WebDriver driver;
this.driver = driver;
PageFactory.initElements(driver, this);
@FindBy(id="search_txt")
@FindBy(name = "search")
return searchProductsEdt;
return searchBtn;
}
@FindBy(xpath = "//img[@title='Create Product...']")
return createProductImg;
package com.crm.comcast.pomrepositoryutility;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
WebDriver driver;
this.driver = driver;
PageFactory.initElements(driver, this);
@FindBy(name = "productname")
productNameEdt.sendKeys(productName);
saveBtn.click();
=======================Camapgins===================
package com.crm.comcast.pomrepositoryutility;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
WebDriver driver;
this.driver = driver;
PageFactory.initElements(driver, this);
return createnewCamapaignBtn;
}
package com.crm.comcast.pomrepositoryutility;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.crm.comcast.genericutility.WebDriverUtlity;
WebDriver driver;
this.driver = driver;
PageFactory.initElements(driver, this);
@FindBy(name = "campaignname")
return campaignEdt;
return saveBtn;
return productLookUpImg;
/**
* @param campaginName
*/
campaignEdt.sendKeys(campaginName);
saveBtn.click();
/**
* @param campaginName
*/
campaignEdt.sendKeys(campaginName);
productLookUpImg.click();
swithToWindow(driver, "Products&action");
pp.getSearchProductsEdt().sendKeys(productName);
pp.getSearchBtn().click();
driver.findElement(By.xpath("//a[text()='"+productName+"']")).click();
swithToWindow(driver, "Campaigns&action");
saveBtn.click();
==================================Campagain Information===============
package com.crm.comcast.pomrepositoryutility;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
WebDriver driver;
this.driver = driver;
PageFactory.initElements(driver, this);
@FindBy(className = "dvHeaderText")
return orgNAmeInfo;
return orgHeaderSucMsg;