Writing Maintainable, Expressive Tests with PageObjects
Michael Denomy @mdenomy
About Me
• Senior Developer @TerribleLabs
• Practicing Agile for ~10 years
• @mdenomy on Twitter and gmail
• http://mdenomy.wordpress.com/
I ❤️ TDD
I ❤️ TDD• Why?
I ❤️ TDD• Why?
• Makes me a better developer
I ❤️ TDD• Why?
• Makes me a better developer
• Keeps me thinking of behavior before implementation
I ❤️ TDD• Why?
• Makes me a better developer
• Keeps me thinking of behavior before implementation
• TDD, BDD, more or less the same for me
I ❤️ TDD• Why?
• Makes me a better developer
• Keeps me thinking of behavior before implementation
• TDD, BDD, more or less the same for me
• It’s not about testing…..
Well-Factored Tests
• Tests should follow same principles as application code
• Expressive
• Well-factored
• DRY
What does it mean to be DRY
• Don’t Repeat Yourself
• Actually it is OK to repeat yourself
• Just eliminate the duplication as part of your Red-Green-Refactor workflow
What are Page Objects• Wraps an HTML page in an
application DSL
• Allows us to write acceptance tests using application language
• HTML specific bits are kept in one place
• Tests are less brittle
http://martinfowler.com/bliki/PageObject.html
Let’s look at some code• Denomy’s Wine Emporium
• https://github.com/mdenomy/foundation-demo • Originally written to play around with Zurb Foundation’s grid system,
but threw in some tests with PageObjects for this talk
• To see the overall workflow check out these branches in the following order • manager-adds-event • introduce-page-objects • events-on-homepage • order-events • limit-events-on-homepage • base-page-object
Let’s look at some codeUser Story - Manager Creates Events
As a store manager, I want create events that will be shown on the home page, so that people visit the store and buy lots of wine
Summary
• Abstract the implementation of an HTML page away from your tests
• Write your acceptance tests around application behaviors
• Write tests with the same focus on quality as application code
References
• http://martinfowler.com/bliki/PageObject.html
• http://robots.thoughtbot.com/better-acceptance-tests-with-page-objects
• https://code.google.com/p/selenium/wiki/PageObjects
Writing Maintainable, Expressive Tests with PageObjects
Michael Denomy @mdenomy
Top Related