Same company new universe

You might know us as "enjoy.ing" - now, we call ourselves CREATEQ.
Our culture, projects, clients and all of our people, of course, remain the same.
Find out more!

New Website

    Please attach your CV (PDF or DOC, up to 5MB)

    captcha
    enjoy.ing
    • Home
    • About us
      • Who we are
    • What we do
      • Projects
      • Technologies
    • work’n’enjoy
      • Why we enjoy engineering
      • People Development – Investing in people
    • Open positions
    • News
    • Contact
    • Home
    • About us
      • Who we are
    • What we do
      • Projects
      • Technologies
    • work’n’enjoy
      • Why we enjoy engineering
      • People Development – Investing in people
    • Open positions
    • News
    • Contact

    The importance of Page object model in test scripts

    Home » News » The importance of Page object model in test scripts
    The importance of Page object model in test scripts
    • October, 2020
    • Share It

    Page Object Model (POM) is a Design Pattern which is very popular in Selenium Test Automation. It is widely used design pattern and it can highly enhance test maintenance and reduce code duplication.

    In POM web pages are represented as simple classes, and the various web elements on the page are defined as variables and used in methods. The tests then use these methods of page object classes whenever they need to interact with the UI of the certain page.

    For example, we have a login page of some sort. We locate all needed elements on that page with webdriver. Then, we write methods that use that elements. So, we have all elements and all methods that we want to use in our tests in one simple class. In test class we just call the that methods with suitable arguments for certain test case.
    Every page that we need to interact with, should have its own class with elements and methods (Page Object Class).

    Example diagram of POM looks like this:

    Why is good to use POM ?

    • Code will be cleaner since by POM design pattern we should keep our tests and element locators separately. So, it will be easier to maintain code when something in the UI is changed.
    • We can keep our page objects in separate repository (Page Object Repository). That will give us an opportunity to use for different purposes with different frameworks.
    • Test cases will be a lot shorter since we could reuse methods from POM classes.

     

    What is Page Factory?

    Page Factory is an extension to Page Objects, primarily used for initialization of the web elements defined in the page classes (or page objects). Web elements used with Page Objects have to be initialized before they can be used further and Page Factory simplifies the initialization with the initialization method.

    It looks like this:

    Next thing to know about Page Factory is @FindBy annotation. Using @FindBy annotation, every WebElement variable is initialized by the Page Factory based on the locators configured to locate the element on the web page.

    Examples of @FindBy:

    Instead of:

    The @FindBy annotation can accept lots of attributes like XPath, Id, Name, CssSelector, ClassName, LinkText, PartialLinkText, etc.

    Will you use POM or not, will you use it with Page Factory extension or without?

    It all depends on you, your project and your client needs. :D

    From my perspective, when looking into huge dinosaur Java Selenium project without POM and PF with over 200 tests, we really need it.

    A tiny UI change, will take some time to refactor code everywhere, while with POM it could be a lot shorter.

    Probably a lot of you know about POM and PF, some of you are using it, I just wanted to point out importance of reusable and maintainable code in your test scripts. Especially when it gets quite big.

    Author: Aleksandar Marjanović, QA Engineer @ enjoy.ing

    Previous Next

    Related Posts

    Swiss banking: Innovation shaping the future

    Swiss banking: Innovation shaping the future

    We love running

    We love running

    Hands-on blockchain: Ethereum Swarm & Tezos

    Hands-on blockchain: Ethereum Swarm & Tezos

    New enjoy.ing office in Niš

    New enjoy.ing office in Niš

    One of the ways to catch a wide range of the Radio Signals….

    One of the ways to catch a wide range of the Radio Signals….

    The enthusiasts from enjoy.ing created a mobile application for the Belgrade Marathon

    The enthusiasts from enjoy.ing created a mobile application for the Belgrade Marathon

    enjoy.ing at „Voxxed Days“

    enjoy.ing at „Voxxed Days“

    Basic overview on React Hooks

    Basic overview on React Hooks

    The best way to start your career or at least to start thinking about it.

    The best way to start your career or at least to start thinking about it.

    Dynamics of working in an international team

    Dynamics of working in an international team

    enjoy.ing Family day 2018

    enjoy.ing Family day 2018

    NSM Engineering AG strengthens its executive board with Oliver Brack and Arnoud A. Douw

    NSM Engineering AG strengthens its executive board with Oliver Brack and Arnoud A. Douw

    Sit up and take notes – It’s online onboarding time!

    Sit up and take notes – It’s online onboarding time!

    enjoy.ing wants to interview you: Please, send us your Skype nick

    enjoy.ing wants to interview you: Please, send us your Skype nick

    Heapcon 2019

    Heapcon 2019

    Open Day Belgrade 2018

    Open Day Belgrade 2018

    enjoy.ing internship – Speak up.

    enjoy.ing internship – Speak up.

    ITkonekt 2016 – Origami boat, exclusive sunglasses & lots of fun

    ITkonekt 2016 – Origami boat, exclusive sunglasses & lots of fun

    ElasticSearch Main Objectives

    ElasticSearch Main Objectives

    Wooden labyrinth as a challenge for engineers

    Wooden labyrinth as a challenge for engineers

    Enjoy the Ride Party 2020

    Enjoy the Ride Party 2020

    Open Day Niš 2018

    Open Day Niš 2018

    Enjoy Open.ing

    Enjoy Open.ing

    Fun methods to work on your arithmetic skills

    Fun methods to work on your arithmetic skills

    Family day 2019

    Family day 2019

    Logic behind Chatbot

    Logic behind Chatbot

    Enjoy the Ride company event

    Enjoy the Ride company event

    celebrat.ing 5 years

    celebrat.ing 5 years

    The remarkable women who made a difference

    The remarkable women who made a difference

    The remarkable women who made a difference

    The remarkable women who made a difference

    Job Fair in Nis 2020

    Job Fair in Nis 2020

    Memory management and data persistence mechanism in Exlibris ecommerce platform and bookstore

    Memory management and data persistence mechanism in Exlibris ecommerce platform and bookstore

    Job Fair 2015

    Job Fair 2015

    For the second year running, enjoy.ing supports the Belgrade Marathon

    For the second year running, enjoy.ing supports the Belgrade Marathon

    Open Day Kragujevac 2019

    Open Day Kragujevac 2019

    Open Day 2015

    Open Day 2015

    Meet.ing ElasticSearch – the most popular SE in the world

    Meet.ing ElasticSearch – the most popular SE in the world

    Belgrade Marathon 2019

    Belgrade Marathon 2019

    Enjoying the new normal enjoy.ing

    Enjoying the new normal enjoy.ing

    enjoy.ing and Stanton Chase hosted HR professionals

    enjoy.ing and Stanton Chase hosted HR professionals

    Officially opened new premises in GTC 41

    Officially opened new premises in GTC 41

    Job Fair Nis: Record-breaking number of students visited enjoy.ing booth!

    Job Fair Nis: Record-breaking number of students visited enjoy.ing booth!

    We enjoyed connecting at IT konekt 2017

    We enjoyed connecting at IT konekt 2017

    Job Fair Niš 2019

    Job Fair Niš 2019

    Decade and a half of Ivan Kun

    Decade and a half of Ivan Kun

    VDB16 – Silver sponsor with gold coins

    VDB16 – Silver sponsor with gold coins

    What is shaping the future of education?

    What is shaping the future of education?

    enjoy.ing party 2019

    enjoy.ing party 2019

    Fantastic CODEstantine 2019

    Fantastic CODEstantine 2019

    Open day 2016 with our new bend “Null Pointer and The Exceptions”

    Open day 2016 with our new bend “Null Pointer and The Exceptions”

    Java 8 Workshop

    Java 8 Workshop

    How to deploy a React app without a server, easy, no compromises

    How to deploy a React app without a server, easy, no compromises

    We enjoy connecting

    We enjoy connecting

    Follow us
    enjoy.ing

    Copyright © 2021 enjoy.ing