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

IBM RFT: Enable Java Domain for Java AUT

Normally IBM RFT just regards all objects in Win domain without respect that the AUT is a Java application.
It's fine normally, but for some special objects (e.g. grid) against which you'd like call the special methods for your test purpose, you could enable RFT to treat objects in Java domain:
  • In RFT, 'Configure->Enable Environments for Testing...';
  • In tab 'Eclipse Platforms', 'Add...' browse to where your Java application home_dir (with private jre);
  • 'Enable' it, then 'Apply', 'Finish' to close 'Enable Environments' window.