A well structure design helps reduce the extra cost and conflicts; it also helps the team to work together better and achieve better results. We need to develop support libraries for re-usability and expandability of the code in our automation. We have to comment in scripts and function headers which will improve the readability and understand-ability of the structure.
A test automation framework is define as a real or conceptual structure; created to provide support which could expand in future. Test Automation framework is not a single process or tool. It’s a collection of tool and process working together to automate the manual process.
Note: Click here for Basics of Test Automation Framework blog where I have explained about the basics of framework.
Important points consider while Designing Test Automation Framework
- Handle Scripts and Data separately – Automated test scripts should be separated from input data files (eg – XML, Ms-Excel or Databases) and code, so that no modifications are needed to the test scripts whenever some data has to be changed.
- Library – Library should contain all reusable functions such as databases, generic functions, application functions etc. so that we have to just call the function rather than writing the whole code again and again.
- Coding Standards – Coding standards should always be maintained across your test automation framework, which will encourage individual coding practices and help in maintaining code structure, which makes it easier for others to understand the code.
- Extensibility and Maintenance – An ideal test automation framework should regularly support all new updation to the software application which allows modification. e.g. Some new library can be created, which would help in updating application features with less effort.
- Script/Framework Versioning – Versions of your Test Automation Framework / scripts should be maintain in a local repository or some versioning tool, which would help in easy checking of changes to the software code.
Goals for designing a Test Automation Framework
- The framework design should be easy to expand and maintain
- Provide abstraction from complexities
- Identification of the common functions used across scripts
- Separate complex logic functions with utility functions
- Separate test data and test scripts
- Creation of robust functions
- Appropriate functional break down which can be changed
- Ensure scripts are executed without human intervention, even in false conditions
- Improve Design documentation
Using Page Object Model in Test Automation Framework
You need classes that interact with the pages of your website. These classes should be within the framework layer. The most popular design pattern for creating these types of classes is the page object model (POM). This model recommends creating a separate class for each page of your website, (e.g. buttons, text fields, etc), as well as methods for interacting with those elements. You can use a browser automation tool, such as Selenium WebDriver, to handle the actual interaction.
Note: Click here to read about Page Object Model (POM).
now. Find out More
The role of Inheritance in Test Automation Framework
Inheritance, an object-oriented programming principle that enables objects to receive properties from a parent object, also has its place in your automation test code.
We have to always launch the browser for running our scripts. Rather than duplicating your code in every test method, you can use this functionality, and place into a method that runs before each test. To verify, this method does not get duplicate in every test class, place this method in a base test class from which all test classes inherit. The base page can also contain objects for other parts of the website that are visible from any page, such as navigation menus, headers, and footers. All of these would be inherit by any page, and therefore accessible without duplicating code.
Test runner tools, such as JUnit and TestNG, provide “before” annotations that you can use to denote methods that should run before the test. They also provide “after” annotations that you can use and can be inherit in the same way to clean up after tests.
How To Design a Test Automation Framework
Some points which should be consider while designing a framework:-
- Create Wrapper Method: Writing a wrapper method is one of the solutions for extending the library features. An example of extending the wrapper method is to allow better logging capabilities and handling the errors well in Selenium.
- Implement Custom Logger: While running the test script; all information should be logged into the file. This information can be use as a reference for understanding the code. The popular logging framework for java is log4j and python is Custom logger.
- Choosing the Right Design Pattern: Choosing the right design pattern speeds up the test case development and helps in preventing minor issues that can cause major problems and therefore improves code readability. The most popular design pattern for creating a selenium automation framework is the Page Object Model (POM).
- Separate Tests From Automation Framework: Separate the Test script logic and the input data from the automation framework. It increases code readability and makes the code readable.
- Create a Proper Folder Structure For The Code: Always define the folder structure which makes the code readable and makes it easy to understand. Eg – Test Cases, Utilities, Input Data etc.
- Build & Continuous Integration: Continuous Integration is a development practice that integrates with a build automation tool like Maven to ensure whether the software is running without any breaks after making a commit decision.
In case you have any queries then feel free to ask in the comment section below.
This is all about Designing of Test Automation Framework.
Thank you for reading this blog.