Aug 31, 2010

IBM RFT: how to invoke object methods

Looks like currently IBM RFT only support Java domain objects methods invoke(?)

Three steps to invoke the object methods:

1. get all methods signature:

printTOMethods(TestObject TO) {
int i = 0;
System.out.println("Object Class [" + TO.getObjectClassName() + "]'s methods: \n");
for (MethodInfo mi : TO.getMethods()) {
System.out.println("Method-" + (i++) + ": [" + mi.getName() + ":" + mi.getSignature() + "]");
}
}

2. Study api documents to select the methods you need to use according to your target;
3. invoke object methods strictly obey the signature:

for example, for some 'new' objects RFT could only blindly click/select by screen point, you need to find the screen point for RFT:

boolean selectTableItem(ScrollTestObject table, String itemName) {
boolean selected = false;

TestObject[] itemsTo = (TestObject[])table.invoke("getItems");

for (int i=0; i
if (itemsTo[i].getProperty("text").toString().equalsIgnoreCase(itemName)) {
java.awt.Rectangle rec = (java.awt.Rectangle) itemsTo[i].invoke("getBounds", "(I)", new Object[] {new Integer(0)});
table.click(atPoint(rec.x + rec.width/2, rec.y + rec.height/2)); //click at the item center to select it

selected = true;
break;
}
}

return selected;
}

No comments: