From Documentation

Jump to: navigation, search



InputAgent can be used on any input component such as textbox or datebox. Among these input components, components in which users can type string in, we can mimic it with InputAgent.type(String) . In cases where components are not able to type in string such as slider, we can use InputAgent.input(Object) instead.

We will use a todo list application to demonstrate the usage of InputAgent . Here is the application's UI:


The following test case verifies "Add" function, we enter values into 3 fields: item name, priority, and date, and click "Add" button. Then we inspect each listcell of a listitem to verify that a to-do item is added to the listbox.

public class TodoTest {

	public void test() {
		//visit the target page
		DesktopAgent desktop = Zats.newClient().connect("/todo.zul");

		//find components
		ComponentAgent itemName = desktop.query("textbox");
		ComponentAgent priority = desktop.query("intbox");
		ComponentAgent date = desktop.query("datebox");

		//verify each listcell's label
		ComponentAgent listbox = desktop.query("listbox");
		List<ComponentAgent> cells = listbox.queryAll("listitem").get(0).getChildren();
  • The formal usage of InputAgent is to retrieve from a ComponentAgent . (line 14)
  • As seen in the previous example, this is also a shortcut method. (line 15)
  • Although priority is an intbox, we still provide a String as the parameter. The string will be parsed to an integer internally, if failed we'll get an exception. (line 16)
  • When typing in a Datebox, use the date format that you have specified in Datebox's "format" attribute. The same rule applies to timebox. (line 17)
  • The query syntax means "retrieve a button whose label is 'Add'". (line 18)
  • If we call ComponentAgent.query() , it'll only query the ComponentAgent's child components. Here, we find listitem to get listcell. (line 22)


If you want to mimic a user's typing , you should use InputAgent.typing(String) . It is similar to type(String) but it triggers an onChanging event instead of an onChange event.

For example, to achieve auto-complete feature, developers usually listens to an onChanging event of a textbox and performs post-processing.




select(int, int) is used to mark the selection of a range of text by starting and ending index (ending index is exclusive).




Among input components, only slider is where users cannot type text in. So we provide a method, input(Object) , to generalize input operation. Users don't have to care how values are inputted into a component, but what the values are. For slider, we should pass integer as the parameter.



Supported Components

Bandbox, Combobox, Textbox 5, 6
Datebox, Decimalbox, Doublebox, Doublespinner, Intbox, Longbox, Spinner, Timebox 5, 6 input string should match "format" attribute's pattern
CKEditor 5, 6 only supports type(String) , typing(String)
Colorbox 5, 6 only supports type(String)
Slider 5, 6 only supports input(Object)

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.