Page Object for Navigation

82 views
Skip to first unread message

mactuto...@gmail.com

unread,
Mar 1, 2014, 6:36:07 PM3/1/14
to seleniu...@googlegroups.com
Hello,

I have seen a few basic examples of navigation using Page Objects where say PO1.SomeAction returns PO2. But how would you create a PageBase class and what common functions would be included in the base class. All other page object classes would inherit this class. In some examples, the base class is singleton class. I know this is more of a programming language question than WebDriver PageObject. I appreciate if someone could please explain in using singleton pattern for base class which would be derived by other page object classes.

Thanks. 

David Lai

unread,
Mar 3, 2014, 8:05:30 PM3/3/14
to seleniu...@googlegroups.com
You don't necessarily need a Singleton for this.  You can do it as a BasePage as you mentioned, or as a completely separate PageObject.  Either way, there isn't a real need to do a singleton unlike something like a Configuration manager or a WebDriver Factory.  In fact, if you take the BasePage approach, you won't be able to do singletons.

Besides doing a BasePage, another approach is just use a separate PageObject to represent a page fragment.  I like this approach better in that you can support different abstract pattern that subclassing will not.  For example, say you have 3 variations on your navigation bar, Pre-Login, Post-Login basic user, and Post-Login Admin User.  Instead of doing a bunch of if/else logic to support all 3, it's much easier to to create 3 different classes and subclass each other to reuse the shared functionality, then use an Abstract PageFactory pattern to instantiate it so your tests are completely agnostic of your user level when it's not needed.

mactuto...@gmail.com

unread,
Mar 3, 2014, 9:49:18 PM3/3/14
to seleniu...@googlegroups.com
Thanks, David! Can you please show me an example of Abstract PageFactory? I really like the idea of page fragment as a PageObject. 
Reply all
Reply to author
Forward
0 new messages