Page Object Model and Implementation in Selenium

In testing department of today’s IT sector, Automation has a significant role. IT companies are leaning towards automation testing because there are endless advantages of automating an application. For programming language, automation gives flexibility. There are distinct types of frameworks that companies use for automating their applications. Some of which are mentioned below, and one of which is Page Object Model also popular as POM.

●    Page Object Model (POM)
●    Hybrid
●    Data Driven
●    Keyword Driven

POM is a type of framework which is very easy to understand and easy to implement while making architecture of any automation process. It basically enhances the test maintenance and reduces the possibility of duplication of code, which is very concerned thing in test automation. In other words POM is a structured base object repository design.

In POM we create a page class for each corresponding web page in the application. Now, the page class that we have created contains all the web-elements of that page and also that methods that we will perform on those web-elements, so the name that we give to a method should be according to its functionality, for example- for a log-in page, the name of the method can be login() which only has few elements like user-name, password, log-in button, forget password link, etc. and methods like passing strings in the field and clicking the buttons.

For making a robust and easy to maintain framework we use POM with data driven by collating excel with POM. The best combination would be POM with data driven through excels and run test cases through TestNG

Below mentioned the flowchart will make it clearer to understand:

Flow Chart

Implementation Example in Selenium 

  1. Create a new package file as Practice; we will be creating different packages for Page Objects, Utilities, Test Data, Test Cases and Modular actions. It is always recommended to use this structure, as it is easy to understand, simple to use and easy to maintain.
  2. Create a new class file and refer the name to the actual page from the test object. In our case it is Home Screen and Login Screen.
  3. Create a static method for each element in Home Screen. Each method will have an argument (driver) and returns a value (element).

package Practice;

   import org.openqa.selenium.By;

    import org.openqa.selenium.WebDriver;

    import org.openqa.selenium.WebElement;

public class Home_Screen {

    private static WebElement element = null;

public static WebElement MyAccount(WebDriver driver){

    element = driver.findElement(By.id(“id”));

    return element;

    }

public static WebElement LogOut(WebDriver driver){

    element = driver.findElement(By.id(“logout”));

return element;

    }

}

4.Reason of passing driver as argument selenium is able to locate the element on the browser (driver). Element is returned so that action can be performed on it.
5.Method is declared as public static so that it can be called in any other method without creating instance of the class.
6.Follow same rule for creating another class LogIn Screen.

package Practice;

import org.openqa.selenium.*;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

public class LogIn_Screen {

        private static WebElement element = null;

    public static WebElement UserName(WebDriver driver){

         element = driver.findElement(By.id(“id”));

         return element;

         }

     public static WebElement Password(WebDriver driver){

         element = driver.findElement(By.id(“id”));

         return element;

         }

     public static WebElement LogIn(WebDriver driver){

         element = driver.findElement(By.id(“id”));

         return element;

         }

}

7. Now create a new class which will be our test case, let’s say we are creating it in package called Framework by name POM.

package Framework;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

// Import package pageObject.*

import pageObjects.Home_Screen;

import pageObjects.LogIn_Screen;

public class POM{

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_Screen.MyAccount(driver).click();

LogIn_Screen.UserName(driver).sendKeys(“testuser_1”);

LogIn_Screen.Password(driver).sendKeys(“Test@123”);

LogIn_Screen.LogIn(driver).click();

System.out.println(” Login Successfully, now it is the time to Log Off buddy.”)

Home_Screen.LogOut(driver).click();

driver.quit();

}

}

8.You will notice that once you type HomeScreen in your test script and the moment you press dot, all the methods in the Home Page will display. We can expose methods in order to reduce duplicated code. We are able to call these method multiple times. This will ensure a better maintainable test code, because we only have to make adjustments and improvements in one particular place.

**Implementation reference is taken from: toolsqa.com.

Explore Best Bug Tracking Tools to Rectify Challenges

There are so many digital-first companies in today’s business world deal with website flaws and drawbacks with what we call issue or bug tracking tools. These are systems that enable digital teams (counting digital specialists, developers, web analysts, etc.) to track, manage, report, and resolve bugs. It is significant to track bugs throughout the software development process so that one small technical or other challenging issue does not snowball into a million giant issues. It is also crucial for your business since development teams that create software with unresolved bugs would not find customers who will buy, use, or trust their products. The adept development team should have a time-tested and genuine bug tracking solution on hand from the moment they get to work on a project. But, if you are a lean startup that does not yet have tons of cash to spend on software or allotted to a project where every penny counts, investing in an extra system might seem next to impossible.

