The ‘Base’ Page

In any Page Object tree there is a class that sits at the top of the inheritance tree. Just to be confusing, I learned this as the ‘Base’ (though not sure when or where). Saunter comes with a class to form the Base of your Page Object tree.

from import Page

class HomePage(Page):
    def __init__(self): = wrapper().connection

    def open_default_url(self):"/")

In the above code example our HomePage class inherits from the class included in Saunter. And because of this, it has access to all the synchronization helper methods in the Page class.

But what if you found yourself needing to add your own, site-specific synchronization methods into this inheritance tree? (And you will.) Well, you could edit the Page class directly, but that means the changes will be lost in future upgrades which does not seem to be an ideal plan. Instead, what you want to do is create a site-specific class in the modules directory that acts as an intermediary between your pages and Saunter.

from import Page

class YourSiteNameBasePage(Page):
    def your_custom_synch_method(self):
        # does something

With this in place, the original example will look like so.

from your_site_name_base_page import YourSiteNameBasePage

class HomePage(YourSiteNameBasePage):
    def __init__(self): = wrapper().connection

    def open_default_url(self):"/")

Of course you can still use the synchronization included in Saunter‘s Page class, but this bit of extra wiring is well worth the 3 minutes of coding in order to add tailoring to your Page Objects to your specific needs while still leveraging what the framework provides.

Post a Comment

Your email is never published nor shared. Required fields are marked *