Selenium Best Practices
Sowmya Sridharamurthy
Enabling engineering teams deliver value at scale |??International keynote speaker |?? writer | ? Accessibility Advocate |
1) Use page objects framework Whenever we mention about the best practices in selenium, Page object model will be the cream rising on top.
Having the page locators and page actions maintained in separate class grooms your code automatically and makes it hassle free.
2) Do not automate End to End NO !!! never think of running a code marathon,Keep your test simple and petite. Break it into logical units, achieving one goal at a time. Overcrowding your test with multiple assertions isn't a great idea though. pic courtesy: https://www.intelliware.com
3) Do not automate every test case: Automation is used to cover the regression scenarios to save time on redundant manual testing, the very idea of automating the new features even before the manual testing isn't recommended. Automation cannot compete with manual testing when it comes to creativity and number of bugs that can be reported. But of-course it reduces the redundant effort(that is what automation meant for). Always prioritise your test cases; before getting into actual coding. By doing so you will be clear on what should be achieved by when.
One should not set the goal of automating everything under the sun, its not a great idea for multiple reasons , good test cases for automation are the scenarios which require huge data or actions that needs to be performed multiple times.
4) DO not leverage on COPY-PASTE I have come across multiple instances when automation testers leverage the power of copy paste, do no copy paste same set of code in multiple locations. When there are certain actions which needs to be performed multiple times, its recommended to have a separate class/method and its reused by passing relevant parameters .Its good to have a Utility class which comes handy.
5) Inefficient coding practices = Bad testing practices In my team, we always had this hot topic for discussion "Difference between a good code and efficient code". Well, my definition would be a good code is the one which religiously follow structured coding, documentation, maintainability etc and an efficient code is good code+less number of code lines, runs faster, reliable, non-volatile store etc
We usually land up coding exactly the way we run the application manually, make sure you have optimised manual steps that goes into code, and you are well aware of what's going into the code.By doing so you are well aware of what is your target to achieve and what best possible way you can take to achieve it.
6) Cowboy mindset : Cowboy attitude basically means the programmer/s having autonomy over the coding practice.The attitude of "Lets do whatever we want"is the root cause of flaky code and frequent test failures.Ever since the agile process is followed in development teams the cowboy attitude of resolving things is masked under the name of agile. Have a well defined set of process for any task , stick to the process defined and this will help the whole team to be on track.
Having a well defined process and pathway to walk in-order to achieve the desired goal increases the probability of success.