I'd do a search on objects whose ".hasFocus" property is set to "true". From there, you could just run the method in a loop to check that the currently focused element is the one you want. I'd also personally recommend (if possible) to check against the ".id" property, since for a given (web)page, that's guaranteed to be a unique identifier... whereas I'm not entirely sure the ".name" property is.
public void testMain(Object[] args) {
ArrayList<String> focusOrder = new ArrayList<String>();
String currentlyFocusedObjectName = "";
// Add element names to the list
focusOrder.add("Object1");
focusOrder.add("Object2");
// ...
focusOrder.add("Objectn");
// Iterate through the list, tabbing and checking ".name" property each time
for (String s: focusOrder) {
TestObject currentObject = getCurrentlyFocusedElement();
// Tab
getScreen().inputKeys("{TAB}");
if (currentObject != null) {
currentlyFocusedObjectName = getCurrentlyFocusedElement().getProperty(".name")
.toString();
// Do other stuff with the object
}
else {
currentlyFocusedObjectName = "";
}
// Verify that the currently focused object matches the current iteration in the list.
vpManual(s + "HasFocus", currentlyFocusedObjectName, s).performTest();
}
}
private TestObject getCurrentlyFocusedElement() {
RootTestObject root = RootTestObject.getRootTestObject();
TestObject[] focusedObjects = root.find(atProperty(".hasFocus", "true");
TestObject currentlyFocusedObject = null;
// Check to ensure that an object was found
if (focusedObjects.length > 0) {
currentlyFocusedObject = focusedObjects[0];
}
else {
unregister(focusedObjects);
return null;
}
// Clean up the object
unregister(focusedObjects);
return currentlyFocusedObject;
}