Design POM Classes

In this tutorial, We will learn the concept of Inheritance and Encapsulation in POM.

In the previous tutorials, We have learned about the POM, Encapsulation, and Inheritance in details.

 

Now we will see, How OOPS concepts are important and helpful in creating the POM testing frameworks.

Inheritance – Inheritance is a way in which one class can acquire all the properties of the another class.

Encapsulation – Encapsulation is used to wrap up the data or Binding the data into the single unit.

 

Now let’s understand the use of Encapsulation and Inheritance in Page Object Model. We will learn this concept using the simple example.

We are taking the example of FaceBook.

 

We will divide our Framework structure into three parts. Page classes, Test Classes and Utility classes. We will discuss the use of all classes in Details.

Design POM Classes

 

Page Classes

In Page package, we design the Page classes for every single page available in Website. In page classes, we define the Locators for the elements present on the particular web page and actions what we can take on these Web Elements.

 

i.e In our example we have taken the example of Login page and Named the class LoginPage.class  . In LoginPage class, we have declared the Locators for the WebElement Username, password, and Log-in button and also define the actions, what we can perform on these elements like input text and click the button.

 

You can see in our example we have declared our Locators private so that no other class can make any unnecessary change in the script. This is how we are using Encapsulation in our Model.

 

Test Classes

The second thing we do is create the Separate Test Class for each page class or each functionality.

 

In our example, we are creating the LoginTest.class . In this Test Class, we create the Test scripts. In our example, we are creating the Login test. We created the object of LoginPage class and called the methods (Steps) of LoginPage class in our Test Class to create the test script.

 

Utility Classes

In utility classes, we declare and implement the project utilities like logging, configuration, connectivity implementation.

 

In our example, for the time, we have created the only one class in the utility class calledPage.class , This page class will contain the common methods and global functions which can be used by any page class.

 

Every page class will inherit this Page.Class class. Write now we have implemented the Browser invoke code in this class; In future, we will see the multiple uses of this class as well.

 

So this is the way, How can we Design the classes in Page Object Model. This will make the project structure more simple, easy to understand and maintainable.

0 Comment

Leave a Reply