OneStopTesting - Quality Testing Jobs, eBooks, Articles, FAQs, Training Institutes, Testing Software, Testing downloads, testing news, testing tools, learn testing, manual testing, automated testing, load runner, winrunner, test director, silk test, STLC

Forum| Contact Us| Testimonials| Sitemap| Employee Referrals| News| Articles| Feedback| Enquiry
 
Testing Resources
 
  • Testing Articles
  • Testing Books
  • Testing Certification
  • Testing FAQs
  • Testing Downloads
  • Testing Interview Questions
  • Career In Software Testing
  • Testing Jobs
  • Testing Job Consultants
  • Testing News
  • Testing Training Institutes
  •  
    Fundamentals
     
  • Introduction
  • Designing Test Cases
  • Developing Test Cases
  • Writing Test Cases
  • Test Case Templates
  • Purpose
  • What Is a Good Test Case?
  • Test Specifications
  • UML
  • Scenario Testing
  • Test Script
  • Test Summary Report
  • Test Data
  • Defect Tracking
  •  
    Software testing
     
  • Testing Forum
  • Introduction
  • Testing Start Process
  • Testing Stop Process
  • Testing Strategy
  • Risk Analysis
  • Software Listings
  • Test Metrics
  • Release Life Cycle
  • Interoperability Testing
  • Extreme Programming
  • Cyclomatic Complexity
  • Equivalence Partitioning
  • Error Guessing
  • Boundary Value Analysis
  • Traceability Matrix
  •  
    SDLC Models
     
  • Introduction
  • Waterfall Model
  • Iterative Model
  • V-Model
  • Spiral Model
  • Big Bang Model
  • RAD Model
  • Prototyping Model
  •  
    Software Testing Types
     
  • Static Testing
  • Dynamic Testing
  • Blackbox Testing
  • Whitebox Testing
  • Unit Testing
  • Requirements Testing
  • Regression Testing
  • Error Handling Testing
  • Manual support Testing
  • Intersystem Testing
  • Control Testing
  • Parallel Testing
  • Volume Testing
  • Stress Testing
  • Performance Testing
  • Agile Testing
  • Localization Testing
  • Globalization Testing
  • Internationalization Testing
  •  
    Test Plan
     
  • Introduction
  • Test Plan Development
  • Test Plan Template
  • Regional Differences
  • Criticism
  • Hardware Development
  • IEEE 829-1998
  • Testing Without a TestPlan
  •  
    Code Coverage
     
  • Introduction
  • Measures
  • Working
  • Statement Coverage
  • Branch Coverage
  • Path Coverage
  • Coverage criteria
  • Code coverage in practice
  • Tools
  • Features
  •  
    Quality Management
     
  • Introduction
  • Components
  • Capability Maturity Model
  • CMMI
  • Six Sigma
  •  
    Project Management
     
  • Introduction
  • PM Activities
  • Project Control Variables
  • PM Methodology
  • PM Phases
  • PM Templates
  • Agile PM
  •  
    Automated Testing Tools
     
  • Quick Test Professional
  • WinRunner
  • LoadRunner
  • Test Director
  • Silk Test
  • Test Partner
  • Rational Robot
  •  
    Performance Testing Tools
     
  • Apache JMeter
  • Rational Performance Tester
  • LoadRunner
  • NeoLoad
  • WAPT
  • WebLOAD
  • Loadster
  • OpenSTA
  • LoadUI
  • Appvance
  • Loadstorm
  • LoadImpact
  • QEngine
  • Httperf
  • CloudTest
  •  
    Languages
     
  • Perl Testing
  • Python Testing
  • JUnit Testing
  • Unix Shell Scripting
  •  
    Automation Framework
     
  • Introduction
  • Keyword-driven Testing
  • Data-driven Testing
  •  
    Configuration Management
     
  • History
  • What is CM?
  • Meaning of CM
  • Graphically Representation
  • Traditional CM
  • CM Activities
  • Tools
  •  
    Articles
     
  • What Is Software Testing?
  • Effective Defect Reports
  • Software Security
  • Tracking Defects
  • Bug Report
  • Web Testing
  • Exploratory Testing
  • Good Test Case
  • Write a Test
  • Code Coverage
  • WinRunner vs. QuickTest
  • Web Testing Tools
  • Automated Testing
  • Testing Estimation Process
  • Quality Assurance
  • The Interview Guide
  • Upgrade Path Testing
  • Priority and Severity of Bug
  • Three Questions About Bug
  •    
     
    Home » Testing Articles » Automated Testing Articles » Test Automation - How to handle common components with Page Object Model?

    Test Automation - How to handle common components with Page Object Model?

    A D V E R T I S E M E N T


    you are working in web application testing domain and are interested in test automation, you might have used, come across or heard about PageObject Model in test automation. If you haven't heard of it, it might be a good idea to read this article.

    In nutshell, a separate class is created for every page / screen of the application in the PageObject model. This class exposes methods to represent all the operations a user can perform on various elements on the page. For example, a class to represent LoginPage might have methods to enter userName, password and click on submit button. Tests can use this class to interact with the page instead of duplicating elements everywhere in the test scripts.

    PageObject essentially decouples UI from the tests and as a result makes test automation suite a bit more maintainable. In my opinion, if you are not doing anything else, PageObject Model is at least something you should implement in your test automation projects to decouple UI from the tests.

    This is all fine and PageObject model usually works. However, in the context of web applications, we often come across common components or parts of the page which are shared on some or all the pages. How do we handle common components like header / footer / sidebars / widgets etc with PageObjects model?

    A simple (and bad) way to solve this problem would be to ignore it as a problem to solve and copy paste elements and their methods on all the pages. This is a sure way to get into the maintenance nightmare and will have potential to put you on the story of Jim :-)

    However, there are plenty of good ways to solve this problem. Let us examine the approaches I have used in past to solve this problem

    Handling common parts with inheritance

    Inheritance in the context of OOP is often used for code reuse or to establish subtype from an existing type. In the context of solving this problem, we can't really establish subtype kind of relationship in the pages, so our focus is on reusing the code with inheritance.

    Let's say our application has common header, footer and sidebar on all the pages. To represent this in the PageObject Model without duplicating them on all the pages, we create a BasePage class with all the common parts. This BasePage class might look similar to the following class definition

    Class BasePage {      // common elements & methods for header        // common elements & methods for footer        // common elements & methods for sidebars        //� and so on  }  

    Now all the pages with common header, footer and sidebar will be inherited from this class. This is a simple and effective way to remove code duplication in PageObject model to some extent.

    This approach can also be used effectively with many types of BasePages. For example, if header / footer / navigation etc are different for user who is logged in the system, we can create BasePageForLoggedInUser and so on.

    Classes to represent Pages can focus on specific bits pages are accomplishing and everything else can be inherited from the base classes.

    This approach works, but it is not perfect.

    Handling slight variations or unique pages might become tricky. For example, if header / footer are slightly different for few promotional pages, it will require one more BaseClass. On the same lines, if it is possible to control layout / content of the pages with the widgets, it might be difficult to define pages in advance.

    Handling common parts with composition

    Composition, In my opinion is a better approach. In OOP, composition is often used to represent "has a" relationship. If you think about pages, screens and shared components like header, footer etc, "has a" relation makes more sense. For example, it is very natural to say that PaymentPage has a navigation and footer whereas AccountPage has sidebar and footer.

    In this approach, instead of creating a base page with all the shared components, an object is created for every component which can be shared on multiple pages. Things like header, footer, sidebars etc are created as separate classes on the lines of

    Class Header{      // stuff related to header  }  Class Footer {      // stuff related to footer  }  Class SideBar {      // stuff related to sidebar  }  

    Now pages can use these components as needed instead of relying on the inheritance or duplicating code. A home page with header and footer might look on the lines of

    Class HomePage {      Header header;      Footer footer;      // home page related stuff  }  

    This approach IMO is better than inheritance for many reasons. Code is much easier to understand with the composition than inheritance. Header object is instantiated in the HomePage class and so I know that HomePage has a header. With inheritance, it's not visible and readable. With composition it is possible to create any page you want by instantiating whatever make sense. With inheritance, it might be possible to have duplicate code in various BasePages, a bit more complicated multi-level inheritance or a combination of both.

    So what am I using these days - well whatever make sense :-) Have you faced similar issue in your experience? Please leave your comments and let us know how you have approached it. Thank you for sharing this in your network :-)



    More Automated Testing Articles
    1 2 3 4 5 6 7 8 9 10 11 Next



    discussionDiscussion Center
    Discuss
    Discuss

    Query

    Feedback
    Yahoo Groups
    Y! Group
    Sirfdosti Groups
    Sirfdosti
    Contact Us
    Contact

    Looking for Software Testing eBooks and Interview Questions? Join now and get it FREE!
     
    A D V E R T I S E M E N T
       
       

    Members Login


    Email ID:
    Password:


    Forgot Password
    New User
       
       
    Testing Interview Questions
  • General Testing
  • Automation Testing
  • Manual Testing
  • Software Development Life Cycle
  • Software Testing Life Cycle
  • Testing Models
  • Automated Testing Tools
  • Silk Test
  • Win Runner
  •    
       
    Testing Highlights

  • Software Testing Ebooks
  • Testing Jobs
  • Testing Frequently Asked Questions
  • Testing News
  • Testing Interview Questions
  • Testing Jobs
  • Testing Companies
  • Testing Job Consultants
  • ISTQB Certification Questions
  •    
       
    Interview Questions

  • WinRunner
  • LoadRunner
  • SilkTest
  • TestDirector
  • General Testing Questions
  •    
       
    Resources

  • Testing Forum
  • Downloads
  • E-Books
  • Testing Jobs
  • Testing Interview Questions
  • Testing Tools Questions
  • Testing Jobs
  • A-Z Knowledge
  •    
    Planning
    for
    Study ABROAD ?


    Study Abroad


    Vyom Network : Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Programming & Source Codes | Free eBooks | Job Interview Questions | Free Tutorials | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Bangalore Info | GATE Preparation | MBA Preparation | Free SAP Training
    Privacy Policy | Terms and Conditions
    Sitemap | Sitemap (XML)
    Job Interview Questions | Placement Papers | SMS Jokes | C++ Interview Questions | C Interview Questions | Web Hosting
    German | French | Portugese | Italian