TrainingConferencesAbout UsContact UsAdvertiseSQE.com

StickyMinds.com: brain food for building better software

Join

Join

Clarify Your Search Criteria
Tips on Using Our Search Feature(s)
StickyMinds.com Home
ResourcesEventsTopicsPowerPassJobs
Software Testing & QA Online Community  >  Detail: Easing Test Automation with the Page Object Pattern



A StickyMinds.com Original
Article Picture
Easing Test Automation with the Page Object Pattern

By Lisa Crispin

Send This Content to a FriendGet a Short Link to This ContentPrint This ContentSee User Comments About This Content

Summary: Everyone knows that GUI tests are brittle and costly to maintain, right? That conventional wisdom has broken down in recent years, thanks to better test libraries and frameworks, and better approaches to designing maintainable automated tests. My own current team felt our GUI tests, written starting in 2004, had a reasonable return on investment, but we still found we were spending more time than we liked to refactor and maintain them.


Tricentis

Everyone knows that GUI tests are brittle and costly to maintain, right? That conventional wisdom has broken down in recent years, thanks to better test libraries and frameworks, and better approaches to designing maintainable automated tests. My own current team felt our GUI tests, written starting in 2004, had a reasonable return on investment, but we still found we were spending more time than we liked to refactor and maintain them.

In 2009, I was inspired by Dale Emery's session on writing maintainable automated tests at Agile Development Practices West. I already knew that, as Dale pointed out, writing automated test code is no different from writing production code. We need to use the same principles of eliminating duplication and hiding essential details. The names we give our test scripts also matter.

My team applied Dale's techniques as well as we could, but felt there was a "smell" with our overall automated test approach. At Agile 2010, I attended an OpenJam session by Patrick Wilson-Welsh, where he demonstrated a "page object" pattern. He showed how to hide details and eliminate duplication with web page classes and page control classes "under the covers." When we apply the object-oriented techniques we use in our production code to our test code, our test code becomes much easier to understand and maintain. A "page object" is a test object that holds the details of all the elements on a web page that might be involved in an automated test.

I excitedly showed Patrick's work to my then-teammate Tony Sweets, who was officially our system administrator but also a developer who had always helped with our test automation. He started experimenting with the page object pattern.

Our team had other compelling reasons to start using Selenium WebDriver, and we wanted to apply the page object pattern. Our whole team, including Tony and other developers and testers, experimented with different frameworks, finally settling on Robot Framework. The developers and a system administrator on our team helped us understand the pattern, but we wanted to ensure that we got started on the right track in order to get a solid foundation for our tests. We brought in a coach who has a lot of experience using the page object pattern to help us with a customized three-day course, writing actual tests for our own application. We took the time to learn and experiment with good ways to apply this pattern.

Two months into using the page object pattern, I'm happy to report that frequent UI changes as we develop a new feature are no problem at all! For each change, we only have to change one file and all our automated tests continue to work. We're still learning and experimenting, but we’re confident our GUI tests will deliver a much better return on investment than before.

Practitioners such as Jeff "Cheezy" Morgan provide resources that give teams a head start in applying the page object pattern to automated GUI tests. Check out some ways that my own team is applying this pattern, and try your own experiments to see if you can create UI tests that are less brittle and cost less to maintain by applying the page object pattern. 

About the Author
Lisa Crispin is the co-author, with Janet Gregory, of Agile Testing: A Practical Guide for Testers and Agile Teams (Addison-Wesley, 2009), co-author with Tip House of Extreme Testing (Addison-Wesley, 2002) and a contributor to Beautiful Testing (O’Reilly, 2009). She has worked as a tester on agile teams for the past ten years, and enjoys sharing her experiences via writing, presenting, teaching and participating in agile testing communities around the world. Lisa was named one of the 13 Women of Influence in testing by Software Test & Performance magazine. For more about Lisa’s work, visit www.lisacrispin.com.

Back to Top
 
 


Member Comments
Add Your CommentExpand Comments
 
Comment:    
by Curtis Stuehrenberg 7/24/2012

I'm curious about why you went with Robot. Can you elaborate on why you chose that specific framework versus going all the way with a framework like Cucumber which is open source but has a much larger and more active user community or Twist which is proprietary and so has vendor support?

Author's Response:
7/24/2012    
RobotFramework has quite an active user community, maybe not as big as Cucumber, but it's widely used in Europe. I have used RobotFramework for teaching basic test automation principles in tutorials and articles, and I happen to know some of the main RF developers and users. The support from the RF developer community has been excellent.

We've tried Cucumber before, but the Given/When/Then type pattern doesn't appeal to our team, not sure why. (No doubt it's possible to use other formats). We couldn't go with Twist because we all use IntelliJ IDEs. :->

RobotFramework's test result reporting and ease of integrating that into Jenkins was the biggest appeal compared to other frameworks. We've used Canoo Webtest (another open source tool) for 8+ years, and we're used to the ease with which we can drill down and see exactly what the problem was with a failing test. RobotFramework's result reporting is quite similar. AFAIK, Cucumber doesn't provide similar reporting.

Before RF, we tried Geb, but we didn't like the result reporting, and the learning curve for us testers learning Groovy was steep. RF uses Python, which is a bit weird, but we don't have to know much to be able to script the tests.

 
 
Comment:    
by Jim Hazen 7/23/2012

Interesting how the Selenium community is now catching up in the practice of using a 'component' type approach to automation for GUI. The practice of abstracting the individual page & object code into its own code module has been around a long time. This along with writing custom functions or methods for the objects has also been around a long time.
Both Component and Keyword automation methodologies, or a combination of both in Hybrid approaches, prescribe to an approach of modularizing the code and working towards robust and reusable code in automation.
The problem with GUI automation has always been one of ignorance by the...Read On

Author's Response:
7/23/2012    
Agreed, the page object pattern isn't new, it was only new to me when I saw Patrick Wilson-Welsh present on it.

Don't even get me started on record/playback, and a lot of the commercial tools, though I'm told some of these are getting a lot better.

IME the most successful test automation happens when testers & coders collaborate on it. Testers know what tests to write, coders know best way to design the code. Plus, that collaboration gives us a shared vision of the feature being tested.

 
Back to Top



 
Ads By Google
What's This?
 
 



About Us   |   Contact Us   |   Terms & Conditions   |   Privacy Policy   |   RSS Feed



© 2013 StickyMinds.com. All rights reserved.
ASTQB

Tricentis



Agile Development Conference & Better Software Conference West