Does anyone write unit tests for page objects and related UI test infrastructure? If so, what suggestions do you have for designing those unit tests? Do you mock WebDriver instances, or take another approach?
Background: I realize this is a mind-bending question for some people. “Test the tests?” No, I’m not talking about testing tests. I’m talking about testing domain objects and test framework code that tests use. Consider this typical technology stack for a well architected UI test:
- Test cases
- Domain objects - page objects in the case of Selenium, or a DSL, or generic classes in the case of non-UI tests
- Test framework - xUnit, PyTest, TestNG, etc.
- Language libraries, including assertion handling
- OS code, way down at the bottom
People write unit tests for all these layers except the tests themselves. Good developers write unit tests for the domain objects they create. And one type of domain object - in the case of Selenium UI test suites - is page objects. I know some people unit test these classes, but I haven’t seen any good articles about it.
Do you have experience testing at this layer for UI tests that use the Selenium toolset? If so, I’d love to hear your experience about whether you use general mocking tools (PyTest MagicMock or Java Mockito, for example) or use built-in Selenium tricks.