HomePage:
package pageObjects;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class
Home_Page {
private static
WebElement element = null;
public static
WebElement lnk_MyAccount(WebDriver driver){
element =
driver.findElement(By.id("account"));
return element;
}
public static WebElement
lnk_LogOut(WebDriver driver){
element =
driver.findElement(By.id("account_logout"));
return element;
}
}
LoginPage:
package pageObjects;
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class LogIn_Page {
private static
WebElement element = null;
public static WebElement
txtbx_UserName(WebDriver driver){
element =
driver.findElement(By.id("log"));
return
element;
}
public static WebElement
txtbx_Password(WebDriver driver){
element =
driver.findElement(By.id("pwd"));
return
element;
}
public static WebElement
btn_LogIn(WebDriver driver){
element =
driver.findElement(By.id("login"));
return
element;
}
}
Test Class/page object model:
package automationFramework;
import
java.util.concurrent.TimeUnit;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.firefox.FirefoxDriver;
// Import package
pageObject.*
import
pageObjects.Home_Page;
import
pageObjects.LogIn_Page;
public class PageObjectModel {
private static WebDriver driver = null;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://www.store.demoqa.com");
// Use page Object library now
Home_Page.lnk_MyAccount(driver).click();
LogIn_Page.txtbx_UserName(driver).sendKeys("testuser_1");
LogIn_Page.txtbx_Password(driver).sendKeys("Test@123");
LogIn_Page.btn_LogIn(driver).click();
System.out.println(" Login
Successfully, now it is the time to Log Off buddy.")
Home_Page.lnk_LogOut(driver).click();
driver.quit();
}
}