Task: select a service in the Services MMC snap-in (Windows XP). For the service selected, call its context menu and start the service. After that, stop the service through the context menu.
Task #2: provide a field for learning the module.
Requirements: just do it. The test should be repeatable.
Solution: run the following code:
Get-UIAWindow -Name 'Services' | ` Get-UIADataGrid | ` Get-UIADataItem -Name 'Alerter' | ` Invoke-UIAControlContextMenu | ` Get-UIAMenuItem -Name 'Start' | ` Invoke-UIAMenuItemClick;
In the code snippet above, we get the window by name, get the grid (it does no matter, the Standard view is selected or the Extended one. However, this code uses a Win32 click (any cmdlet without a control type in the name may be a Win32-based cmdlet), which is sent to a geometrical center of the control), select a data item (the row) and perform a Win32 right-click. The click returns the window object (context menu is an independent window in the application process), where the last two cmdlets recognize and activate the menu item we’ve been tasked to click.
It’s a must for a tester to use after this code something with Get-Service or WMI to check that the service is started and so on.
After the test marked as Passed, the following code helps us to stop the service:
Get-UIAWindow -Name 'Services' | ` Get-UIADataGrid | ` Get-UIADataItem -Name 'Alerter' | ` Invoke-UIAControlContextMenu | ` Get-UIAMenuItem -Name 'Stop' | ` Invoke-UIAMenuItemClick;
As a Homework, please open the Properties window of a service you chose.