Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 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.

share|improve this answer
    
That's a good idea! I'll try to figure out how to combine it with IOC as you mention. –  Alberto Jul 27 '11 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! –  Mario Duarte Jan 11 '12 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 '12 at 19:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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