2 Reference - essenius/FitNesseFitSharpUiAutomation GitHub Wiki

Locators

Many of the functions use a search criterion to locate the control they act on. This criterion takes the form method:criterion. You can also specify a default method (Name, if not overridden via a Search By command), and then only use the criterion. The available methods are shown in the table below.

Search Method Explanation
AccessKey The access key character for the control
ClassName The class name of the control
ControlType Type of control, e.g. Button, TreeItem, Text, Document
HelpText The help text string
Id Automation ID property of the control
IsEnabled Whether the control is enabled
IsPassword Whether the control contains protected content
Name
Caption
Name property of the control (which is usually the caption as well)
ProcessId process ID (only relevant for windows)
WindowHandle Native window handle

A default is taken if no method is specified. Unless Search By is used, the default is Name. If you only specify a colon, everything will match. Should you want to use a criterion with a colon in it, then explicitly use the search method.

You can also use more than one locator in a search; they will then be both applied (logical ‘and’). To separate locators use a double ampersand surrounded by two spaces (&&).

Examples:

Command Meaning
| Select Item | id:MainTab | Selects an item with the Automation ID MainTab
| Click Control | Cancel | Click the control named Cancel (default=Name).
| Search By | Id | Set default search method to Id
| Select Item | MainTab | Select the item with the automation ID MainTab
| Check | Control Exists | Name:Note: | Looks for a control named Note:
| Click Control | ControlType:Button && Name:OK | Look for a Button control named OK.

Script Fixture: UI Automation Fixture

