How can I create a POM test case in Selenium Webdriver?

0 votes
Can anyone suggest how can I create a POM test case in Selenium Webdriver?
May 11 in Selenium by Akshay
16 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Hey Akshay, follow these steps to create a POM test case in Selenium Webdriver:

1. Create a New Package file and name it as ‘pageObjects’, by right clicking on the Project and select New > Package. Keep in mind to create different packages for Page Objects, Utilities, Test Data, Test Cases and Modular actions. It's recommended to use this structure, as it is easy to understand, easy to use and easy to maintain.

2. Create a New Class file and refer the name to the actual page from the test object, by right click on the above created Package and select New > Class. For eg. In our case it is Home Page and LogIn Page.

3. Now create a Static Method for each Element (Object) in the Home Page. Each method will have an Argument (driver) and a Return value (element).

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;
    }
} 

4. Next create a New Class and name it as POM_TC by right click on the ‘automationFramework‘ Package and select New > Class. We will be creating all our test cases under this package. 

package automationFramework;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
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();
   }
}

5. Finally your Project Explorer would look like this:

answered May 12 by Anvi
• 5,880 points

Related Questions In Selenium

0 votes
1 answer

How to create a test case with TestNG in Selenium?

Hey Deepak, to create a Test Case ...READ MORE

answered 1 day ago in Selenium by Abha
• 5,840 points
12 views
0 votes
1 answer

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,030 points
120 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
60 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
432 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
49 views
0 votes
1 answer

How can I write test scripts in Selenium with python?

Hey Khushi, writing test scripts in Selenium ...READ MORE

answered May 9 in Selenium by Anvi
• 5,880 points
10 views
0 votes
1 answer

How can I use HTML Unit Driver as a headless browser with Selenium?

Hello @Nishant, follow these steps to use ...READ MORE

answered 5 days ago in Selenium by Anvi
• 5,880 points
5 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.