Automation Architecture Design Pattern

Amarendra Singh
7 min readDec 12, 2019

--

What is Architecture in general?

Architecture is the process of planning, designing and constructing a building or any other structures. For an automation testing project, architecture is as important as it is for constructing a building. The best architecture design is one that won’t cost much but will continue to drive the economic flow. Designing and building architecture takes time, money, and collaboration.

In this blog, we will focus on the high-level architecture of the Selenium framework. We will provide you an insight through the steps to be followed and core components required to build a strong framework for your Selenium project.

What is a Selenium automation framework?

A Selenium automation framework is a platform that can be developed by integrating various tools and services to efficiently design and develop automated test scripts.

Selenium is the most favorite tool among testers when coming to automation testing because of the benefits it provides. Selenium is an open-source tool and provides support for multiple languages and browsers. It can be integrated into other third-party tools as well. But “Selenium alone does not fulfill the needs of the best framework.”

The biggest challenge in developing a framework is to identify the tools and resources that best suites our needs to build a reliable framework that can be maintained easily with changing requirements.

Steps to create a Selenium Automation Framework:

We can build a real automation framework that we can utilize without worrying about technology. We perform black-box automation testing with Selenium because of the regression tests that need to be executed again and again. So, here are the steps listed to create a good automation framework for the Selenium project.

  1. Choosing the right set of tools
  2. Building the components required for application functionality
  3. Implementing CI/CD

Choosing the right set of tools:

Choosing the right combination of tools that best suits your project requirement is the foremost task in designing a framework. The right set of tools is a combination of programming language and Unit test framework. Depending upon the core technology your application is developed in the choice of programming language to write test script can be made.

As most of the applications, these days are developed in Java or C#. So, these languages are the most popular languages among the Selenium testers and are the safest choices to be made so that testers can get all the required online support for tutorials as well as code snippets.

Depending upon the choice of language of the tester, the unit test framework can be chosen.

1. Java as a Programming language: TestNG is the Next Generation unit testing framework that is used by testers for writing selenium test cases with Java as the programming language. It is inspired from JUnit in using the annotations and is more powerful than JUnit. TestNG provides additional advantages over Junit.

a) Default Selenium tests do not generate the properly formatted report but with TestNG, the properly formatted report can be generated displaying the number of test cases that are passed, failed or skipped.

b) The same tests can be executed multiple numbers of times

c) Easy integration with other tools like Maven, Jenkins, etc.

2. C# as a Programming language: NUnit is the unit test framework in .NET that can be used to write the test script for C#. Although NUnit is not as powerful and flexible in use as TestNG if our choice of language is C# then we would use NUnit framework.

Just because of the advantages of TestNG over other unit testing frameworks we have chosen Java with TestNG as our set of tools to describe the architecture in detail.

Building the components required for application functionality:

To build the application core functionality components, the POM (Page Object Model) is the best model to follow. To implement POM in your project you should learn how to manage the core components in the folder structure.

POM is the basic building block in test automation frameworks because it reduces duplication of code as you will organize your code into Page Objects which in result reduces the test maintenance cost.

Here are the important steps that are listed to build the core components of the framework: -

Selenium Core components are designed to manage the browser instances as well as element interactions. To achieve this purpose and manage the functionality you should create folders inside your project and name them as Main and Test. The main folder could be further segregated into 3 folders — Base, Pages, and Utility.

a) Base Folder — Base folder contains the Base class. The Base class is a collection of all those methods that would be called once inside the entire script. The Base class contains the functionality of browser instances, implicit wait, deletion of cookies.

b) Pages Folder — There would be one class for every page of the application. So, as many pages are there in the application as many classes would be created under this folder. For example, my application has several pages like Login, Logout, Dashboard, Documents page, etc.

Each page has different actions that you perform on the elements of the page. Each class will contain different methods depending on the core functionality of the respective page. Every class is a combination of element locators to locate all the web elements on the page and methods that contain the actions to be performed on those elements.

c) Utility Folder — This folder contains all custom methods like wait, screenshot, scroll, etc. You can directly call these methods anywhere you required in the script without creating again and again.

  • The test folder could be organized in further folders as follows:

a) Config folder — Every application runs on a specific configuration and every user is provided with a different authentication. All these fields need to be provided from some external source so that if the script is to run with a different configuration, the code need not be touched and configuration variables like browser, username, and password, etc. fields can be changed easily. To achieve this purpose, you need to create a config file under this folder to store all the configuration variables.

b) Test folder — All the test cases need to be in a different test class. There can be more than one class for the TestNG test cases as per the convenience of the tester.

c) Test Data folder — Designing, managing and storing the test data is itself a tedious task. Managing the test data means separating the test data from the test script. You need to store the data centrally for easy access. Test data could be either a PDF document, an image file or an excel file containing some registration information, etc. All these test data would be stored in this folder.

d) Logs folder — Logs folder contain all the custom as well as the application logs file.

e) Test Controller folder — The controller folder contains those files that help to execute multiple test cases parallel at the same time.

f) Reports folder — The reports folder contains all types of reports that are generating on executing the automation script like “TestNG HTML Reports”, “Extent Reports”. Users can easily check reports from this folder.

The POM makes the life of a tester easier by making the code maintenance easier. If there happens to be any change in the functionality of any page, it can be easily located, and changes can be made effortlessly.

Implementing CI/CD:

Selenium can be easily integrated with other tools to provide Continuous Integration and Continuous Deployment functionality. It can be integrated into various tools like Maven, Jenkins GitHub, etc.

Maven is a powerful project management tool based on the concept of a POM.

GitHub is a repository where developer/QA store their projects and code for other people to use and take benefit from them. Git is a version control system. When developer/QA create an application, continuous changes are being made to the code and new versions are released and store that code at a centralized location. This allows developers/QA to collaborate easily, as they can download a new version of the software, make changes, and upload the newest revision. Every developer/QA can see these new changes, download them, and contribute.

Jenkins is a continuous integration tool which allows Selenium tests to run every time your software changes and deploy the software to a new environment when the tests pass. Jenkins can also schedule your tests to run at a specific time and save the execution history and Test Reports.

Conclusion:

Selenium is a powerful tool to perform functional and regression testing. A strong foundation is required to build a stable project which can be provided by good architecture. A selenium project with good architecture is easy to maintain.

Hope you have learned to create the architecture with my blog. If you like my blog, click on the like icon. Feel free to post your queries on the same and stay tuned for more tutorials on Selenium.

--

--

Amarendra Singh

Consultant Software Quality Assurance | Selenium | C# | Cypress | API Automation