Application Is Active
Description: Return whether the application under test is active
In: -
Out: active? (true/false)
Example(s): | ensure | Application Is Active |
Application Process Id
Description: Return the process Id of the active application under test
In: -
Out: Process ID
Example(s): | $id= | Application Process Id |
Cell In Control Containing
Description: Get the location specification of the first cell in a grid that contains a value
In: grid control search criterion, value to search for in the grid
Out: cell specification (row:x, column:y) or null if the control is not a grid or the value is not found
Example(s): | $spec= | Cell In Control | myGrid | containing | hello |
Click Control
Description: Click a clickable control (e.g. Button)
In: search criterion
Out: succeeded? (true/ false)
Example(s): | Click Control | Add |
| Click Control | Id:143 |
Close Application
Description: Close a running application. It does so by closing the main window.
It does not force a close if warnings or notifications pop up (e.g. “are you sure?”)
In: -
Out: whether or not the application could be closed (true/false)
Example(s): | Close Application |
Collapse Control
Description: Expand a collapsible control (e.g. TreeItem)
In: search criterion
Out: whether the collapse succeeded ( true/ false)
Example(s): | Collapse Control | Id:TreeView1 |
Column Count Of Control
Description: Returns the number of columns in a grid control
In: search criterion
Out: the number of columns in the control (int)
Example(s): | Check | Column Count Of Control | Name:myGrid | 4 |
Control Exists
Description: Returns whether a certain control exists.
In: search criterion
Out: whether the control is present (true/ false)
Example(s): | Control | Sine | Exists |
| Control | ControlType:Slider | Exists |
Control Is Visible
Description: Returns whether a certain control is visible.
In: search criterion
Out: whether the control is visible (true/ false)
Example(s): | Control | Warning | Is Visible |
| Control | Name:Subtract | Is Visible |
Double Click Control
Description: Double click a control (via mouse emulation)
In: search criterion
Out: success? (true/ false)
Example(s): | Double Click Control | TextItem |
Drag Control
Description: Drag the mouse from a control. Pair with Drop On Control
In: drag control search criterion
Out: whether the drag/drop succeeded (true/ false)
Example(s): | Drag Control | id:DragFrom |
Drag Control And Drop On Control
Description: Drag the mouse from a control and drop onto another control
In: drag control search criterion, drop control search criterion
Out: whether the drag/drop succeeded (true/ false)
Example(s): | Drag Control | id:DragFrom | And Drop On Control | id:DropTo |
Drop On Control
Description: Drop a dragged control onto another one. Pair with Drag Control
In: drag control search criterion
Out: whether the drag/drop succeeded (true/ false)
Example(s): | Drop On Control | id:DropTo |
Expand Control
Description: Expand an expandable control (e.g. TreeItem)
In: search criterion
Out: success? (true/ false)
Example(s): | Expand Control | Id:TreeView1 |
First Text Under
Description: Return the content of the first text control under the current control. Useful for UWP apps
In: search criterion
Out: success? (true/ false)
Example(s): | Expand Control | Id:TreeView1 |
Forced Close Application
Description: Close a running application by closing the main window.
If the close does not succeed, it will try and kill the process (i.e. forced close).
In: -
Out: true
Example(s): | Forced Close Application |
Is UWP App
Description: Returns whether the current application is an UWP app
In: -
Out: UWP App? (true/ false)
Example(s): | ensure | Is UWP App |
Maximize Window
Description: Maximize the window of the system under test
In: -
Out: success? (true/ false)
Example(s): | Maximize Window |
Minimize Window
Description: Minimize the window of the system under test
In: -
Out: success? (true/ false)
Example(s): | Minimize Window |
Move Window To
Description: Move the window such that the top left position becomes the specified coordinate
In: X, Y coordinates
Out: Success? (true/false)
Example(s): | Move Window to | 20, 30 |
Name Of Control
Description: Return the name of a control
In: search criterion
Out: its name
Example(s): | $name= | name of control |
No Automatic Switch To Application
Description: If an application gets started, no automatic switch to the application window will be attempted.
This will then need to be done manually with a Switch To Window command.
In: -
Out: -
Example(s): | No Automatic Switch To Application |
Normal Window
Description: ‘Restore’ the window of the system under test
In: -
Out: success? (true/ false)
Example(s): | Normal Window |
Press Key
Description: Use the SendKeys.SendWait method to simulate keypresses. For more details on formats see http://msdn.microsoft.com/en-us/library/vstudio/system.windows.forms.sendkeys(v=vs.100).aspx
In: key to press
Out: whether or not the keys could be pressed
Example(s): | Press Key | ^{F4} |
Property Of Control
Description: Return a property of a control
In: property name, search criterion
Out: the property value
Example(s): | $className= | Property | ClassName | of control | myControl |
Resize Window To
Description: Resize a window to a certain width and height. Format: width, height
In: coordinate (x,y)
Out: success? (true/false)
Example(s): | Resize Window to | 1024,768 |
Row Count Of Control
Description: Returns the number of rows in a grid control
In: search criterion
Out: the number of rows in the control (int)
Example(s): | Check | Row Count Of Control | myGrid | 7 |
Search By
Description: Sets the default search method. If this command is not called, Name will be assumed.
In: search method
Out: success? (true/false)
Example(s): | Search By | Name |
Selected Cell In Control
Description: Get the row and column of the selected cell in a control.
If multiple cells are selected, it returns the first only
In: grid control search criterion
Out: coordinates of the selected cell
Example(s): | $cell= | Selected Cell In Control |
Select Item
Description: Select a selectable item (e.g. RadioButton, Tab)
In: search criterion
Out: whether the selection succeeded (true/ false)
Example(s): | Select Item | RadioButton1 |<br/>| Select Item | Name:Work Items Tab |
Set Automatic Switch To Application
Description: Enable automatic switching to an application that gets started (default setting)
In: -
Out: -
Example(s): | Set Automatic Switch To Application |
Set Focus To Control
Description: Set the focus to a control
In: search criterion
Out: success? (true/false)
Example(s): | $name= | name of control |
Set Value Of Control To
Description: Set the value of a control. Tries to use an appropriate method based on the control type.
In: search criterion, value to set
Out: the value (string)
Example(s): | Set Value Of Control | Id:ApplicationListBox | To | FitNesse |
| Set Value Of Control | myTextBox | To | The quick brown fox |
| Set Value Of Control | slider1 | To | 23 |
Snapshot Object Of Control
Description: Take a snapshot of a control on the screen and return it as a Snapshot object
In: search criterion, value to set
Out: the value (string)
Example(s): | $snapshot= | snapshot object of control | Result |
Snapshot Of Control
Description: Take a snapshot of a control on the screen and render it as an HTML base 64 image.
In: search criterion, value to set
Out: the value (string)
Example(s): | show | snapshot of control | Result |
Start Application [With Arguments] [With Working Folder] [With Arguments And Working Folder]
Description: Start an executable application, optionally with a working folder and/or arguments
In: path to the executable including the application name [, command line arguments] [, path to the working folder]
Out: success? (true/false)
Example(s): | Start Application | C:\Windows\System32\Calc.exe |
| Start Application | notepad.exe | with arguments | test.txt |
| Start Application | notepad.exe | with working folder | c:\temp |
Note: Set/No Automatic Switch To Application defines whether a switch to the application will be attempted.
Switch To Parent Window
Description: Switch to the parent window of the current app (useful for UWP apps)
In: search criterion
Out: success? (true/false)
Example(s): | Ensure | Switch to Parent Window |
Switch To Process
Description: Switch to a process (using either ProcessId or Name)
In: search criterion
Out: success? (true/false)
Example(s): | Ensure | Switch to Parent Window |
Timeout Seconds (property)
Description: Set/get the default timeout for all wait commands. Default value is 3 seconds.
Max is 3600 * 24 * 24 (i.e. 24 days)
In: timeout value in seconds (set)
Out: timeout value in seconds (get)
Example(s): | set timeout | 20 | seconds |
Toggle Control
Description: Toggles the value of a control.
In: search criterion
Out: whether or not the control could be toggled (true/false)
Example(s): | Toggle Control | CheckBox1 |
| Toggle Control | Id:354 |
UWP Apps Are Supported
Description: Returns whether the platform supports UWP apps
In: -
Out: whether UWP apps are supported (true/ false)
Example(s): | ensure | UWP apps are supported |
Value Of Control
Description: Returns the value of a control. Tries to return an appropriate value based on the control type.
In: search criterion
Out: the value (string)
Example(s): | Check | Value Of Control | Id:textAnswer | 30 |
| Check | Value Of Control | Result | ~=0.45990349 |
Wait For Control
Description: Waits for a control to be present.
In: search criterion
Out: control was found before the timeout? (true/false)
Example(s): | Wait For Control | Radians |
| Wait For Control | Id:304 |
Wait For Control And Click
Description: Waits for a control to appear, and then clicks it.
In: search criterion
Out: success? (true/false)
Example(s): | Wait For Control | Radians | and click |
Wait For Process
Description: Waits for a process to become active (typically via Name, can also use ProcessId)
In: search criterion
Out: process found before timeout (true/false)
Example(s): | Wait For Control | Radians |
| Wait For Control | Id:304 |
Wait Seconds
Description: Wait the specified number of seconds (can be fractions)
In: wait time in seconds
Out: process found before timeout (true/false)
Example(s): | Wait | 0.3 | seconds |
Wait Until Control Disappears
Description: Waits for a control to disappear
In: search criterion
Out: control disappeared before the timeout? (true/false)
Example(s): | Wait Until Control | Id:304 | Disappears |
Wait Until Process Ends
Description: Waits for a process to end (via ProcessId or Name)
In: search criterion
Out: process found before timeout (true/false)
Example(s): | Wait For Control | Radians |
| Wait For Control | Id:304 |
Window Size
Description: Returns the window size of the system under test as a pair of width, height in pixels
In: -
Out: the size in pixels
Example(s): | Check | Window Size | 400, 240 |
Window Snapshot [Minus Outer Pixels]
Description: Take a snapshot of the current window and return it as an HTML image in base 64 format.
Optionally the snapshot can remove an inner border.
In: [the border width that needs to be removed from the snapshot]
Out: the snapshot in HTML img
Example(s): | Show | Window Snapshot |
| Show | Window Snapshot Minus Outer | 5 | Pixels |
Note: Border removal is useful to remove semi-transparent borders to enable picture comparisons
Window Snapshot Object [Minus Outer Pixels]
Description: Take a snapshot of the current window and return it as a Snapshot object
In: [the border width that needs to be removed from the snapshot]
Out: the snapshot object
Example(s): | $snapshot= | Window Snapshot Object |
| $snapshot= | Window Snapshot Object Minus Outer | 10 | Pixels |
Window Top Left
Description: Returns the coordinates (X, Y) of the top left corner of the system under test’s window
In: -
Out: the coordinate of the top left point
Example(s): | Check | Window Top Left | 100, 150 |

Query Fixture: Extract Grid

The Extract Grid fixture implements a query allowing you to extract the values of a grid control. The parameter is a search criterion in the same format as the script fixture: method:locator. The first row of the table specifies the headers you are interested in.

Before using this fixture, start the application using the script fixture.

Here are an example system under test and the corresponding test page:

Sample Grid

!|Query: Extract Grid|id:DataGrid1                                            |
|Id                  |Title                                          |Status  |
|100                 |Create UI Automation fixture                   |Done    |
|101                 |Create demo UI Automation application          |Active  |
|102                 |Add UI Automation fixture to application       |Approved|
|103                 |Test UI Automation fixture with GridData object|New     |
|104                 |http://localhost:8080                          |Resolved|

!|Subset Query: Extract Grid|id:DataGrid1                                |
|Id                         |Title                                |Status|
|100                        |Create UI Automation fixture         |Done  |
|101                        |Create demo UI Automation application|Active|

The result:

Sample Grid Test Result

⚠️ **GitHub.com Fallback** ⚠️