Wiki

Clone wiki

uinput / Home

Welcome

U-input is a testing helper that allows easy access to the UI components and simulates user interaction with the UI. It uses the Flex automation API so in most cases it mimics best the real interactions.

U-input focuses on providing access to the components and interactions not the verification. For verification you should look at tools like Morefluent.

U-input works with Flex3 at this point. Support for the spark components and SDK4 will come soon.

How to

Setup

U-input can be used in several ways. The easiest thing to do is to call:

install(rootComponent);

where rootComponent should be the same container or a component that you want to browse and test. In the most generic case you could pass the application instance.

This call should be made before you start using U-input for instance: from a setUp() function of your test case. Once you do it you can use U-input short notation for browsing components (like button(), grid(), etc).

Example:

install(mainView);

button("save").click();

You can also simply create an instance of Uinput class by calling new Uinput(rootComponent) and use this instance to call browse functions of it.

Example:

var uinput = new Uinput(mainView);

uinput.button("save").click();

Finding components by name

U-input can find components in many ways. Primarily it uses properties like name and automationName to match the component.

A button:

<mx:Button name="saveButton" />

Can be found by calling:

button("saveButton");

You should know that automationName takes after some of the properties assigned to the component. If a component is given an id in MXML this id becomes the automationName if no other property is set.

<mx:Button id="saveButton" />

Can be found by calling:

button("saveButton");

It's very important to understand that if both name and automationName is assigned, the name property takes precedence. It's been chosen to work like that on purpose.

Also note that you don't have to put the complete path to the component. The stage will be traversed for you and the first match will be used.

Resolving path ambiguities

If it happens that component of the same name is used in several places, you can make the query more specific by adding the parent path to it.

button("settingsForm/saveButton");
button("expenses/saveButton");

Note that any intermediate components can be omited in the path so the saveButton can be actually nested in more than just settingsForm or expenses pane.

Finding components by type and name

To further help resolving ambiguities the component query can be complemented with a type definition. So if you have two components of the same name but different type you can use this feature to pick the right one.

<mx:TextInput name="description" />
<mx:TextArea name="description" />

Can be found by calling:

textInput("description:TextInput").typeText("very important entry");
textInput("description:TextArea").typeText("very important entry");

You can also use type query w/o name for the rare cases:

textInput(":TextInput").typeText("very important entry");

The type can be also a fully qualified name in a form:

textInput("description:acme.component.TextInput").typeText("very important entry");

Type query can be used at any level in the path:

textInput("view:HBox/description").typeText("very important entry");

Property queries

More complex queries may require going beyond the name and type. To add properties to the query you can use:

button("@label=Save Changes");
button("@label=Save Changes@width=100");

To query by name, type and properties use:

button("saveButton:Button@label=Save Changes");

Button, CheckBox, RadioButton

To access the any type of the button in your application you should use:

button("saveButton");

Fluent interface of the button allows:

button("saveButton").click();
button("saveButton").doubleClick();
button("saveButton").pressKey(KeyCodes.SPACE);

TextInput, TextArea

Text inputs are accessible with:

textInput("userName");

Fluent interface of the text inputs allows:

textInput("userName").typeText("kris"); // types text replacing any selection
textInput("userName").pressKey(KeyCodes.TAB); // simulates key stroke
textInput("userName").selectAllText(); // selects all text
textInput("userName").selectText(2, 5); // selects from the start to the end offset
textInput("userName").clearSelection(); // removes selection

List

Lists are accessible with:

list("songs");

Fluent interface of the list allows:

list("songs").select(2); // to select specific row
list("songs").startSelection(2).endSelection(5); // to select multiple rows
list("songs").edit(2).typeText("UNFORGIVEN").commitEdit(); // to perform text edit of the row in the list
list("songs").cancelEdit(); // to cancel pending edit
list("songs").click(); // to mouse click - to specify location within a list you must pass appropriate mouse event instance here
list("songs").doubleClick(4); // to double click specific row
list("songs").pressKey(KeyCodes.ENTER); // for the keystroke

DataGrid

DataGrids can be browsed with:

Note: AdvancedDataGrid is not functioning at the moment.

grid("expenses");

Fluent interface of the grid allows:

grid("expenses").select(2); // to select row
grid("expenses").startSelection(3).endSelection(2); // for the continuous selection
grid("expenses").edit(2, 4).typeText("100").commitEdit(); // to enter 100 in the row 2 and column 4
grid("expenses").cancelEdit(); // to cancel any pending edit
grid("expenses").commitEdit(); // to commit any pending edit
grid("expenses").typeText("vacation"); // to type on the grid
grid("expenses").pressKey("A"); // to send a keystroke to the grid

ComboBox

Dropdowns are accessible with:

dropdown("options");

Fluent interface of the dropdown allows:

dropdown("options").typeText("my option"); // to enter text to the editable dropdown
dropdown("options").pressKey(KeyCodes.DOWN); // to send the keystroke
dropdown("options").selectAllText(); // to select text of the editable dropdown
dropdown("options").select(2); // to select third option from the options list
dropdown("options").open(); // to open dropdown
dropdown("options").close(); // to close dropdown
dropdown("options").popup.select(1); // to access the dropdown list and perform operations on it

License

The MIT License

Copyright (c) 2010 U-input contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Updated