Summary
In this chapter, we wrote a custom wrapper to select an item from a list element. We learned how to handle two separate types of objects with a single method, reducing test case code. The combobox path uses the click()
method to open and navigate through a list, as well as clear the input field that filters matches in the list. We embedded reporting if no exact or close match exists, making debugging easier. This was done by sending a log error message, indicating what item was sought, the list element it was using, and the list of non-matching values. We also showed how to use SelectorsHub
to provide a way to validate handwritten XPath selectors when the list closes, as soon as the object loses focus.
This completes three of the four most common methods used in test automation. In the next chapter, we will create an enhanced Assertion
method that validates the state or text of an object, as well as validating generic text that appears on a page.