Best way to improve our Automation script Quality
Every organisation is trying to deliver their product feature on fast and to do this they are following Agile model. To make success of Agile model they must automate their most of test cases so that they can reduce their manual work and to overcome that automation comes in existence.
In current QA industry Selenium web Driver has taken good place in market over the other tools. When we talk about selenium web Driver it opens option to use various languages for automation. But mostly we prefer Java because all the engineer have already studied it in their college life and its better organised and simplified language which gives them many benefits during implementation from the others.
But while we are automating our test cases we do some minor mistakes which decrease our code quality, here I am going to share some of them which I have collected from my experience.
For every project we have a team who is having multiple engineers who are coding for the same project, to organize their code we must have a common repository. There are multiple repositories in market but in this article, I will be mostly focusing on GitHub.
Before submitting code into repository its good practice to get it reviewed from peer and then push your code into Git local branch and create a pull request by CCing some of your developer and the person who is having good coding exposer, that they may suggest you some good ideas over your script and suggestion how to optimize your code in better way.
Below are the common minor mistakes ours QA members always do, that do not impact any functionality but yes reduce our coding quality.
- Always take care about camel case while you are defining your class, method, and variables names, below are few example-
- In class name make sure all the Words used their first letter is in upper case.
- While you are writing your method always write first letter of first word in lower case and rest of the words first letter in upper case.
- While you are creating any variable or object always write first letter of first word in lower case and rest of the words first letter in upper case.
- Always try to maintain the format of codes, you can do this in Eclipse as Ctrl + Shift + F, this will make your code more readable.
- Do not use calls that wait or sleep without taking into consideration the desired application state that you need before execution of the next statement.
- Do not use Thread.sleep() calls in your test case. If you need a DOM element to exist and be available for interaction use the standard design pattern for WebDriverWait and ExpectedCondition as follows:
- Do not create new instances of WebElement in your test case by using findByElement() and passing hard coded locator strings to locate the DOM element. Instead please refer to the appropriate member of the page object you are utilizing. If a member variable reflecting the DOM element you wish to manipulate does not exist on the page object then add it and declare it as an instance of the appropriate control in the test control framework.
- Follow the “don’t repeat yourself (DRY)” principle and avoid repeated blocks of code in your automated test case code. If you see a repeated code block please refactor it and either add a private method in your test suite or even better create a domain object and add the method there.
- Try to make it habit to add test case steps, author name before the tests in comment, so it will help people to understand what test case is for and if still they want to reach out to the person who is automated this they can refer author name.
Author : Nasim Akhter