Leverage automation testing with design patterns€¦ · Builder Concept • Separate the...
Transcript of Leverage automation testing with design patterns€¦ · Builder Concept • Separate the...
Leverage automation testing with design patterns
Bodean Paul-Andrei
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
Purpose of this research-> Testing challenges• Multiple platforms/technologies• Complex applications• Lack of human resources• Time• False failures• Code duplication• Spaghetti code
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
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
A general overview –project related
A general overview –project related
Why design patterns
Typical solutions to commonly
existing problems
Solve issues using proven
solutions
Code reusabilityReadability
Minimum effort
Solve problems using the OOP
principles
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
Classify patterns Creational
Simple factory
The factory method
Builder
Singleton
To be covered
Abstract factory
Prototype
Classify patternsStructural
Composite
Facade
Page object
To be covered
Decorator
Adaptor
Bridge
Proxy
Flyweight
Classify patternsBehavioral
Observer
State
Strategy
To be covered
Chain of responsibility
Command
Iterator
Mediator
Memento
Template Method
Visitor
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
Analyze patterns
Simple factory Usage
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
Analyze patterns
The factory methodUsage
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
Analyze patterns
BuilderUsage
Analyze patterns
BuilderUsage
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
Analyze patternsSingletonUsage
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
Analyze patterns
Page objectUsage
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
Analyze patterns
CompositeUsage
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
Analyze patterns
FaçadeUsage
Analyze patternsObserverConcept
• Define a relationship between object, if one object state is changed, the others will be notified
• Automation usage• Automated performance testing
Analyze patternsObserverUsage
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
Analyze patterns
StateUsage
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
Analyze patternsStrategyUsage
Our top:1. Façade – entry point2. Page object – grouping3. Simple factory – organized access 4. Singleton – one instance5. Observer - notification
Extended research
- GitHub: https://github.com/paulbodean88/automation-design-patterns
- Personal blog: www.atechnovel.com