InputAgent

From Documentation
Revision as of 09:41, 11 May 2012 by Hawk (talk | contribs)



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

Smalltalk-MimicLibrary-todolist.png

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 the result.

TodoTest.java

public class TodoTest {

	@Test
	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");

		//add
		//itemName.as(InputAgent.class).type("one-item");
		itemName.type("one-item");
		priority.type("3");
		date.type("2012-03-16");
		desktop.query("button[label='Add']").click();
		
		//verify each listcell's label
		ComponentAgent listbox = desktop.query("listbox");
		List<ComponentAgent> cells = listbox.queryAll("listitem").get(0).getChildren();
		assertEquals("one-item",cells.get(0).as(Listcell.class).getLabel());
		assertEquals("3",cells.get(1).as(Listcell.class).getLabel());
		assertEquals("2012/03/16",cells.get(2).as(Listcell.class).getLabel());
	}
}
  • 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)




Last Update : 2012/05/11

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