16
Writing Maintainable, Expressive Tests with PageObjects Michael Denomy @mdenomy

Writing Maintainable Tests with PageObjects

  • Upload
    mdenomy

  • View
    395

  • Download
    0

Embed Size (px)

DESCRIPTION

How to write maintainable Ruby on Rails integration tests using PageObjects. The code for this can be found at https://github.com/mdenomy/foundation-demo#demo-of-page-objects

Citation preview

Page 1: Writing Maintainable Tests with PageObjects

Writing Maintainable, Expressive Tests with PageObjects

Michael Denomy @mdenomy

Page 2: Writing Maintainable Tests with PageObjects

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

I ❤️ TDD

Page 4: Writing Maintainable Tests with PageObjects

I ❤️ TDD• Why?

Page 5: Writing Maintainable Tests with PageObjects

I ❤️ TDD• Why?

• Makes me a better developer

Page 6: Writing Maintainable Tests with PageObjects

I ❤️ TDD• Why?

• Makes me a better developer

• Keeps me thinking of behavior before implementation

Page 7: Writing Maintainable Tests with PageObjects

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

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

Well-Factored Tests

• Tests should follow same principles as application code

• Expressive

• Well-factored

• DRY

Page 10: Writing Maintainable Tests with PageObjects

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

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

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

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

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

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

Writing Maintainable, Expressive Tests with PageObjects

Michael Denomy @mdenomy