Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Tuesday 30 March 2021

Page Object Model - POM

Page Object Model is a pattern that we can apply it to develop efficient automation framework. With Page model, it is possible to minimize maintenance cost. Basically Page Object means that our every page is inherited from a base class which includes basic functionalities for every pages. If we have some new functionality that every pages have, we can simple add it to the base class.
Page Object Model is a design pattern that is used mostly in Web UI testing for enhancing maintenance of the test code and reducing duplication of it. Each page in the web application has to be separate class different than the others. These are the classes that contains Web Elements(Locators) of the web page, the classes include the methods which perform operations on those Web Elements and the classes are exist so that to execute corresponding page tests.

Why :

Selenium test projects generally are hard to be maintained. Also there is a significant amount of duplicated line of codes. Duplicated code cause unnecessary functionality and many crazy similar page object locators. Another reason is that changing the page locators frequently, if some locator will change, we might have to adjust the locator for the new implementation. This is a considerable waster of time for the QA team. We cannot see the exact advantage of POM if we have a small script to test the login behavior of the application. Scripts maintenance looks easy. However, as time goes further, the test suite will grow. As we add more and more lines to our code, things become tough. for example, IF we consumed out time to maintain our code at every change, how would we increase our test coverage.

Implementation -

In PyCharmIDE Create a directory and give a name whatever we want for the project on our local. Here is the very first window once we start to create a new project in PyCharm. First we need to specify both the location and the project name, then select project interpreter and click on Create button.

The next step is creating separate folders for the corresponding elements, for example Web Elements will be located under Locators folder, common actions will be in Base Class, Chrome, Firefox and Explorer driver will be in Drivers, Web Page methods will be located in Pages, Testcases will be in Tests folder. We can also create a TestSuite folders so that executing our tests as suite. 

Project folder structure.

we can create python files under folders that are related actions for our Application Under Test. For creating a python file, right click locators folder then click "New" and create a python file.


After completing the associated files, project structure will look like this.

Advantages
-
  1. If the UI design of the page changes, we dont have to update the test class implementation, rather it is enough to update the page object(locator)
  2. POM provides us creating a non-fragile test by means of reducing duplicated codes.
  3. POM makes our test code as clean as possible. Therefore, the test codes are easy to understand even if after a very long time later.
  4. POM design implementation separates the page objects and tests by achieving an abstraction.


No comments:

Post a Comment

Note: only a member of this blog may post a comment.