Enhancing the recording behavior with SubItems

SubItems are HCL OneTest UI defined portions of a control under test. In some cases, you get best results by recording the user interaction with SubItem details rather than recording just with the coordinate information. The disadvantage of using the coordinate information is that when portions of a control are resized or rearranged, playing back the user actions might not return the same results.

Before you begin

For example, in a table control whose column width can be resized, recording the clicks with coordinate is not meaningful during playback if the column width changes.

HCL OneTest UI has a set of predefined SubItems and proxy can use them during recording. During recording, proxy determines the SubItem at a point and sends the SubItem details along with the user action method for the TestObject. At playback time, the proxy again determines the coordinate for the SubItem and the user action is played back.

You can extend the methods that are listed in Extensible proxy methods:
Table 1. Extensible proxy methods
Java .Net
System.Collections.ArrayList GetActionArgs(System.Drawing.Point point) java.util.Vector getActionArgs(java.awt.Point point)
System.Drawing.Rectangle GetSubitemRect(Rational.Test.Ft.Script.Subitem subitem) java.awt.Point getScreenPoint(com.rational.test.ft.script.Subitem subitem)

Recording methods with SubItems

While you are recording an event, the ProcessMouseEvent method is called. Then, the proxy determines the appropriate SubItems at certain points and these SubItems are recorded as part of the event.

Before you begin

The following code is an example of how the event is recorded:
listBox.click(atText("Item1"));

In this example, click is the event. The atText("Item1") parameter is the subItem that the proxy finds at the point. In case of .Net, the GetActionArgs() API returns one or more SubItems of the control. Determining which SubItem to use is specific to the control.

The following example shows the Java implementation of recording methods with SubItems:

java.util.Vector getActionArgs(java.awt.Point point)
{
	. 
	.
        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);
	.
	.
	}

The following example shows the .Net implementation of recording methods with SubItems:

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 ;
}

Playing back methods with SubItems

During playback, the proxy needs to find the screen coordinate of a SubItem to play back the user action.

Before you begin

The following example shows the Java implementation of playing back methods with SubItems:

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 );

}

The following example shows the .Net implementation of playing back methods with SubItems:

protected override System.Drawing.Rectangle GetSubitemRect(Rational.Test.Ft.Script.Subitem subitem)
{
	int index = GetItemIndex(subitem) ;		
	return ((ListBox)theTestObject).GetItemRectangle(index) ;
}

What to do next

After successfully developing and deploying this proxy code, the recorded methods have the appropriate SubItems and playback happen as expected.