SlideShare a Scribd company logo
Using the Page Object
                       Pattern to Improve
                  Functional Test Maintainability
                            Dante Briones
                                Principal Consultant
                              Electronic Ingenuity LLC
                           http://electronicingenuity.com




Friday, 07 August, 2009
The Page Object Pattern

                     • Technique for structuring test code that:
                      • Promotes reuse and reduces duplication
                      • Makes tests readable
                      • Makes tests more robust (less brittle)
                      • Improves maintainability, particularly if
                          the application is rapidly evolving


Friday, 07 August, 2009
The Page Object Pattern

                     • Demos will be coded in Java
                     • Everything we discuss is applicable to other
                          strongly-typed languages (e.g. C#)
                     • Most things are applicable to dynamically-
                          typed languages (e.g. Ruby, Python, Perl)



Friday, 07 August, 2009
Selenium IDE
                                     Quick Poll


                     • How many using Se IDE?
                     • How many create tests primarily through
                          record & playback?




Friday, 07 August, 2009
Selenium IDE
                               It’s Great Because:

                     • It’s Free
                     • It’s Free
                     • Requires little or no programming
                          experience




Friday, 07 August, 2009
Selenium IDE
                           It falls short because:

                     • Selenese is not a programming language
                      • No support for loops/iteration
                      • No support for conditionals (if...else)
                      • No way to eliminate duplicated code!

Friday, 07 August, 2009
Selenium IDE
                            Why is duplication bad?

                     • Has this ever happened to you?
                      • A tiny change to the app causes several
                            test failures?
                          • Let’s see an example


Friday, 07 August, 2009
Demo



Friday, 07 August, 2009
Selenium IDE
                           Why is duplication bad?


                     • Fixing the tests will require more work
                          than the change that caused the failure
                     • Duplication makes code less maintainable


Friday, 07 August, 2009
Selenium IDE
                                       Summary


                          • Great productivity for the first few tests
                          • Maintainability decreases as the test suite
                            grows
                          • How can we do better?

Friday, 07 August, 2009
Start Coding Your Tests
                                             a.k.a.
                          “Write tests in a programming language”




Friday, 07 August, 2009
Coding Your Tests
                                 Quick Poll



                     • How many are using Selenium RC?



Friday, 07 August, 2009
Coding Your Tests
                              How does this help?


                     • We can eliminate duplication by building
                          abstractions
                     • Let’s see an example of this


Friday, 07 August, 2009
Demo



Friday, 07 August, 2009
Coding Your Tests
                              What happens next?

                     • All commonly used methods get pulled into
                          the base class of all tests
                     • As the test suite grows, so does the base
                          class
                     • Uh oh...the base class starts getting too big

Friday, 07 August, 2009
Coding Your Tests
                              How Big is Too Big?

                     • You can’t tell someone else has already
                          written the code you’re about to write
                     • Frequent version control conflicts
                     • Maintenance is an issue again


Friday, 07 August, 2009
Coding Your Tests
                 How to rein in your base class?
                     • Observation: For any given page, most of
                          the behavior does not apply
                     • Example: you can’t change your password
                          on the “view cart” page
                     • What if we moved the page-specific
                          behavior into a corresponding class?
                     • Voila! The Page Object is born
Friday, 07 August, 2009
The Page Object



Friday, 07 August, 2009
The Page Object
                                What does it do?


                     • Consolidates the code for interacting with
                          any given UI element
                     • Allows you to model the UI in your tests

Friday, 07 August, 2009
The Page Object
                                 What does it do?
                     • Exposes methods that reflect the things a
                          user can see and do on that page, e.g.
                          • addItemToCart(), getPrice()
                          • getEntryTitle(), saveDraft(), publishEntry()
                     • Hides the details of telling the browser
                          how to do those things


Friday, 07 August, 2009
Demo



Friday, 07 August, 2009
The Page Object
                                     Results

                     • Test code is very readable
                     • No duplication of Selenium API calls
                     • Interactive documentation via Ctrl-Space
                     • Eminently reusable code

Friday, 07 August, 2009
The Page Object
                                        Results

                     • This technique is framework-agnostic
                      • Has been used with Selenium, WebDriver
                            (Selenium 2.0), Watir, and others
                          • I’ve even used it to drive desktop apps


Friday, 07 August, 2009
The Page Object
                                        Results

                     • Because it encapsulates the details of the
                          test framework API:
                          • You can use this technique to simplify the
                            process of swapping frameworks
                          • In theory, you only need to reimplement
                            the Page base class.



Friday, 07 August, 2009
But wait, there’s more!
                                   It gets better!

                     • Page Objects improve maintainability
                     • They also provide an opportunity to make
                          test creation extremely quick (and maybe
                          even fun!)
                     • How? Page Objects + Method Chaining

Friday, 07 August, 2009
Method Chaining
                          What’s method chaining?


                     • Change the signature of user behavior
                          methods so that they return the page
                          object itself
                     • Allows multiple behavior methods to be
                          called in sequence



Friday, 07 August, 2009
Method Chaining
                            What will it do for me?


                          • Removes for “code clutter”
                          • Tests become even more readable


Friday, 07 August, 2009
Method Chaining
                    How does it work in practice?
                     • All Page Object methods return a
                          reference to a Page Object
                          • If the “user action” moves the focus to a
                            different page, the method should return
                            that page object
                          • Otherwise, return the same page object
                     • Time for an example
Friday, 07 August, 2009
Demo



Friday, 07 August, 2009
Method Chaining
                                      Results


                     • Test code is even more readable
                     • Very quick to write
                     • (Actually kinda fun. Don’t tell anyone!)


Friday, 07 August, 2009
Method Chaining
                                       Caveats


                     • Dependent on tool support
                     • Lots of options: IntelliJ IDEA, Eclipse,
                          NetBeans, VisualStudio




Friday, 07 August, 2009
Method Chaining
                                       Caveats
                     • Tool support depends on language
                      • Excellent support for strongly typed
                            languages like Java and C#
                          • Support is “up and coming” for
                            dynamically typed languages (Ruby,
                            Python, and Perl)



Friday, 07 August, 2009
The Page Object Pattern
                     • Technique for organizing test code that:
                      • Promotes reuse and reduces duplication
                      • Makes tests readable
                      • Makes tests more robust (less brittle)
                      • Improves maintainability, particularly if
                            the application is rapidly evolving
                          • Is just as quick record & playback!
Friday, 07 August, 2009
Q &A



Friday, 07 August, 2009

More Related Content

PDF
Perils of Page-Object Pattern
PDF
Mastering Test Automation: How to Use Selenium Successfully
PPT
Intro to Service Worker API and its use cases
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
PDF
Test Driven Development in AEM/CQ5
PPTX
Story Testing Approach for Enterprise Applications using Selenium Framework
PPTX
Brace yourself from automation death trap
PPTX
Protractor for angularJS
Perils of Page-Object Pattern
Mastering Test Automation: How to Use Selenium Successfully
Intro to Service Worker API and its use cases
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Test Driven Development in AEM/CQ5
Story Testing Approach for Enterprise Applications using Selenium Framework
Brace yourself from automation death trap
Protractor for angularJS

What's hot (20)

PPTX
Test Driven Development in CQ5/AEM
PPTX
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
PDF
Automated Testing in Angular Slides
PDF
Cucumber ppt
PDF
[Webinar] Continuous Testing Done Right: Test Automation at the World's Leadi...
PDF
Better Page Object Handling with Loadable Component Pattern
PPTX
Selenium WebDriver - Test automation for web applications
PDF
Patterns of a “good” test automation framework
PDF
Introduction To Web Application Testing
PDF
Selenium Tips & Tricks
PDF
UI Testing Automation
PDF
Rspec and Capybara Intro Tutorial at RailsConf 2013
PPTX
Angular Unit Testing
PPTX
An easy way to automate complex UI
PPT
Test Automation With Cucumber JVM, Selenium, and Mocha
PDF
Visual Automation Framework via Screenshot Comparison
DOCX
Protractor end-to-end testing framework for angular js
PPTX
Design patterns in test automation
DOCX
Automation Frame works Instruction Sheet
PPTX
Colorful world-of-visual-automation-testing-latest
Test Driven Development in CQ5/AEM
DSL, Page Object and WebDriver – the path to reliable functional tests.pptx
Automated Testing in Angular Slides
Cucumber ppt
[Webinar] Continuous Testing Done Right: Test Automation at the World's Leadi...
Better Page Object Handling with Loadable Component Pattern
Selenium WebDriver - Test automation for web applications
Patterns of a “good” test automation framework
Introduction To Web Application Testing
Selenium Tips & Tricks
UI Testing Automation
Rspec and Capybara Intro Tutorial at RailsConf 2013
Angular Unit Testing
An easy way to automate complex UI
Test Automation With Cucumber JVM, Selenium, and Mocha
Visual Automation Framework via Screenshot Comparison
Protractor end-to-end testing framework for angular js
Design patterns in test automation
Automation Frame works Instruction Sheet
Colorful world-of-visual-automation-testing-latest
Ad

Viewers also liked (20)

PDF
Beyond Page Objects
PDF
Page Objects Done Right - selenium conference 2014
PDF
Automation Abstraction Layers: Page Objects and Beyond
PPT
A journey beyond the page object pattern
PPTX
DSL, Page Object and Selenium – a way to reliable functional tests
PPTX
Introduction to Selenium Web Driver
PPT
Test Automation Framework Designs
PPTX
Automation Testing by Selenium Web Driver
PDF
Automation Testing using Selenium
PDF
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
PPT
Software Estimation Techniques
PPT
Selenium ppt
PDF
Selenium - The page object pattern
PPT
Web Test Automation with Selenium
PPT
Software cost estimation
PPT
Automation testing strategy, approach & planning
PPTX
Refactoring page objects The Screenplay Pattern
PDF
Advanced Selenium Workshop
PDF
Nodejs - A quick tour (v6)
PPTX
Specifications For Enterprise Testing
Beyond Page Objects
Page Objects Done Right - selenium conference 2014
Automation Abstraction Layers: Page Objects and Beyond
A journey beyond the page object pattern
DSL, Page Object and Selenium – a way to reliable functional tests
Introduction to Selenium Web Driver
Test Automation Framework Designs
Automation Testing by Selenium Web Driver
Automation Testing using Selenium
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Software Estimation Techniques
Selenium ppt
Selenium - The page object pattern
Web Test Automation with Selenium
Software cost estimation
Automation testing strategy, approach & planning
Refactoring page objects The Screenplay Pattern
Advanced Selenium Workshop
Nodejs - A quick tour (v6)
Specifications For Enterprise Testing
Ad

Similar to Using The Page Object Pattern (20)

PDF
PHPUnit & Continuous Integration: An Introduction
PDF
Web Application Testing with Selenium
PDF
TLC2018 Shyam Sunder: Legoizing Testing
PDF
How To Make Your Testing More Groovy
PPTX
Generalization in Auto-Testing. How we put what we had into new Technological...
PDF
2011 JavaOne Apache TomEE Java EE 6 Web Profile
PDF
Plone Testing Tools And Techniques
KEY
Enterprise Strength Mobile JavaScript
PPT
Useful automation
PDF
FreshAir2008
PDF
FreshAir2008
PDF
SVCC 2011 - 0 - 60: QA Automation @ Box
PDF
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
PPTX
Sap inside track Munich 2017
PPTX
Opticon 2017 How Developers Can Take Experimentation
PPTX
Growing Trends of Open Source UI Frameworks
PDF
Test Driven Sysadmin
PDF
Web Test Automation Framework - IndicThreads Conference
PDF
Why Your Selenium Tests are so Dang Brittle, and What to Do About It
PPTX
Test Driven Development
PHPUnit & Continuous Integration: An Introduction
Web Application Testing with Selenium
TLC2018 Shyam Sunder: Legoizing Testing
How To Make Your Testing More Groovy
Generalization in Auto-Testing. How we put what we had into new Technological...
2011 JavaOne Apache TomEE Java EE 6 Web Profile
Plone Testing Tools And Techniques
Enterprise Strength Mobile JavaScript
Useful automation
FreshAir2008
FreshAir2008
SVCC 2011 - 0 - 60: QA Automation @ Box
DjangoCon 2013 - How to Write Fast and Efficient Unit Tests in Django
Sap inside track Munich 2017
Opticon 2017 How Developers Can Take Experimentation
Growing Trends of Open Source UI Frameworks
Test Driven Sysadmin
Web Test Automation Framework - IndicThreads Conference
Why Your Selenium Tests are so Dang Brittle, and What to Do About It
Test Driven Development

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPT
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Monthly Chronicles - July 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Empathic Computing: Creating Shared Understanding
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Understanding_Digital_Forensics_Presentation.pptx
cuic standard and advanced reporting.pdf
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Teaching material agriculture food technology

Using The Page Object Pattern

  • 1. Using the Page Object Pattern to Improve Functional Test Maintainability Dante Briones Principal Consultant Electronic Ingenuity LLC http://electronicingenuity.com Friday, 07 August, 2009
  • 2. The Page Object Pattern • Technique for structuring test code that: • Promotes reuse and reduces duplication • Makes tests readable • Makes tests more robust (less brittle) • Improves maintainability, particularly if the application is rapidly evolving Friday, 07 August, 2009
  • 3. The Page Object Pattern • Demos will be coded in Java • Everything we discuss is applicable to other strongly-typed languages (e.g. C#) • Most things are applicable to dynamically- typed languages (e.g. Ruby, Python, Perl) Friday, 07 August, 2009
  • 4. Selenium IDE Quick Poll • How many using Se IDE? • How many create tests primarily through record & playback? Friday, 07 August, 2009
  • 5. Selenium IDE It’s Great Because: • It’s Free • It’s Free • Requires little or no programming experience Friday, 07 August, 2009
  • 6. Selenium IDE It falls short because: • Selenese is not a programming language • No support for loops/iteration • No support for conditionals (if...else) • No way to eliminate duplicated code! Friday, 07 August, 2009
  • 7. Selenium IDE Why is duplication bad? • Has this ever happened to you? • A tiny change to the app causes several test failures? • Let’s see an example Friday, 07 August, 2009
  • 9. Selenium IDE Why is duplication bad? • Fixing the tests will require more work than the change that caused the failure • Duplication makes code less maintainable Friday, 07 August, 2009
  • 10. Selenium IDE Summary • Great productivity for the first few tests • Maintainability decreases as the test suite grows • How can we do better? Friday, 07 August, 2009
  • 11. Start Coding Your Tests a.k.a. “Write tests in a programming language” Friday, 07 August, 2009
  • 12. Coding Your Tests Quick Poll • How many are using Selenium RC? Friday, 07 August, 2009
  • 13. Coding Your Tests How does this help? • We can eliminate duplication by building abstractions • Let’s see an example of this Friday, 07 August, 2009
  • 15. Coding Your Tests What happens next? • All commonly used methods get pulled into the base class of all tests • As the test suite grows, so does the base class • Uh oh...the base class starts getting too big Friday, 07 August, 2009
  • 16. Coding Your Tests How Big is Too Big? • You can’t tell someone else has already written the code you’re about to write • Frequent version control conflicts • Maintenance is an issue again Friday, 07 August, 2009
  • 17. Coding Your Tests How to rein in your base class? • Observation: For any given page, most of the behavior does not apply • Example: you can’t change your password on the “view cart” page • What if we moved the page-specific behavior into a corresponding class? • Voila! The Page Object is born Friday, 07 August, 2009
  • 18. The Page Object Friday, 07 August, 2009
  • 19. The Page Object What does it do? • Consolidates the code for interacting with any given UI element • Allows you to model the UI in your tests Friday, 07 August, 2009
  • 20. The Page Object What does it do? • Exposes methods that reflect the things a user can see and do on that page, e.g. • addItemToCart(), getPrice() • getEntryTitle(), saveDraft(), publishEntry() • Hides the details of telling the browser how to do those things Friday, 07 August, 2009
  • 22. The Page Object Results • Test code is very readable • No duplication of Selenium API calls • Interactive documentation via Ctrl-Space • Eminently reusable code Friday, 07 August, 2009
  • 23. The Page Object Results • This technique is framework-agnostic • Has been used with Selenium, WebDriver (Selenium 2.0), Watir, and others • I’ve even used it to drive desktop apps Friday, 07 August, 2009
  • 24. The Page Object Results • Because it encapsulates the details of the test framework API: • You can use this technique to simplify the process of swapping frameworks • In theory, you only need to reimplement the Page base class. Friday, 07 August, 2009
  • 25. But wait, there’s more! It gets better! • Page Objects improve maintainability • They also provide an opportunity to make test creation extremely quick (and maybe even fun!) • How? Page Objects + Method Chaining Friday, 07 August, 2009
  • 26. Method Chaining What’s method chaining? • Change the signature of user behavior methods so that they return the page object itself • Allows multiple behavior methods to be called in sequence Friday, 07 August, 2009
  • 27. Method Chaining What will it do for me? • Removes for “code clutter” • Tests become even more readable Friday, 07 August, 2009
  • 28. Method Chaining How does it work in practice? • All Page Object methods return a reference to a Page Object • If the “user action” moves the focus to a different page, the method should return that page object • Otherwise, return the same page object • Time for an example Friday, 07 August, 2009
  • 30. Method Chaining Results • Test code is even more readable • Very quick to write • (Actually kinda fun. Don’t tell anyone!) Friday, 07 August, 2009
  • 31. Method Chaining Caveats • Dependent on tool support • Lots of options: IntelliJ IDEA, Eclipse, NetBeans, VisualStudio Friday, 07 August, 2009
  • 32. Method Chaining Caveats • Tool support depends on language • Excellent support for strongly typed languages like Java and C# • Support is “up and coming” for dynamically typed languages (Ruby, Python, and Perl) Friday, 07 August, 2009
  • 33. The Page Object Pattern • Technique for organizing test code that: • Promotes reuse and reduces duplication • Makes tests readable • Makes tests more robust (less brittle) • Improves maintainability, particularly if the application is rapidly evolving • Is just as quick record & playback! Friday, 07 August, 2009
  • 34. Q &A Friday, 07 August, 2009