SlideShare a Scribd company logo
1 of 45
Download to read offline
@BagmarAnand
Design Patterns in
Test Automation
Anand Bagmar
Software Quality Evangelist
@BagmarAnand
BagmarAnand
https://www.linkedin.com/in/anandbagmar/
About Me
Design Principles
@BagmarAnand
@BagmarAnand
SOLID Design Principles
https://devopedia.org/solid-design-principles
@BagmarAnand
Design Principles
• Principle of Least Knowledge – Talk only to your immediate friends
• Loose Coupled Principle – Loosely coupled design between objects that interact
What is a Pattern?
@BagmarAnand
@BagmarAnand
https://en.wikipedia.org/wiki/Software_design_pattern
@BagmarAnand
Have you heard-of,
or, used any
Pattern(s) in Test Automation?
@BagmarAnand
@BagmarAnand
Common patterns used in test automation
• Page-Object
• Singleton
• Composition
• Factory Method
• Abstract Factory
• Builder
• Decorator
• Observer
• Command
• Adapter
• Facade
Functional Test
Automation
@BagmarAnand
Code sample - #1
@BagmarAnand
Applying structure
to Functional Test
Automation
@BagmarAnand
Page-Object Pattern
@BagmarAnand
@BagmarAnand
Page Object Pattern
Model pages
in code
Simulates user actions Reduces code duplication
One place change
Code sample - #2
@BagmarAnand
@BagmarAnand
Page Object Pattern
Model pages
in code
Simulates user actions
One place change
Reduces code duplication
Snippets
of page
Code sample - #3
@BagmarAnand
@BagmarAnand
Automation framework with Page Objects
@BagmarAnand
Limitations of Page-Object Pattern
• Test intent gets polluted
• Duplication of Test intent & implementation
• Intent becomes Imperative
• Maintenance challenges
• Scaling challenges
Business-Layer
Page-Object Pattern
@BagmarAnand
@BagmarAnand
Automation framework with Page Objects
@BagmarAnand
Business-layer Page-Object Pattern
Code sample - #3
@BagmarAnand
@BagmarAnand
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’
Test Data Patterns
@BagmarAnand
Why do we need to
think differently
about Test Data?
@BagmarAnand
@BagmarAnand
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
@BagmarAnand
Different ways to specify Test Data
• In Test implementation
• In Test specification / intent
• In code … separate data structures / classes / etc.
• External files
@BagmarAnand
Test Data Specification Examples
• Excel
• CSV
• Property
• XML
• YAML
• Database
• Json
Code sample - #4
@BagmarAnand
@BagmarAnand
Criteria for selection
• Easy to specify
• Easy to read and consume (by test framework)
• Ability to override specified data, easily
• Usable
@BagmarAnand
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.
Locators’ Patterns
@BagmarAnand
@BagmarAnand
Different ways to specify element locators
• In Page-Objects
• In separate files, per Page-Object
• In external files / locator files
Advantages of
using Patterns for
Test Automation
@BagmarAnand
@BagmarAnand
Advantages of Design Patterns
• Well known, well understood
• Tried & tested solutions for common problems
• Reduces complexity
• Language neutral
• Aid in communication
@BagmarAnand
Advantages of Design 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
@BagmarAnand
@BagmarAnand
Which is the “best” pattern to use ?
https://cdn.pixabay.com/photo/2016/02/16/02/17/hands-1202488_1280.png
It DEPENDS!
on the
Context!
@BagmarAnand
@BagmarAnand
References
• SOLID Design Principles
• https://www.monterail.com/hubfs/PDF%20content/SOLID_cheatsheet.pdf
• https://web.archive.org/web/20150906155800/http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf
• https://devopedia.org/solid-design-principles
• 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
• Sample Test Framework implementation
• https://github.com/znsio/tesiz
@BagmarAnand
BagmarAnand
https://www.linkedin.com/in/anandbagmar/
Thank you

More Related Content

More from Anand Bagmar

Getting started with Appium 2.0
Getting started with Appium 2.0Getting started with Appium 2.0
Getting started with Appium 2.0Anand Bagmar
 
Visual Validation - The missing tip of the automation pyramid @AgileIndia2020
Visual Validation - The missing tip of the automation pyramid @AgileIndia2020Visual Validation - The missing tip of the automation pyramid @AgileIndia2020
Visual Validation - The missing tip of the automation pyramid @AgileIndia2020Anand Bagmar
 
Selenium Deep Dive
Selenium Deep DiveSelenium Deep Dive
Selenium Deep DiveAnand Bagmar
 
Does your functional automation really add value?
Does your functional automation really add value?Does your functional automation really add value?
Does your functional automation really add value?Anand Bagmar
 
Measuring Coverage From E2E Tests
Measuring Coverage From E2E TestsMeasuring Coverage From E2E Tests
Measuring Coverage From E2E TestsAnand Bagmar
 
Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020Anand Bagmar
 
Visual validation - The missing tip of the automation pyramid @ QA Symposium
Visual validation - The missing tip of the automation pyramid @ QA SymposiumVisual validation - The missing tip of the automation pyramid @ QA Symposium
Visual validation - The missing tip of the automation pyramid @ QA SymposiumAnand Bagmar
 
Collaboration - A Taboo!
Collaboration - A Taboo!Collaboration - A Taboo!
Collaboration - A Taboo!Anand Bagmar
 
