Page Object Model - What should I know?


As we know that Page Object Model is a Design Pattern where objects and actions are separated from tests. Page object model (POM) can be used in any kind of framework data-driven, keyword driven or hybrid framework. For implementing POM, we need a Page Library and a Testing Framework to begin with. POM approach can be used in both web applications and mobile applications (because both have multiple pages). But, this model cannot be used for API testing.



Why are we using Page Object Model?

  1. It provides an interface that is easy to program and maintain. It also hides the underlying technical aspects of the application window.

  2. This model is commonly used for testing, but can be used to provide scripting interface to an application.

  3. It uses encapsulation concept, by hiding details of UI structure from test components.

  4. Finally, it makes the test code easier to understand as it consists only test methods and no UI details.

Less known facts about Page Object Model:

  1. One page object per UI page- This is a myth. One can have multiple page objects for a single UI page. The only condition being- there should be significant number of elements/complexity on each page to divide it into multiple page objects.

  2. Works well for scripting pages- When scripting is involved in pages, this model performs faster if the scripting layer is programmed underneath UI layer. But, for really complex and heavy scripting interactions, it is better to avoid using this model as it will do a very bad job.

What to ABSOLUTELY NOT do when implementing Page Object Model

  1. NEVER add assertions in the page object. This completely nullifies the separation of UI and test logic and the purpose of Page Object Model. Assertions should ALWAYS be written in Test methods only.

  2. Test methods should never have driver API logic/code. In continuation to the first point above, driver API is not part of test framework, hence it should not be present in test methods, rather in page objects.

Hope you find this information useful. Please let me know if you have any queries at hari.nivedita@gmail.com.

31 views0 comments

Recent Posts

See All