Leverage automation testing with design patterns€¦ · Builder Concept • Separate the...

35
Leverage automation testing with design patterns Bodean Paul-Andrei

Transcript of Leverage automation testing with design patterns€¦ · Builder Concept • Separate the...

Page 1: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Leverage automation testing with design patterns

Bodean Paul-Andrei

Page 2: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Summary• Purpose of this research• A general overview – project related• Why design patterns• The catalog of design patterns• Classify patterns• Analyze patterns• Our top• Extended research• Q&A

Page 3: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Purpose of this research-> Testing challenges• Multiple platforms/technologies• Complex applications• Lack of human resources• Time• False failures• Code duplication• Spaghetti code

Page 4: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Purpose of this research-> Possible solutions• Hire more people to perform manual tests

• High cost with many resources• Increase the automation coverage with a

linear scripting framework• Fast test cases implementation• Need platform specific tools• Low cost with resources• Hard maintenance

• Build your own solid framework

Page 5: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Purpose of this research-> The actual solution• Build your own solid framework

• Modular• Data driven• Keyword driven• BDD• Hybrid

• Our approach = Hybrid framework + Design patterns

Page 6: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

A general overview –project related

Page 7: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

A general overview –project related

Page 8: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Why design patterns

Typical solutions to commonly

existing problems

Solve issues using proven

solutions

Code reusabilityReadability

Minimum effort

Solve problems using the OOP

principles

Page 9: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

The catalog of design patterns

Creational

• Provide different object creation related solutions

Structural

• Assemble objects into larger structures keeping the code flexible

Behavioral

• Focused on the responsibilities between objects

Page 10: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Classify patterns Creational

Simple factory

The factory method

Builder

Singleton

To be covered

Abstract factory

Prototype

Page 11: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Classify patternsStructural

Composite

Facade

Page object

To be covered

Decorator

Adaptor

Bridge

Proxy

Flyweight

Page 12: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Classify patternsBehavioral

Observer

State

Strategy

To be covered

Chain of responsibility

Command

Iterator

Mediator

Memento

Template Method

Visitor

Page 13: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

Simple factory Concept

• Factory – a centralized place where things are getting created

• Simple factory - allow interfaces to create objects without exposing the object creation logic

Page 14: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

Simple factory Usage

Page 15: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

The factory methodConcept

• Define an interface for creating an object but let subclasses to decide which class to instantiate

• Let a class to defer instantiation to subclasses

• In terms of automated testing, it’s good place to start when building a modular framework

• Each component acts as a wrapper over the application pages

Page 16: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

The factory methodUsage

Page 17: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

BuilderConcept

• Separate the construction of an test from its representation, so the whole construction process can create different representations

• We need a manager, a builder and a product• Manager – construct a specific test using the

builder• Builder – construct and assemble parts of

the test • Product – the test to be created

Page 18: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

BuilderUsage

Page 19: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

BuilderUsage

Page 20: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patternsSingletonConcept

• Let you create a single class instance of a given type

• Provide a global access point to it• Automation usage: usually during the

connectivity with a driver

Page 21: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patternsSingletonUsage

Page 22: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

Page objectConcept

• The most popular pattern in SW automation testing

• A page is an OOP class that servers as an interface to a page under AUT

• The main idea is to group all the content of a page in an object, so it will encapsulate:• Element IDS• Interactions

Page 23: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

Page objectUsage

Page 24: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

CompositeConcept

• Compose objects into tree structures• Automation related

• Test case design• Design small test cases having one or a

limited amount of steps• Implement more complex tests

composed of the previously defined simple tests

• Test plan definition -> Treat a test plan as an object composed from a set of test cases

Page 25: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

CompositeUsage

Page 26: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

FaçadeConcept

• Provide a single access point to a set of interfaces or classes

• It’s an interface for all your available pages• Automation usage: on the top of all the available

pages apply a single access point -> your facade

Page 27: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

FaçadeUsage

Page 28: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patternsObserverConcept

• Define a relationship between object, if one object state is changed, the others will be notified

• Automation usage• Automated performance testing

Page 29: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patternsObserverUsage

Page 30: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

StateConcept

• Allow an object to change it’s behavior, when an internal state is changed

• Automation related: • Define each test step as a state• Facilitates the test cases debugging in case

of complex scenarios• It helps us on the identification of any step

from a test case• Prevent false failures by treating new

possible behaviors individually

Page 31: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patterns

StateUsage

Page 32: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patternsStrategyConcept

• Define a family of algorithms, encapsulate each of them and make them interchangeable

• Strategy pattern give to the client the flexibility to use same object with different algorithms

• Automation related• Define a series of validators which could be

accessed by injecting them in a single interface• Useful while using different validation algorithms

in many contexts

Page 33: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Analyze patternsStrategyUsage

Page 34: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Our top:1. Façade – entry point2. Page object – grouping3. Simple factory – organized access 4. Singleton – one instance5. Observer - notification

Page 35: Leverage automation testing with design patterns€¦ · Builder Concept • Separate the construction of an test from its representation, so the whole construction process can create

Extended research

- GitHub: https://github.com/paulbodean88/automation-design-patterns

- Personal blog: www.atechnovel.com