Question

I am modeling my web app interaction using the Page Object pattern. Most pages in the app have some standard options like "log in", "log out", "home", etc. Additionally, they all have a protected WebDriver reference.

So I created a super-super class that all pages will inherit - GrandpaClass. This will only contain a protected WebDriver reference and a constructor to initialize the driver.

I then created a super class that most pages will inherit - PapaClass. It inherits GrandpaClass and adds the standard menu functionality I listed above (log-in, etc.)

The problem arises when the same menu action can result in different pages displayed. For example, when you log out you can either go to the login page, or back to an error page. But since the log-in functionality is in the PapaClass, this class has to return different pages, that inherit from him. This makes the superclass dependent on its subclasses.

I was thinking of using something like Strategy to factor out the common menu functionality. So the PapaClass, instead of maintaining the functionality, will only maintain a reference to the Menu object.

Is this a good idea, or is there a more elegant (or simpler) way to solve this?

Thanks.

Was it helpful?

Solution

I think your Menu object is a good idea, but you don't need the PapaClass. You can just have all your pages inherit from the GrandpaClass and use Composition where there are common elements. With inheritance you are saying 'is a page with a menu' which suggests the page should just have a menu.

OTHER TIPS

Yes, I think this is okay, if you need a different strategy for returning pages based on something. Your description of the problem tends to lead me to believe that your over-complicating the issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top