Top Banner
PATTERNS OF A “GOOD” TEST AUTOMATION FRAMEWORK, LOCATORS & DATA! Anand Bagmar Test Practice Lead
43

Patterns in Test Automation

Apr 16, 2017

Download

Software

Anand Bagmar
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Patterns in Test Automation

PATTERNS OF A “GOOD” TEST AUTOMATION FRAMEWORK, LOCATORS & DATA!

Anand Bagmar Test Practice Lead

Page 2: Patterns in Test Automation

@BagmarAnand about.me/anand.bagmar

ABOUT ME

Page 3: Patterns in Test Automation

Test Automation Principle

Page 4: Patterns in Test Automation

Code Quality

Page 5: Patterns in Test Automation

What is a Design Pattern?

Page 6: Patterns in Test Automation
Page 7: Patterns in Test Automation

Have you heard-of or used any

Patterns for Test Automation?

Page 8: Patterns in Test Automation

COMMON PATTERNS USED IN TEST AUTOMATION

¨ Page-Object

¨ Business Layer

¨ Singleton

¨ Composition

¨ Factory

¨ Builder

Page 9: Patterns in Test Automation

Test Automation Framework Patterns

Page 10: Patterns in Test Automation

Case Study

Page 11: Patterns in Test Automation
Page 12: Patterns in Test Automation

Code sample - #1

Page 13: Patterns in Test Automation
Page 14: Patterns in Test Automation

Page-Object Pattern

Page 15: Patterns in Test Automation
Page 16: Patterns in Test Automation

PAGE OBJECT PATTERN

Model pages in code

Simulates user actions

One place change

Reduces code duplication

Snippets of page

Page 17: Patterns in Test Automation

AUTOMATION FRAMEWORK WITH PAGE OBJECTS

Page 18: Patterns in Test Automation

Code sample - #2

Page 19: Patterns in Test Automation

As the framework evolves ….

Page 20: Patterns in Test Automation

AUTOMATION FRAMEWORK WITH PAGE OBJECTS

Page 21: Patterns in Test Automation

Code sample - #3

Page 22: Patterns in Test Automation

LIMITATIONS OF PAGE-OBJECT PATTERN

¨ Test intent gets polluted

¨ Duplication of Test intent & implementation

¨  Intent becomes Imperative

¨ Maintenance challenges

¨ Scaling challenges

Page 23: Patterns in Test Automation

Business-Layer

Page-Object Pattern

Page 24: Patterns in Test Automation

BUSINESS-LAYER PAGE-OBJECT PATTERN

Page 25: Patterns in Test Automation

Code sample - #4

Page 26: Patterns in Test Automation

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’

Page 27: Patterns in Test Automation

Test Data Patterns

Page 28: Patterns in Test Automation

Why do we need to think differently about Test Data?

Page 29: Patterns in Test Automation

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

Page 30: Patterns in Test Automation

DIFFERENT WAYS TO SPECIFY TEST DATA

¨  In Test implementation

¨  In Test specification / intent

¨  In code … separate data structures / classes / etc.

¨ External files

Page 31: Patterns in Test Automation

TEST DATA SPECIFICATION EXAMPLES

¨ Excel

¨ CSV

¨ Property

¨ XML

¨ YAML

¨ Database

¨  Json

Page 32: Patterns in Test Automation

Code sample - #5

Page 33: Patterns in Test Automation

CRITERIA FOR SELECTION

¨ Easy to specify

¨ Easy to read and consume (by test framework)

¨ Ability to override specified data, easily

¨ Usable

Page 34: Patterns in Test Automation

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.

Page 35: Patterns in Test Automation

Locators’ Patterns

Page 36: Patterns in Test Automation

DIFFERENT WAYS TO SPECIFY ELEMENT LOCATORS

¨  In Page-Objects

¨  In separate files, per Page-Object

¨  In external files / locator files

Page 37: Patterns in Test Automation

Advantages of using Patterns for Test Automation

Page 38: Patterns in Test Automation

ADVANTAGES OF PATTERNS

¨ Well known, well understood

¨ Tried & tested solutions for common problems

¨ Reduces complexity

¨ Language neutral

¨ Aid in communication

Page 39: Patterns in Test Automation

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

Page 40: Patterns in Test Automation

WHICH IS THE “BEST” PATTERN TO USE ?

Page 41: Patterns in Test Automation

It DEPENDS! on the

Context!

Page 42: Patterns in Test Automation

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

Page 43: Patterns in Test Automation

[email protected] [email protected]

@BagmarAnand

about.me/anand.bagmar

THANK YOU