DEV Community

loading...

How to use POM in software testing

isurumax26 profile image Isurumax26 ・2 min read

What is POM?

POM is a design pattern which is commonly used in Selenium for Automating the Test Cases. This design pattern can be used with any kind of framework like keyword-driven, Data-driven, hybrid framework, etc. I think you have an idea about the above frameworks Anyway I'll talk about them later.

Alt Text

Project hierarchy?

image

Under this model, for each web page in the application, there should be a corresponding Page Class. This Page class will identify the WebElements of that web page and also contains Page methods which perform operations on those WebElements. Name of these methods should be given as per the task they are performing, i.e., if loader needs to search something using the search box the method name will be setSearchBox(String item).

Consider following script for search some thing

image

As you can see all we are doing in this script is finding the web elements and setting the methods to fill those values. Above code is under the package pages

image

what we are doing here is filling the search box with values we provided(Test cases). Internal logic of these methods are implemented with the separate classes in the page package.

The chief problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, you need to change all 10 scripts. This is time consuming and error prone.

A better approach to script maintenance is to create a separate class file which would find web elements, fill them or verify them. This class can be reused in all the scripts using that element. In future, if there is a change in the web element, we need to make the change in just 1 class file and not 10 different scripts. That is the page object model(POM)

Summary

Developing a maintainable automation code is one of the keys to a successful test-automation project. When developing Selenium WebDriver tests(Or any other framework), We can use the page object model pattern, This pattern helps enhances the tests by making them highly maintainable, reducing the code duplication, building a layer of abstraction, and hiding the inner implementation from tests.

Discussion (0)

Forem Open with the Forem app