Use Many Small Classes Instead of Few Large Ones
8 min readJun 27, 2021
One of the things that makes Selenium code better is having many small, single-purpose classes instead of fewer large, multiple purpose ones.
It is common for testers that just started Selenium automation to use utility classes as containers for many, unrelated common methods.
This leads to less duplicated code and shorter tests.
Unfortunately, this approach is not correct.
Let’s see an example.
I will use the following site to implement a test case: https://todomvc.com/examples/angularjs/#/
The test case is very simple:
- open the site
- wait until the page is loaded
- create an item by typing “one” in the text box and pressing the ENTER key
- create another item by typing “two” in the text box and pressing the ENTER key
- check that the item count is equal to 2
- select the first item
- select the second item
- check that the item count is equal to 0
The code that implements this test case is below:
import java.time.Duration;import org.openqa.selenium.By;
import…