Visual Validation - The Missing Tip of the Automation Pyramid
Visual Validation - The Missing Tip of the Automation PyramidVisual Validation - The Missing Tip of the Automation Pyramid
Visual Validation - The Missing Tip of the Automation PyramidAnand Bagmar
 
Measuring Consumer Quality - The Missing Feedback Loop
Measuring Consumer Quality - The Missing Feedback LoopMeasuring Consumer Quality - The Missing Feedback Loop
Measuring Consumer Quality - The Missing Feedback LoopAnand Bagmar
 
What is Agile Testing? How does Automation help?
What is Agile Testing? How does Automation help?What is Agile Testing? How does Automation help?
What is Agile Testing? How does Automation help?Anand Bagmar
 
The What, Why and How of Analytics Testing
The What, Why and How of Analytics TestingThe What, Why and How of Analytics Testing
The What, Why and How of Analytics TestingAnand Bagmar
 
Patterns of a “good” test automation framework
Patterns of a “good” test automation frameworkPatterns of a “good” test automation framework
Patterns of a “good” test automation frameworkAnand Bagmar
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance TestingAnand Bagmar
 
Sharing (less) Pain of using Protractor & WebDriver
Sharing (less) Pain of using Protractor & WebDriverSharing (less) Pain of using Protractor & WebDriver
Sharing (less) Pain of using Protractor & WebDriverAnand Bagmar
 
Automating Web Analytics
Automating Web AnalyticsAutomating Web Analytics
Automating Web AnalyticsAnand Bagmar
 
Sharing the pain using Protractor
Sharing the pain using ProtractorSharing the pain using Protractor
Sharing the pain using ProtractorAnand Bagmar
 
Test Data - Food for your Test Automation Framework
Test Data - Food for your Test Automation FrameworkTest Data - Food for your Test Automation Framework
Test Data - Food for your Test Automation FrameworkAnand Bagmar
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and PracticesAnand Bagmar
 
The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)
The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)
The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)Anand Bagmar
 

More from Anand Bagmar (20)

Getting started with Appium 2.0
Getting started with Appium 2.0Getting started with Appium 2.0
Getting started with Appium 2.0
 
Visual Validation - The missing tip of the automation pyramid @AgileIndia2020
Visual Validation - The missing tip of the automation pyramid @AgileIndia2020Visual Validation - The missing tip of the automation pyramid @AgileIndia2020
Visual Validation - The missing tip of the automation pyramid @AgileIndia2020
 
Selenium Deep Dive
Selenium Deep DiveSelenium Deep Dive
Selenium Deep Dive
 
Does your functional automation really add value?
Does your functional automation really add value?Does your functional automation really add value?
Does your functional automation really add value?
 
Measuring Coverage From E2E Tests
Measuring Coverage From E2E TestsMeasuring Coverage From E2E Tests
Measuring Coverage From E2E Tests
 
Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020
 
Visual validation - The missing tip of the automation pyramid @ QA Symposium
Visual validation - The missing tip of the automation pyramid @ QA SymposiumVisual validation - The missing tip of the automation pyramid @ QA Symposium
Visual validation - The missing tip of the automation pyramid @ QA Symposium
 
Collaboration - A Taboo!
Collaboration - A Taboo!Collaboration - A Taboo!
Collaboration - A Taboo!
 
Visual Validation - The Missing Tip of the Automation Pyramid
Visual Validation - The Missing Tip of the Automation PyramidVisual Validation - The Missing Tip of the Automation Pyramid
Visual Validation - The Missing Tip of the Automation Pyramid
 
Measuring Consumer Quality - The Missing Feedback Loop
Measuring Consumer Quality - The Missing Feedback LoopMeasuring Consumer Quality - The Missing Feedback Loop
Measuring Consumer Quality - The Missing Feedback Loop
 
What is Agile Testing? How does Automation help?
What is Agile Testing? How does Automation help?What is Agile Testing? How does Automation help?
What is Agile Testing? How does Automation help?
 
The What, Why and How of Analytics Testing
The What, Why and How of Analytics TestingThe What, Why and How of Analytics Testing
The What, Why and How of Analytics Testing
 
Patterns of a “good” test automation framework
Patterns of a “good” test automation frameworkPatterns of a “good” test automation framework
Patterns of a “good” test automation framework
 
Client-Side Performance Testing
Client-Side Performance TestingClient-Side Performance Testing
Client-Side Performance Testing
 
Sharing (less) Pain of using Protractor & WebDriver
Sharing (less) Pain of using Protractor & WebDriverSharing (less) Pain of using Protractor & WebDriver
Sharing (less) Pain of using Protractor & WebDriver
 
Automating Web Analytics
Automating Web AnalyticsAutomating Web Analytics
Automating Web Analytics
 
Sharing the pain using Protractor
Sharing the pain using ProtractorSharing the pain using Protractor
Sharing the pain using Protractor
 
Test Data - Food for your Test Automation Framework
Test Data - Food for your Test Automation FrameworkTest Data - Food for your Test Automation Framework
Test Data - Food for your Test Automation Framework
 
Test Automation - Principles and Practices
Test Automation - Principles and PracticesTest Automation - Principles and Practices
Test Automation - Principles and Practices
 
The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)
The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)
The What, Why and How of (Web) Analytics Testing (Web, IoT, Big Data)
 

Design Patterns in Automation