Functional Tester 有一组预定义的 SubItem,代理可以在录制过程中使用这些 SubItem。录制过程中,代理确定某一位置上的 SubItem,然后将 SubItem 详细信息与测试对象的用户操作方法一起发送。回放时,代理将重新确定 SubItem 的坐标,然后将回放用户操作。
listBox.click(atText("Item1"));
在此示例中,click 是事件。atText("Item1") 参数是代理在此位置查找的 subitem。在 .Net 方式下,GetActionArgs() API 将返回控件的一个或多个 SubItem。确定要使用的特定于控件的 SubItem。
下面的示例显示了带有 SubItem 的录制方法的 Java 实施:
{
.
.
Vector args = new Vector(20);
SubItem subItem = null;
IMouseEventInfo event0 = action.getEventInfo(0);
Point firstPoint = new Point ( event0.getX(), event0.getY() );
Point firstPointToList = new Point ( firstPoint.x, firstPoint.y );
int itemIndex = locationToIndex(firstPointToList);
String itemText = ((java.awt.List)theTestObject).getItem(itemIndex);
if (itemText!= null && ! itemText.equals("") )
subItem = new Text(item);
else
subItem = new Index(atIndex);
.
.
args.addElement(subItem);
.
.
}
下面的示例显示了带有 SubItem 的录制方法的 .Net 实施:
protected override System.Collections.ArrayList GetActionArgs(System.Drawing.Point point)
{
System.Collections.ArrayList args = new System.Collections.ArrayList() ;
Subitem subitem = null ;
System.Drawing.Point clientPoint = ((Control)theTestObject).PointToClient(point) ;
int itemIndex = ((ListBox)theTestObject).IndexFromPoint(clientPoint) ;
string itemText = ((ListBox)theTestObject).GetItemText(item);
if (itemText == null || itemText.Length == 0)
{
// item has no text so generate an index
subitem = new Rational.Test.Ft.Script.Index(itemIndex) ;
}
if ( subitem != null )
{
args.Add(subitem) ;
}
return args ;
}
下面的示例显示了回放带有 SubItem 的方法的 Java 实施:
public void click(MouseModifiers modifiers, Subitem subitem)
{
.
.
Point pt = this.getScreenPoint(subitem);
new Screen().click( modifiers, pt);
.
.
}
public java.awt.Rectangle getScreenPoint (Subitem subitem)
{
int index = getItemIndex(subitem);
if ( index == -1 )
return null;
java.awt.Rectangle rectCell = getCellBounds(index);
java.awt.Rectangle rectScreen = this.getScreenRectangle();
return new java.awt.Rectangle
( rectScreen.x + rectCell.x, rectScreen.y + rectCell.y,
rectCell.width, rectCell.height );
}
下面的示例显示了回放带有 SubItem 的方法的 .Net 实施:
protected override System.Drawing.Rectangle GetSubitemRect(Rational.Test.Ft.Script.Subitem subitem)
{
int index = GetItemIndex(subitem) ;
return ((ListBox)theTestObject).GetItemRectangle(index) ;
}