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've been using Selenium off and on for the past two years. Recently I've been seeing more references to page objects. (I'm referring to page objects as an means of organizing UI automation code -- not an interface or implementation manifested in the Selenium API.) What are the advantages and disadvantages of using pages objects relative to using a mere collection of functions? Please attempt to justify the advantages and disadvantages.

share|improve this question
add comment

3 Answers


  • Clear separation between test code and navigation code in code base.
  • Easy to comprehend test, for example -

    Homepage.testLogin(username, password);

is more succinct than

  • Ease of maintenance, when UI changes you need to change the navigation code and not test (provided application logic is still the same and only UI object/navigation is changed)


The only one I could think of is, initial design of page object might take more time but pain is definitely worth it

share|improve this answer
You could do the same thing with a function, without going to the trouble of defining an object, so I don't think this answers the question. –  user246 May 14 '11 at 20:34
Tarun is it like page objects are methods or each page object will have its member function? –  Rakesh Prabhakaran May 16 '11 at 1:48
@user246 - True for the example Tarun has used, but not true generally. PageObjects ensure defining an object once, and reusing it everywhere else. If you define multiple methods around an object, the part of your code that identifies the object will be scattered around your entire code, which will create a maintenance nightmare. –  Suchit Parikh May 17 '11 at 1:19
@Suchit Perhaps this is just a matter of our using different terms. When you say, "PageObjects ensure defining an object", what object are you referring to? Functions work just as well as objects for encapsulating logic. There is a stronger argument for using objects if you need inheritance or if you need to encapsulate state. However, it sounds to me like most PageObjects are basically stateless proxies -- just collections of functions. –  user246 May 17 '11 at 13:43
@user246 - Agreed. And yes, objects itself become more useful when there is inheritance and encapsulation i.e. actual OO implementation. –  Suchit Parikh May 17 '11 at 21:07
add comment

@Tarun In my tests for each main functionality or page of AUT, I will have a class created and it will contain member functions for navigation and user events through each sub features in that class. Other than that, I will have a testNg driven function in the same class that will be calling each of the normal member function of the class that will contain the navigation code . This will separate the navigation code that is kept in the normal java methods and test Control or functionality code that is in the TestNg Method. Here as I am keeping navigation cod e separately, I am able to easily edit them when ever there is minor changes in the UI. Does the Page Object approach you mentioned above make and advantage over this approach. Or am I having a wrong understanding about your approach ? Please elaborate.

share|improve this answer
Looks same to me, btw I wonder if you really wanted to add it as answer.... –  Tarun May 16 '11 at 2:48
Tarun, since the post is long i couldn't add it as a comment –  Rakesh Prabhakaran May 16 '11 at 12:43
add comment


  1. (OOP) Separation of defining objects from implementing them in methods. Define once, use it multiple times.

  2. Clarity of tests / self-documentation


3. Easy to maintain - e.g. if the login page elements get updated, you can just go to your loginPage Page Object class and update the methods identifying the elements


  1. Takes time to build the infrastructure (as mentioned before)
  2. Requires good enough programming skills to design the automation suite (+ or - depending on the programming skills of the team)
share|improve this answer
add comment

Your Answer


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.