QA Automation Technology

Design Patterns in Test Automation – A Quick Walkthrough

Design patterns

Design patterns are best practices that the programmer can adapt to enhance code reusability in a framework or solve common problems when designing a framework.

Automation testing is a process of testing software quality through scripts. Hence, the test design patterns are similar to software design development. Design patterns show how to design the test automation suite so that it will be efficient and easy to maintain. The most challenging part of creating automation framework has always been the code maintenance. 

A lot of test automation projects have been immersed or were scrapped due to the inability of the frameworks to cope up with the growing codebases or test suite. In order to keep the maintenance cost low, the automation engineers should strive to optimize the code that they reinvent or create from scratch by using best design techniques and code coverage of existing functionality for common, generic, or repeated operations.

The main benefits of leveraging design patterns in test automation is increasing 

  • Stability
  • Maintainability
  • Flexibility
  • Reliability
  • Clarity

All of them are important but different aspects can be reached by using different patterns.

WHAT ARE THE DIFFERENT TYPES OF TEST AUTOMATION FRAMEWORKS?

1. Design Patterns for the Test Implementation

From the test automation methodology perspective, different design patterns can be understood as types of automation frameworks.

S.NoDesign PatternDescription
1Recorded testsThe actions of the user are recorded by the automation tool. To execute the test, this recorded script is played back as it is.
2Modular testsModular tests require the creation of small, independent scripts that represent modules, sections and functionality of the AUT.
3Data-driven automation testsTest input and the expected output results are stored in a separate data file and a single driver script executes all the test cases with multiple sets of data.
4Keyword-driven automation testsThe test implementation is done through data tables and self-explanatory keywords. The keyword-driven testing is an extension to the data-driven testing.
5Hybrid test automationHybrid testing framework is the combination of data-driven and keyword-driven testing frameworks.
6Behaviour-driven testsTests are written in the form of simple text features descriptions in ubiquitous languages with scenarios typically written before anything else checked by the non-technical shareholders.

2. Functional Design Patterns

S. NoDesign Pattern
1Fluent pattern
2Singleton pattern
3Page Factory pattern
4Page Object Model pattern
5Facade pattern

Page Object Pattern

  • Page Object Element Map 
    • Contains properties of all web elements of the page and their locators
  • Page Object
    • Contains actions of the page
  • Page Object Validator
    • Contains validations/assertions on the page
  • Tests Class 
    • Contains a group of tests referencing the page objects, it can hold only a single instance of the page object.

Facade Design Pattern

  • Facade
    • Contains methods that combine actions executed on multiple pages
  • Page Objects (ItemPage)
    • Contains the actions that can be performed on the page like Search and Navigate. Exposes easy access to the Page Validator through the Validate() method. 
  • Page Object Element Map 
    • Contains properties of all web elements of the page and their locators
  • Page Object Validator
    • Contains validations/assertions on the page
  • Tests Class 
    • Contains group of tests referencing the facade, it can hold only a single instance of the facade.

Singleton Design Pattern

  • Page Objects (ItemPage)
    • Contains the actions that can be performed on the page like Search and Navigate. Exposes easy access to the Page Validator through the Validate() method. 
  • Page Object Element Map 
    • Contains properties of all web elements of the page and their locators
  • Base Page
    • Includes an instance to the child page’s validator class through the Validate method.
  • Base Singleton 
    • An abstract class that extends a static property of its child instance.

Fluent Page Object Design Pattern

  • Page Objects (ItemPage)
    • Contains the actions that can be performed on the page like Search and Navigate. Exposes easy access to the Page Validator through the Validate() method. 
  • Base Page
    • Grants access to the child’s page element map class and define a standard navigation operation.
  • Base Singleton 
    • Provides an abstract class that extends a static property of its child instance.
  • Base Page Validator
    • Provides child validators instance to the current element map and the page object itself.

What are the advantages of using Design Patterns?

The use of design patterns offers below advantages:

  • Low maintenance effort and time
  • Low maintenance cost
  • Enhanced code reusability
  • Enhanced reliability
  • Structured codebase which is easy to fix and extend
  • Improved communication

Conclusion

The test automation design patterns contribute to a major part in defining the test automation best practices. The benefits of test automation cannot be acquired effectively without implementing the required test design patterns specific to an automation framework project.

navdeep-rathore

QA Lead