Calling page object methods in test classes
One of the most common mistakes users make when building automated tests is to build low-level event processing into their test class methods. We have been using the Selenium POM in this framework design, and what that means for the test classes is that you want to call the page object methods from within the test class methods, but not access the WebElements themselves. The goal is to reduce the amount of code being written and create a "library" of common methods that can be called in many places!
Now, what can be done in the framework to restrict users from going off track?
Users can set the scope of all WebElements defined in the page object classes to protected
. That allows subclasses to access them, but prevents users from accessing the WebElements directly in the test methods, after instantiating the class.
Getter/setter methods can be built in the page object classes for cases where the user needs to get the WebElement to clean up a test ...