Explore Software Defect Tracking Tools

We will take a closer look at some of the most generous and most admired bug tracking tools out there – identifying the distinct features that set them apart as well as what kinds of roles they are intended for:

Trac

Trac is an improved wiki and issue tracking system for specific software development projects. It offers a simple and an easy to use web interface. Some of the exceptional features count an interface to Subversion (& other version control systems), convenient project management, reporting facilities, features including user management, roadmap, and milestone tracking, wiki, and support for a series of plugins. It is a lightweight and stable system; however, you may lose out some of the innovative features provided by other bug tracking systems.

JIRA

JIRA is a well-known tool developed by Australian Company Atlassian. It is used for bug tracking, issue tracking, and project management. The basic use of this tool is to track issue and bugs related to your software and Mobile apps.

Bugzilla

Bugzilla is a Mozilla Foundation supported/ developed web-based general-purpose bug tracker & testing tool that allows its users to log and track imperfection and defects in their product efficaciously. It is a matured and advanced feature-rich app with features like bug lists in multiple formats, advanced search capabilities, scheduled reports, the capability to file/ modify bugs by email, automatic duplicate bug detection, patch viewer, time tracking, private attachment and comments, request system, etc. It is a widely accepted and adapted product used by several big open source projects such as Apache dev team, Linux Kernel dev team, GNOME dev team and famous companies like NASA, Open Office, Facebook etc. and is one of the admired and famous bug tracking systems.

ReQtest

ReQtest is an external cloud-based testing solution with bug tracker capacity. Reqtest offers all-encompassing and extensive test management features which give the test team ability for tracking the advancement of testing in real time. Its “Agile board” gives an economic and effective way to visualize tasks and collaborate effortlessly. Reqtest is famous amongst UAT testers and is preferred by large corporations and small teams as it has no hassles accompanying installation or maintenance.

BugHerd

It is a web-based issue tracking project management tool. Intended for designers and developers, glitches are well-organized around four significant listing: Backlog, To Do, Doing & Done – enabling teams to keep up with the status of different tasks. The advanced tool captures a screenshot of the roadblocks counting the exact HTML element being annotated. When already installed tools like Pivotal Tracker or Redmine? BugHerd can be incorporated with any of these.

Trac

It is an open source and more than a bug tracking tool with enhanced wiki and web-based issue management system. It has been adopted by a variety of organizations for software development projects. Trac can be used for documents as well as requirement management. Trac also allows wiki markup in issue descriptions and commit messages and creating links & references between tasks, files, bugs, changesets, and wiki pages. It integrates with major version control systems considering Git and Subversion.

Redmine

Redmine is a free and open source and considered more than just a bug tracker. This web-based project management solution has been around for the past few decades and supports 34 varieties of languages. It is written in Ruby and is compatible with MySQL, Microsoft SQL, PostgreSQL, and SQLite. If in case you are simply searching for bug tracking, it might be economical. It can use the flexibility of its customizable interface and the slew of obtainable plug-ins to adapt the system to your team’s requirements over time.

Mantis BT

Mantis Bug Tracker is a free and open source system and it is one of the most admired bug tracking tools as it is available in 49 different languages. It can also be used for tracking software defects and manage projects. Mantis BT has an event-driven notification system with support for distinct revision control systems. Even though it does not comprise a wiki of its own, it can easily incorporate with several popular wiki platforms.

Noteworthy features:

  • Access control
  • Customizable issue fields, workflows, and notifications
  • Mobile optimized UI for mobile access

Bug Genie

It is an open source project management and bugs tracking tool with a simplest and easy web interface. Users can effortlessly locate issues and glitches in this tool using filters and custom issue fields. In addition, users can add issues and perform tasks on software defects without even opening them. Bug Genie tool is not free, however, when hosted; users can effortlessly use or sign up for a free trial.

Fossil

It is the simple to use SCM (Software Configuration Management) system which not only aids in bug tracking but also offers web-based project management features along with a wiki. It is a high-reliability tool and it has a built-in web interface and supports “auto sync” mode which modifies and eases project management especially in the case of distributed projects.

Noteworthy features:

  • Simple to use the web interface
  • The distributed version control system
  • Technote- a type of wiki page that is linked to a point in time

The robust and effective bug tracker tool forms the backbone of any successful project. For an unprecedented project’s success, you can choose the bug tracking tool from the list above to help you efficaciously plan activities, collaborate with your team and eradicate all the bugs from your projects.