In my project, I faced the problem that the automation regression scripts took a long time to finish. The big products took about 1 or 2 days, the smallest one took about 1 hour to finish (there are so many cases comparing with the database, get API, write to file excel etc…). The framework was developed by the old team, it was not stable, usually running failed, didn’t follow any coding convention or best practice. So when we have inherited it, we must do below actions:
- Define Definition of Done (DOD) when scripting a new test cases
- Define Coding Convention and follow strictly
- Refactor and Clean Code the framework and the test scripts: after reviewing the source code and analyzing it and many things were applied to this step:
- Apply new structure for the new framework to make it stable
- Single responsibility principle applies to a class
- Separate the long methods following the coding convention
- Apply design pattern to the framework
- Remove string concat by string interpolation
- Remove the implicit wait, replace by the explicit wait
- Apply SoftAssert and GroupAssert
- Remove unused classes
- Optimized all classes
- Avoid to using xPath locators with index value
- Refactor core for webdriver
- Return the empty list instead of null
- Move methods from test class to page class
etc…
There are so many things need refactor the framework and test scripts. Above lines are just the highlight
- Weekly code review in our team
- Cross review code each other
- Read and review the checks of test cases to make sure there are no necessary steps in test scripts
- Apply dynamic data to reduce the investigate for out of date data: As you know, all automation scripts have data-driven. The data will be expired on websites or in database or API, and the scripting QA should update them by manual (searching, query, update to data-driven files). My team created a Dynamic Data project to make it automatically, just one click all new data will be generated and created. And we can run the automation scripts again with the newest data
- Add option to turn on/off logging
- Remove unused log code
etc…
And there are some more steps to increase the performance of our framework and test scripts. After 3 months, the performance was increased so much, about half of the execution time was reduced. The biggest product was reduced from 2 days to 5 hours of execution time, and the smallest one is just 30 minutes now