FindParams as External XML Data Sources
Note: This topics assumes a basic understanding of FindParam objects. It is recommended to read the Finding Page Elements topic first before reading this topic.
FindParam's provide a consistent and streamlined approach to describing an element within a markup DOM. They also allow us to encapsulate all the information pertaining to how an element should be located on the page within one object.
The information FindParams contain is usually very specific to the web application's UI and DOM. If we desire to keep our test code logic abstract and independent from trivial UI changes that the application might undergo, we ought to keep this information stored in FindParams as abstracted and external to the test code as possible. With Telerik FindParam and FindParamCollection objects support XML Serialization. This feature allow us to extract out all information contained in FindParams or FindParamCollections to external Xml data sources and consume them when needed without having to hard code specific application information into our test logic:
By doing so we can:
Avoid recompilation of test code each time UI/DOM changes are made. Given that the specifics of the web application are stored externally, we can simply edit these external sources to update any information regarding UI or DOM changes.
Enable the same test logic/code to run against different versions of the same application that differ in UI layout or DOM structure. By versioning the external data sources per each different application version, we can configure our tests to consume different data source versions for each application being tested without having to duplicate test code and worry about maintaining multiple code bases. This approach can dramatically cut down maintenance and support costs especially for product teams that maintain and service multiple versions of the same application. It is also a great approach to take on if you are starting a new project and you think you will end up having to support multiple versions of that product in the future.
Building FindParam Data Sources
We currently don't offer any UI design tools that can help build these data sources directly from your application. Therefore, to build these data source we need to craft our FindParams manually and then using FindParam and FindParamCollection XML serialization methods, store the generated sources to our storage medium of choice (i.e. database, file system ...etc). The sample below shows an example of how to build an XML file that can be later consumed by your test code to identify elements to use in the automation logic.
Consuming the Data Sources
The are three different methods you can use to consume the data source generated above. We can deserialize the data back into a FindParamCollection object and then select one of these FindParams to locate a specific element on the page.
Alternatively we can can create a Dictionary lookup object from the external datasource.
Finally we can load the external datasource using a FindParamAttribute.
Managing and Organizing Data Sources for an Entire Application
There are probably many ways you can think of to organize your external data sources for your an entire application. We though want to discuss three approaches you might want to consider. You can organize your external sources:
Per Page: With this approach you build a data source (i.e. an xml file) for each page within your application and then load it using the Find.FromXX() methods.
Per TestRegion: With this approach you build a data source per each region defined within your application. You can then load and find your elements using the TestRegion.Find.FromXX() methods.
Per Entire Application: With this approach you build one data source that represents your entire application. Many users might prefer this approach given that they only have to manage one file or data source for the entire application. Depending on the size of the application and how the application segments logically, this might or might not be good approach to take. If the application is huge, we recommend you break down your data source's into smaller ones. If your application is relatively small, then one datasource might be more efficient way to go.