You might be wondering:
How professional Automation experts manage Test automation, What all are the Practices & Strategies that they follow for a great Test Automation framework to survive in long term without any hurdles?
In this blog,
I am going to reveal, some mandatory strategies to keep in mind while performing Test Automation on your project.
Are you excited?
Maybe, You are going to start the Test Automation project in your company but you are not confirmed what all are the best practices for Test Automation?
Choose the Right Test Automation Tool for Start.
Suppose, If you want to do Automation for a Microsoft PC Desktop app, choosing Selenium as automation tool is clearly not a good decision.
You should go with the AutoIT Tool.
Make sure you are clear with the advantages or disadvantages of that tool that you are going to use in Test Automation.
Do some POC and figure out early if it is handling your requirements or not.
“If there was one weapon he had against these savages, it was not acknowledging their existence.”
― Melina Marchetta, Finnikin of the Rock
Knowledge about the Other Test Automation tools and their pros and cons is must and You should avoid these naive mistakes while choosing Right tool for Automation.
- Research about the Automation Tool before Selecting
- Do some Proof of concepts and fail fast.
- let the team know about limitations of Automation Tool.
Sometimes by losing a battle you find a new way to win the war. — Donald Trump
Use Design patterns in Test Automation for the God sake
There is the famous quote
“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live”― John Woods
Click to Tweet
In the Test automation,
It is mandatory to code using well practices and pattern so that people can understand your code with minimum efforts.
“I’m not a great programmer; I’m just a good programmer with great habits.”
― Kent Beck
So you need to develop the good habits, and what are all Good habits in Test automation?
Learn to use Page Object Pattern if you have working with the Selenium.
Never ever code in Spaghetti pattern where every test cases is tightly coupled with the Other Test case.
People have a hard time understanding these kinds of patterns and it will lead a bad impression on your colleges or senior resources.
My favorite quote about coding it that -
“Truth can only be found in one place: the code.”
― Robert C. Martin
- Use Patterns in Test Automation
- Learn Clean Code — Amazing article by author on Clean code -
- Get your code Peer Reviewed time to time.
You Can’t ignore the Naming convention
There are few rules that we need to follow for a clean code while creating a Test automation
Use below Rules to choose the Name of the variable.
- Use camelCase.
- Avoid no meaning variables names
- Avoid keywords as variables names.
- If possible use a format for the variable name.
Extensive use of the parameters and Data-driven Testing.
Data-driven is probably the best Testing framework to introduce in the Test automation. It basically means that the input variables, data or parameters are fetched from separate files like CSV,JSON,XML,ADO objects, ODBC sources rather than hard-coding into the same test cases.
Do frequent refactoring whenever required for your test cases.
Refactoring means that changing the code to make it easier to understand without adding the extra functionality in the Test cases.
For your Test automation to succeed it is mandatory to refactor your code time to time
Implement Logs, screenshot, Reports like Professional.
If you are developing Test automation, Screenshot and logs are used for debugging purpose and Test Automation reports are best to share automation progress with the seniors or product owners.
Create custom wrappers for the utils or selenium methods for ease.
We should create some custom wrappers around utility methods provided by the automation framework such as Selenium.
These wrappers may not make sense for everyone or are not generic but they are very helpful for your project and hence makes your test automation great.
We have created Custom wrapper or function to scrollTo X,Y position with the element, This kind of function is used by our Test Cases many times.
It is created as a custom wrapper using the selenium internal methods.
Stabilizing the Tests — The Hard Part
Most of the time, test cases fail due to some environmental issues or configuration issues.
We need to make sure that the test cases should be stable as much as possible.
If they are the flaky test, We should move them to a different test suite.
Create unique & Meaningful — Test data
For the test automation framework to succeed it is important that the test data should be meaningful and it should be as close to the user's actions, behavior.
I have noticed that testers use some random data and due to that their test automation are not able to find bugs and so avoid this mistake.
Use Behaviour Driven Development whenever possible
Not everyone can understand you complex Automation framework test cases.
With the increased popularity of Cucumber(A famous BDD tool).
People are now moving to BDD framework for Test automation,
Where Test cases of in Test automation framework are written like normal language(like Given this then that) rather than complex structured programming code.
Include Alerts,Email Reports of Failure and flaky Test cases.
One of the important strategy or good Test automation is to have an alert system inbuilt.
This can be email or alert with Test report or a Report containing the number of Test cases failed per week/daily extra.
Avoid — Hardcoding input data or values.
Hard coding values for the input values is very dangerous,
I have seen people have hardcoded the passwords of the production server in the Automation framework or admin accounts credentials in the source code.
Please avoid this silly mistake.
Assign Default values
Clean code is an art, Always assign some default values to the variables in your Test automation code.
Not assigning default value is bad code practice and i have seen lots of Automation Test Cases failing due to the null checks extra due to this.
Use the Dry principle
In software engineering, don’t repeat yourself (DRY) is a principle of software development aimed at reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy.
Fail Fast and Do POC first.
Understand the business requirement and create 1 medium, 1 High-level Test case automation as POC and figure out early if Test automation framework is handling your requirements or not.
What do you thing?
Now I’d like to hear from you.
Maybe you have a question about something.
Want to Share Your Awesome Strategy of Test Automation.
Either way, let me know by leaving a comment below right now.
Learn about the Software Testing and Test automation in Discussion.
Recommend Book of Post
Lessons Learned in Software Testing: A Context-Driven Approach
Decades of software testing experience condensed into the most important lessons learned. The world’s leading software testing experts lend you their wisdom and years of experience to help you avoid the most common mistakes in testing software. Each lesson is an assertion related to software testing, followed by an explanation or example that shows you the how, when, and why of the testing lesson. More than just tips, tricks, and pitfalls to avoid.
Originally published at https://scrolltest.com/2019/01/05/best-practices-test-automation/