Selenium Best Practices

*1. The code should use clear names*

Variables should have names that explain their purpose.
Methods should have names that either explain what the method does or the result returned by the method.

*2. Use problem domain names*

If you do automation for an e-commerce site, make sure that you have classes for concepts such as

- product
- user
- basket
- cart
- order
- invoice

*3. Classes should be small*

A class should contain an average of less than 30 methods.

*4. Methods should be small*

Methods should not have more than an average of 30 code lines.

*5. Do one Thing*

This applies to both classes and methods.
If a method does more than one thing, consider splitting it in 2.
If a class has more than one responsibility, consider breaking it in more classes.

*6. Don’t Repeat Yourself*

Any duplication, inside a page object class, a page method, a test class or a test method should be avoided.

*7. Explain yourself in code*

Write code that is self-explanatory, that is so easy to understand so no comments are needed.

*8. Make sure the code formatting is applied*

Code formatted correctly is easier to read by other developers.

*9. Use Exceptions rather than Return codes*

If a method cannot fulfill its purpose, instead of returning an obscure error code,
throw an exception since the code is in an abnormal state.

*10. Don’t return Null*

There are many ways of avoiding returning null.
You can use Optional introduced in Java 8.
Or you can return an empty list.

Connect - http://www.facebook.com/soni10.10
Connect Socially - https://harendersoni.blogspot.com

No comments:

Post a Comment

Add ur comment here!!!