NGABannerNew1.png

DETAILED READ SECTION

Design patterns for test automation frameworks

In this post QA Automation Engineers will understand most commonly used design pattern for test automation frameworks.


Lets first understand how poorly designed automation frameworks will lead to projects failures in long run.


A poorly designed architecture is a major reason why test automation frameworks fail. Engineers need to identify problems and adopt the right design patterns upfront. Common factors that result in bad design are:

  • Those implementing the work are new to or unfamiliar with test automation tactics.

  • The project’s timeline is strict.

  • The scale is unclear.

  • Engineers lack basic programming knowledge and, as a result, don’t use the right principles.

Design patterns: A better software testing technique and must take into consideration by every Automation Engineer.


Design patterns provide a general reusable solution for the common problems that occur in software design. Design patterns are like collections of best practices as they provide a concept but not particular implementations. Design patterns help reduce code complexity as well as make code more extensible, and maintainable.


Basically Design patterns are grouped into three categories:

  • Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.

  • Creational patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.

  • Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects.

In this post, I’ll go over the most popular structural, creational, and behavioral design patterns, outlining what they are, why they’re useful, and how to structure them.


Before diving into design patterns, it’s important to become familiar with SOLID principles that help make software design more understandable, flexible, and maintainable.

  • The Single Responsibility Principle - A class should have one, and only one reason to change.

  • The Open Closed Principle - You should be able to extend a class behavior without modifying it.

  • The Liskov Substitution Principle - Derived classes must be substitutable for its base classes.

  • The Interface Segregation Principle - Make fine grained interfaces that are client-specific.

  • The Dependency Inversion Principle - Depend on abstractions, not on concretions.

Structural design patterns


Page Object Models (POM)


What are they?


This is the most popular structural design pattern and is commonly used in building test automation frameworks to automate UI test cases. The pattern abstracts any page information away from the actual tests.


Why are they useful?


POM’s are beneficial because:

  • Developers don't need to write duplicate code. They create page components (e.g., input fields, buttons, etc.) which are used when building other page objects.

  • The pattern provides encapsulation and abstraction. Page objects encapsulate web elements, or other class members and provide access to wrapper methods that hide all the logic (i.e., the mechanics used to locate or change data).

  • Creating and organizing page objects makes it easier for developers to understand the structure of the automation solution via usage, new test creations, creation of new page components, and readability of tests.

How are they structured?


Page objects are like interfaces for web pages or web page components, also known as loadable components. These components support the same interaction with other web pages and should consist of:

  • preferably encapsulated web elements

  • other page objects

  • methods to operate with page object and return other page objects by design