Page Object Pattern
As per selenium wiki : The Page Object pattern represents the screens of your web app as a series of objects.Here what we mean by objects is, these are the sample areas within a page. In simple words, Page Object model is the combination of Pages and its associated components.Benefits
- Maintainability is easy : When application represented as a series of pages, if we have a change of functionality/UI in one of the page we can very easily fix that up and should concerned about that page , not the whole framework.
- Reuses the Code : A single method inside a page class can be called N no. of times
- Easy Readability : Below diagram explains it better
Design Overview
Pitfall
As noticed from the above design, When i wanted to test few objects from HomePage , I defined my HomePageTest class but unfortunately i had to call few methods of LoginPage in order to visit HomePage.
Now why cant we have a mechanism/structure where, when we create object of HomePage, it should ensure that HomePage is loadable and takes the user to the HomePage. Something like below :
Loadable Component
LoadableComponent is a abstract base class, whose only task is to ensure that all pages are loadable when we create object of a page class.
When we extend LoadableComponent class, we should override these 2 following abstract methods:
Hope it helps :)
No comments:
Post a Comment