Writing Maintainable Tests with PageObjects
-
Upload
mdenomy -
Category
Technology
-
view
395 -
download
0
description
Transcript of Writing Maintainable Tests with PageObjects
![Page 1: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/1.jpg)
Writing Maintainable, Expressive Tests with PageObjects
Michael Denomy @mdenomy
![Page 2: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/2.jpg)
About Me
• Senior Developer @TerribleLabs
• Practicing Agile for ~10 years
• @mdenomy on Twitter and gmail
• http://mdenomy.wordpress.com/
![Page 3: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/3.jpg)
I ❤️ TDD
![Page 4: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/4.jpg)
I ❤️ TDD• Why?
![Page 5: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/5.jpg)
I ❤️ TDD• Why?
• Makes me a better developer
![Page 6: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/6.jpg)
I ❤️ TDD• Why?
• Makes me a better developer
• Keeps me thinking of behavior before implementation
![Page 7: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/7.jpg)
I ❤️ TDD• Why?
• Makes me a better developer
• Keeps me thinking of behavior before implementation
• TDD, BDD, more or less the same for me
![Page 8: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/8.jpg)
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…..
![Page 9: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/9.jpg)
Well-Factored Tests
• Tests should follow same principles as application code
• Expressive
• Well-factored
• DRY
![Page 10: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/10.jpg)
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
![Page 11: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/11.jpg)
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
![Page 12: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/12.jpg)
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
![Page 13: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/13.jpg)
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
![Page 14: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/14.jpg)
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
![Page 15: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/15.jpg)
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
![Page 16: Writing Maintainable Tests with PageObjects](https://reader035.fdocuments.in/reader035/viewer/2022081907/5481d42bb079592e0c8b45fc/html5/thumbnails/16.jpg)
Writing Maintainable, Expressive Tests with PageObjects
Michael Denomy @mdenomy