Patterns in Test Automation

16,087 views

Published on

Building a Test Automation Framework is easy - there are so many resources / guides / blogs / etc. available to help you get started and help solve the issues you get along the journey.

However, building a "good" Test Automation Framework is not very easy. There are a lot of principles and practices you need to use, in the right context, with a good set of skills required to make the Test Automation Framework maintainable, scalable and reusable.

Design Patterns play a big role in helping achieve this goal of building a good and robust framework.

In this talk, we will talk about, and see examples of various types of patterns you can use for:

Build your Test Automation Framework
Test Data Management
Locators / IDs (for finding / interacting with elements in the browser / app)
Using these patterns you will be able to build a good framework, that will help keep your tests running fast, and reliably in your CI / CD setup!

Published in: Software
4 Comments
18 Likes
Statistics
Notes
No Downloads
Views
Total views
16,087
On SlideShare
0
From Embeds
0
Number of Embeds
8,463
Actions
Shares
0
Downloads
380
Comments
4
Likes
18
Embeds 0
No embeds

No notes for slide

Patterns in Test Automation

  1. 1. PATTERNS OF A “GOOD” TEST AUTOMATION FRAMEWORK, LOCATORS & DATA! Anand Bagmar Test Practice Lead
  2. 2. @BagmarAnand about.me/anand.bagmar ABOUT ME
  3. 3. Test Automation Principle
  4. 4. Code Quality
  5. 5. What is a Design Pattern?
  6. 6. Have you heard-of or used any Patterns for Test Automation?
  7. 7. COMMON PATTERNS USED IN TEST AUTOMATION ¨ Page-Object ¨ Business Layer ¨ Singleton ¨ Composition ¨ Factory ¨ Builder
  8. 8. Test Automation Framework Patterns
  9. 9. Case Study
  10. 10. Code sample - #1
  11. 11. Page-Object Pattern
  12. 12. PAGE OBJECT PATTERN Model pages in code Simulates user actions One place change Reduces code duplication Snippets of page
  13. 13. AUTOMATION FRAMEWORK WITH PAGE OBJECTS
  14. 14. Code sample - #2
  15. 15. As the framework evolves ….
  16. 16. AUTOMATION FRAMEWORK WITH PAGE OBJECTS
  17. 17. Code sample - #3
  18. 18. LIMITATIONS OF PAGE-OBJECT PATTERN ¨ Test intent gets polluted ¨ Duplication of Test intent & implementation ¨ Intent becomes Imperative ¨ Maintenance challenges ¨ Scaling challenges
  19. 19. Business-Layer Page-Object Pattern
  20. 20. BUSINESS-LAYER PAGE-OBJECT PATTERN
  21. 21. Code sample - #4
  22. 22. ADVANTAGES OF BUSINESS-LAYER PAGE-OBJECT PATTERN ¨ Validate what is important - Business requirements ¨ Test Pyramid remains sane ¨ Abstraction layers allow separation-of-concerns ¨ Changes are isolated ¨ Maintenance & Scaling becomes ‘easier’
  23. 23. Test Data Patterns
  24. 24. Why do we need to think differently about Test Data?
  25. 25. CRITERIA FOR TEST DATA ¨ Data is complex ¨ Needs to mimic “real” data ¨ Needs to be unique ¨ Data can be nested ¨ Though specified as static, may need to be Dynamic ¨ Data can be shared and reused
  26. 26. DIFFERENT WAYS TO SPECIFY TEST DATA ¨ In Test implementation ¨ In Test specification / intent ¨ In code … separate data structures / classes / etc. ¨ External files
  27. 27. TEST DATA SPECIFICATION EXAMPLES ¨ Excel ¨ CSV ¨ Property ¨ XML ¨ YAML ¨ Database ¨ Json
  28. 28. Code sample - #5
  29. 29. CRITERIA FOR SELECTION ¨ Easy to specify ¨ Easy to read and consume (by test framework) ¨ Ability to override specified data, easily ¨ Usable
  30. 30. TIPS FOR IMPLEMENTATION ¨ Consistent way to specify test data ¨ Read the data – as Business Entities ¨ Override as appropriate ¨ Create DSL to give meaning to data ¨ Use in test implementation ¨ Implement Test Data Entity Utilities – Build, Equals, Copy, Find, etc.
  31. 31. Locators’ Patterns
  32. 32. DIFFERENT WAYS TO SPECIFY ELEMENT LOCATORS ¨ In Page-Objects ¨ In separate files, per Page-Object ¨ In external files / locator files
  33. 33. Advantages of using Patterns for Test Automation
  34. 34. ADVANTAGES OF PATTERNS ¨ Well known, well understood ¨ Tried & tested solutions for common problems ¨ Reduces complexity ¨ Language neutral ¨ Aid in communication
  35. 35. ADVANTAGES OF PATTERNS IN TEST AUTOMATION Saves time & effort (eventually) Single ownership Test Automation Code is of Production Quality! Single point of change Easy to – - Implement - Maintain - Debug - Scale
  36. 36. WHICH IS THE “BEST” PATTERN TO USE ?
  37. 37. It DEPENDS! on the Context!
  38. 38. REFERENCES Page Objects – Google https://code.google.com/p/selenium/wiki/PageObjects Page Objects – Martin Fowler http://martinfowler.com/bliki/PageObject.html Perils of Page-Object Pattern – Anand Bagmar http://essenceoftesting.blogspot.in/2014/09/perils-of-page-object-pattern.html Test Design Consideration http://docs.seleniumhq.org/docs/06_test_design_considerations.jsp
  39. 39. abagmar@gmail.com Anand.Bagmar@thoughtworks.com @BagmarAnand about.me/anand.bagmar THANK YOU

×