Sample Excel Extension: TechnologyManager Class
This class extends the UITechnologyManager class and is responsible for providing core services for the Microsoft Excel extension. Although the base class has many methods, only a subset of them is used in this sample.
Some methods just return a property value. Many of the methods are intended to allow the developer to override default algorithms build into the coded UI test engine. These methods throw a NotSupportedException or return null, which tells the framework to use the default algorithm.
Depending on the complexity of the underlying technology, developing the technology manager code could take from a few weeks to a few months. Excel provides an opportunity to create a potentially very extensive technology manager. This example is intentionally limited to Excel worksheets and cells and uses limited formatting.
When it is possible, the technology manager code uses the .NET Remoting channel opened by the Communicator class to extract information from the Add-In running in the Excel process.
This override of the UITechnologyManager.TechnologyName property must provide a unique and meaningful name that identifies the underlying technology for every other component of the extension. For this extension, the value is "Excel".
This override of the UITechnologyManager.GetControlSupportLevel method returns a number that indicates the level of support that the technology manager can offer for the control represented by the provided handle. The higher the returned value, the more the technology manager can support the control. In this case, the method checks the window that contains the control and if it is an Excel Worksheet, the method returns the highest value; otherwise, it returns zero, which indicates that no support is provided.
Methods to Get an Element
There are several important methods that are used by the coded UI testing framework to get an element specific to the technology by providing a handle, a point on the screen, or an element from a different technology. The code for these methods are self-explanatory. The base methods are as follows:
When a coded UI test is created, the user can specify property values for some or all the controls in the test. These property values are used by the testing framework to create name-value pairs called search properties that are used to find specific UI controls during the test. All the search properties together represent the value of the UITechnologyElement.QueryId property of every element in the technology, which includes every control. Because a control might have to be found several times during a test, this method gives the technology manager a way to optimize parsing of search properties for the given control. This method also returns a cookie that the framework can use for subsequent searches for that control. This implementation of the method uses the AndCondition.Match method to parse the search properties.
To perform a control search by the technology manager, you can implement the UITechnologyManager.Search method to either return an array of possible matches, or throw the NotSupportedException, which tells the framework to use its own search algorithm. Either way, you must implement the MatchElement method where this implementation again uses the AndCondition.Match method.
These methods get the parent, children, or siblings of the provided element from the UI hierarchy. The code is simple and clearly commented.
GetExcelElement Internal Method
This internal method takes a window handle and information about an Excel element, and returns the requested Excel element.