7

I need to refactor my Selenium tests, and was wondering what the best design solution would be for a portal with a hierarchical page organization. We are using tiles, and we have defined a baselayout from which many pages inherit.

Consider the following simplified example:

  1. baselayout
    • start
    • about

What would be better, an inherited based design:

/** Implements methods that access the top-level menu. */
Class BaseLayout {...}

/** Implements methods that access elements of the "Start" page */
Class StartPage extends Base Layout {...}

/** Implements methods that access elements of the "About" page */
Class AboutPage extends Base Layout {...}

or an aggregation based design?:

/** Implements methods that access the top-level menu. */
Class BaseLayout {...}

/** Implements methods that access elements of the "Start" page */
Class StartPage {
    BaseLayout parent;
    // ...
}

/** Implements methods that access elements of the "About" page */
Class AboutPage {
    BaseLayout parent;
    // ...
}

The question arose when I came across the LoadableComponent design pattern, as Selenium already provides an abstract class for such components, thus making the first inheritance-based solution unfeasible.

1 Answer 1

1

I'm using the inherited based design. It worked great until the application I'm testing was also made available in another, more limited customer-facing UI. So now I have two applications which consist of the same components surrounded by different menus. That's a situation where the inherited design breaks.

An aggregation-based design combined with some IOC container could be a lot more flexible, I guess.

3
  • That's a good idea! I'll try to figure out how to combine it with IOC as you mention.
    – Alberto
    Jul 27, 2011 at 10:26
  • @Alberto I'm currently asking myself the same question and after seeing Ivo's response I'm starting to think he's right. I was wondering if you could share with me how you ended up implementing it and what were the problems you found. Thank you! Jan 11, 2012 at 13:01
  • @Mario I'd probably disappoint you, but at the end, I didn't find useful the org.openqa.selenium.support.ui.LoadableComponent. We also don't have (up to now) any web component included into more than one page, so the inheritance-based design works well. If things change in the future, I can always rewrite the PageObjects of the reused components to be aggregated into their PageObject containers.
    – Alberto
    Jan 11, 2012 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.