What Is Page Object Model Using Selenium Webdriver 20230227 Lyst5796
What Is Page Object Model Using Selenium Webdriver 20230227 Lyst5796
1- It is design pattern in which will help you to maintain the code and code duplication,
which is a crucial thing in Test automation.
2- You can store all locators and respective methods in the separate class and Call them
from the test in which you have to use. So the benefit from this will be if any changes in
Page then you do not have to modify the test simply modify the respective page and that
all.
3- You can create a layer between your test script and application page, which you have
to automate.
4- In other words, it will behave as Object repository where all locators are saved.
Implementation of Page Object model using Selenium Webdriver
1 – Page Object model without PageFactory
2- Page Object Model with Pagefactory.
What is Page Factory in Selenium?
@FindBy(locataorname=”value”)
Webelement user;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
* This class will store all the locator and methods of login page
*/
WebDriver driver;
By username=By.id("user_login");
By password=By.xpath(".//*[@id='user_pass']");
By loginButton=By.name("wp-submit");
this.driver=driver;
driver.findElement(username).sendKeys(userid);
driver.findElement(password).sendKeys(pass);
driver.findElement(loginButton).click();
{
driver.findElement(username).sendKeys(uid);
driver.findElement(password).sendKeys(pass);
driver.findElement(loginButton).click();
package com.wordpress.Testcases;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import com.wordpress.Pages.LoginPage;
public class VerifyWordpressLogin
@Test
driver.manage().window().maximize();
driver.get("http://demosite.center/wordpress/wp-login.php");
login.clickOnLoginButton();
driver.quit();
}
http://artoftesting.com/automationTesting/pageObjectModel.html