Patterns of a "Good" Test Automation Framework, Locators & Data

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

Transcript of Patterns of a "Good" Test Automation Framework, Locators & Data

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

Anand Bagmar Test Practice Lead

@BagmarAnand about.me/anand.bagmar

ABOUT ME

Test Automation Principle

Code Quality

What is a Design Pattern?

Have you heard-of or used any

Patterns for Test Automation?

COMMON PATTERNS USED IN TEST AUTOMATION

¨ Page-Object

¨ Business Layer

¨ Singleton

¨ Composition

¨ Factory

¨ Builder

Test Automation Framework Patterns

Case Study

Code sample - #1

Page-Object Pattern

PAGE OBJECT PATTERN

Model pages in code

Simulates user actions

One place change

Reduces code duplication

Snippets of page

AUTOMATION FRAMEWORK WITH PAGE OBJECTS

Code sample - #2

As the framework evolves ….

AUTOMATION FRAMEWORK WITH PAGE OBJECTS

Code sample - #3

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

BUSINESS-LAYER PAGE-OBJECT PATTERN

Code sample - #4

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

Why do we need to think differently about Test Data?

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

DIFFERENT WAYS TO SPECIFY TEST DATA

¨  In Test implementation

¨  In Test specification / intent

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

¨ External files

TEST DATA SPECIFICATION EXAMPLES

¨ Excel

¨ CSV

¨ Property

¨ XML

¨ YAML

¨ Database

¨  Json

Code sample - #5

CRITERIA FOR SELECTION

¨ Easy to specify

¨ Easy to read and consume (by test framework)

¨ Ability to override specified data, easily

¨ Usable

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

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

ADVANTAGES OF PATTERNS

¨ Well known, well understood

¨ Tried & tested solutions for common problems

¨ Reduces complexity

¨ Language neutral

¨ Aid in communication

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

WHICH IS THE “BEST” PATTERN TO USE ?

It DEPENDS! on the

Context!

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

[email protected] [email protected]

@BagmarAnand

about.me/anand.bagmar

THANK YOU