Before you start building any automation framework, there are set of guidelines which should be followed to build a highly reliable, scalable and maintainable framework. Some of the best practices are listed below:
1. Define the scope of automation
It is impossible to achieve 100% test automation, so it is important to determine which test cases can be automated and which cannot be automated.
Below test cases should be considered for automation:
– Tests which need to be run repeatedly for every build.
– Tests which take a lot of time if performed manually.
– Tests which can cause human error.
– Tests which require multiple sets of test data.
– Tests which need to be run on different platforms like operating systems or browsers.
2. Select the right test automation tool
It is important to select the right tool for your test automation, as there are many tools available in the market which may suite different kind of applications. Below are some recommendations for choosing the right tool:
– Budget: Consider the amount of budget allocated to your project before choosing your tool. There are many popular open source automation tools like Selenium which can be used for UI Automation.
– Feasibility: Consider whether the system requirements of the automation tool match with that of the application.
– Proof of concept: Determine the capabilities of the automation tool by doing a POC on frequently used functionalities.
– Identification: Determine whether tool is able to identify all UI elements of the application.
– Ease of use: Determine the complexity of the tool, whether it is easy to learn and implement without any extensive training.
– Framework: Determine whether tool already has an inbuilt framework which can be used by the team while developing the automated tests.
3. Build an independent framework
– Framework should not be dependent on any particular test or application.
– Framework should be capable to handle any kind of application or tests.
– Framework can be reused for multiple applications with minimal changes.
4. Always use test design patterns and principles
Design principles provide you with guidelines or rules that you need to follow for constructing well built and maintainable software.
– Page Object Model can be used to maintain your objects/elements efficiently across your application when you are working with automation tools like Selenium which does not provide an object repository.
– Java design patterns like Singleton pattern can be used in Selenium automation frameworks where you need to ensure that only one instance of a browser object exists at a time.
5. Configure all your properties
– Configure all framework properties in properties file which will be extracted and provided to the framework at run time.
– Configure all application properties in properties file which will be extracted and provided to the framework at run time.
– Configure all user properties like usernames, passwords, Database connections in properties file which will be extracted and provided to the framework at run time.
– Passwords should be stored in encrypted format and these files should not be checked in on to a code repository.
6. Extensive Reporting & Logging
– Use different reporting plugins to automatically create test reports in different formats.
– Use different automation tool methods to enable the framework to automatically take screenshots during test failures.
– Use logging frameworks like log4j to provide logging at run time which will make it easier for debugging purpose.
7. Enable Parallel Execution and Multithreading
– Use any test frameworks like TestNG to enable running multiple tests in parallel with multiple threads. This is particularly useful when the test suite contains thousands of tests and take a long time to complete execution.
8. Enable Automatic Execution
– Integrate your framework with different CI tools like Maven and Jenkins to automatically trigger your test execution at a given schedule.
– Use windows scheduler to automatically trigger the test execution.
9. Follow coding best practises
– Always follow coding best practices and standard naming conventions for your classes/methods irrespective of the coding language.
10. Enable documentation
– Always provide proper comments or documentation for each method or class which is written in the framework.
– Use plugins like JavaDoc to produce java documentation for all your classes in the framework.