Task: teach how to find cmdlets for your tests.
Task #2: provide a task to practise.
Requirements: provide examples on how to find cmdlets.
Solution: most of questions from the people who started working with the UIAutomation module are about how to get a control and how to deal with it. In other words, better to say: in terms of the UIAutomation module, Get- cmdlets and Invoke- cmdlets.
In UI Automation, there are several important properties of a control:
– AutomationID (it can be a name of a control, usually the Name property as it seen in SharpDevelop or Visual Studio. Though, sometimes it can be generated by the application)
– Class (ClassName in terms of MS UI Automation. This property is platform-dependent and hardly recommended for use)
– Name (usually the Text property in your IDE. Therefore, should be used not with an every control. For example, there’s no much sense to use the Name property with a Text Box, since this property is subject to change during the test)
– ControlType (even this can be platform-dependent: compare the grid in services.msc (DataGrid in Windows XP) and services.msc (List in Windows 7). The same thing has been observed for Common Controls on Windows 2000 and Windows XP many years ago, by means of other tools)
The UIAutomation PowerShell framework is built in a way that you’ll be needing rarely in setting the last property, the ControlType. This is done, in most situations, automatically by aliasing. That means that
Get-UIATextBox -a UserNameBox
is the same as
Get-UIAControl -ControlType Edit -a UserNameBox
Furthermore, TextBox, LinkLabel, GroupBox are also aliases to the UI Automation’s Edit, Hyperlink, Group. This is done for achieving two purposes:
– simplifying the search across the cmdlets
– readability of the code
How to find the cmdlets, the topic of a post? Consider the following piece of code:
Get-Command -Module uia* *textbox*
This command returns several cmdlets that are intended to be used with a textbox.
If you need an action that you can perform to a control, run something like this:
Get-Command -Module uia* *click*
This command returns all the cmdlets that can perform a click.
Note: the list of actions (patterns) you may use with controls can be seen here: http://msdn.microsoft.com/en-us/library/ms752362.aspx
Note: not every control supports a pattern even if it is in the list http://msdn.microsoft.com/en-us/library/ms750574.aspx. It depends even on properties the developer set to a control. AccessibilityRole, for instance. If control does not support a pattern, the cmdlet returns an exception. It also may depends on a time of day:), I mean the time when a control is in one state when the pattern is supported, and other time the control can be in somewhat other state, and the pattern may not be supported.
Note: there are several ways to find out which patterns are supported by the control right now:
– enum currently supported patterns
(Get-UIAWindow -p mmc | Get-UIADataGrid).GetSupportedPatterns()
– use UIA Verify 1.0 or 2.0 (the first has a problem with hovering, the latter does show less patternt than the first). The link to the project: http://uiautomationverify.codeplex.com/
– use the script recorder with the parameter -WriteCurrentPattern (it’s very likely that the parameter will be renamed in the next version, and the recorder itself is a subject of near-future rewriting. Nonetheless, you can play it around right now).
Homework: find the cmdlets that are targeted to work with Tab, TabItem (both control can be found in the MMC), Button. Try to find appropriate patterns (Invoke- cmdlets) and perform actions with the controls.