I usually declare element locator static as well as the helper method using them, since element locators is a class variable or constant and is not dependent on a specific instance of class. For example in the following code snippet, element locators - imageElement and teamDeletionSucessMessage are static. Also, method - isTeamDeletionSucessMessageDisplayed is static -
- If you are writing utility classes and they are not supposed to be changed.
- If the method is not using any instance variable(s) or instance method(s). {some thing I consider most important when declaring a variable static}
- If any operation is not dependent on instance creation.
- If there is some code that can easily be shared by all the instance methods, extract that code into a static method.
- If you are sure that the definition of the method will never be changed or overridden. As static methods can not be overridden.
What is your take on this? Are your element locators also static (or even static final)?