All about Components - dn0000001/test-automation GitHub Wiki
What are Components?
To understand components, you need to understand the way developers think. Developers do not want to repeat tasks or copy/paste code. So, when you look at elements (components) on a web-page like a custom radio button, each of the different types of elements (components) will operate the same and have the same HTML structure. Why you ask because to not do the same task for every element (component) or copy/paste code, a developer will have written a single method for each different type of element (component). We can use the same philosophy to reduce/simplify the automation work by modeling these individual elements (components.)
How do Components work?
A component in the framework has a core element which comes from the locator. The purpose of the core element is to provide an anchor element to which if necessary relative elements can be located. A component in the framework has to implement the method init(). The purpose of the method init() is to initialize all the elements which will be called anytime by the proxy class.
Exposed Component Methods
- getData(DataTypes type, boolean resolveAliases) - Allows you to get the test data without binding the component.
- getLocator() - Allow you to get the locator for the component without binding the component.
- initializeData(String data, String initialData, String expectedData) - Allows manual initialization of the test data variables without binding the component. The data variable is the value to be set by the component. The initialData variable is the initial value of the test data. The initialData variable can be used to validate the default value for a component on the page. (Currently, no component uses the initialData variable.) The expectedData variables is the expected value after entering the test data. An example of this would be entering a value (1000) into a currency field in which the entered value is re-formatted ($1,000.00).
- setValue() - This method will use the test data to enter the value on the page.
- getValue() - This method will get current value of the component on the page.
- validateData(DataTypes validationMethod) - This method validates the current value of the component on the page to the specified test data.
Common Issues
The most common issue with a component is the locator is invalid for the component. This happens when the method init() needs to initialize elements that are relative to the core element which uses the locator. This manifests itself in many forms. The most common is either element could not be found or a null pointer exception. Another issue is using a component that does not match the functionality of the component on the page. A good indicator of this is the component cannot enter the test data.