Page Object Model (POM)

Ahmeteminege
2 min readDec 13, 2023

--

We can briefly say that POM in Selenium is a design that will create an object repository for the elements in the user interface in web applications. There must be a page class for each web page and all elements belonging to that page must be defined here. The Page class will define the WebElements of that Web page and will also contain the Web Methods that perform operations on those WebElements. It is important to give the name of these methods according to the task they perform for the most healthy and readable code. That is, if the method you are performing contains a username, it is important to give it a name that includes username in the method name.

Advantages

1- Easier to maintain, understandable and especially traceable code emerges.
2- Since the object repository is independent of the test class, it can be used in different tools. It may be selenium/tesng for functional tests or cucumber/Junit, which is more commonly used for tests in the analysis category.
3- It prevents code repetition, when a change is made in one place, instead of making the change in more than one place, the most specific change can be made and affected in more than one scenario.
4-Without code confusion, it becomes more understandable by simply stating the defined method and the work it should do in the test class.

Page Object Model and Page Factory topics can be confused with each other, so addressing them with the following items may be useful to understand differently.

• POM is a test design pattern that tells scripts and page objects to be organized by pages so that they can be easily distinguished. Page Factory, on the other hand, is a way to implement the Page Object Model built into Selenium.

• In POM, locator can be defined using ‘By’ without using Page Factory, FindBy annotation is used to identify page objects while using Page Factory.

• In plain page object model, you have to initialize each page object separately otherwise you will encounter NullPointerException, but in PageFactory all page objects can be initialized using initElements() method.

--

--

No responses yet