The question "How do we know that the user or the test clicked?" can be answered easily. The answer is InvokedEvent.
For example, we need to know which numeric button of calc.exe have been clicked, and the number of click performed (a completely imaginary task):
[int]$global:clickCount = 0;
[string]$global:lastClickedButton;

Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -n [1-9] | Register-UIAInvokedEvent -EventAction { $global:clickCount++; },{ param($src, $e) $global:lastClickedButton = $src.Current.Name; }; 
# the delay may be needed
sleep -Seconds 1;
Get-UIAButton -Name [1-9] | Invoke-UIAButtonClick;
# this delay is usually needed as events are relatively slow to be fired
sleep -Seconds 1;

# check the result
$global:clickCount
$global:lastClickedButton
The following example demonstrates how to create a simple custom log for clicks:
# use the Get-UIAControlDescendants cmdlet to collect all the visible buttons
# use the Register-UIAInvokedEvent cmdlet to assign an event action to each button
Start-Process calc -PassThru | `
Get-UIAWindow | `
Get-UIAControlDescendants -ControlType Button | `
Register-UIAInvokedEvent -EventAction {param($src) "$($src.Current.Name) clicked" >> $env:TEMP\calc.log;}

Tags: ControlType.Window, ControlType.Button, InvokePattern, InvokedEvent

Last edited Jan 19, 2013 at 4:43 PM by xinliu, version 6

Comments

No comments yet.