IBM Support

How to use unregisterAll method in a Rational Functional Tester script

Technote (FAQ)


Question

How can you explicitly unregister any bound reference in an IBM Rational Functional Tester script that was created when a Java script uses dynamic find?

Cause

When you run a long script that heavily uses dynamic find, you want to avoid the following issues.

  • Error message Spy heap is locked.
  • Playback halts before completion.
  • Abnormal end of IBM Rational Functional Tester.
  • To run out of memory.
  • Other unexpected messages.


Helper script methods refer to an object in the application under test (AUT). For this the methods use the test object map. IBM Rational Functional Tester finds such mapped objects each time the script calls a method on the object.. In some cases; however, you do not want Rational Functional Tester to find mapped objects.

Answer

Use unregisterAll(). Consider the following examples how to invoke this method at appropriate places in the test script.


EXAMPLE #1

You want to call many methods directly on the same object. In this case you can use the TestObject.find() method to find an object. See the following sample code.





// Doing find and saving the returned object in the TestObject array.
TestObject[] googleButton = bto.find(atDescendant(".class" ,"Html.INPUT.submit",".value","I'm Feeling Lucky"));

if(googleButton.length ==0 )

{

System.out.println("None found");

return;

}

//Click the first test object it found.

((GuiTestObject)googleButton[0]).click();

}

else

{

System.out.println("Browser didn't come to ready State");

}

//

unregisterAll();




In this example TestObject[] discovers the test object with a find method and returns to an array of the test object. When the method finds the object, the method casts into a GUITestObject and performs a click. This code discovers the test object dynamically, the test object dynamically. In other words, you do not use no mapped test objects. Now you need explicitly unregister any bound references that you created as soon as you do not need these references any more. Otherwise this might leads into memory issues , such as Spy Heap is Locked and out of memory error.

The script explicitly calls unregister the bound references of the HTML Button using unregisterAll(). RationalTestScript contains several methods that remove references to TestObjects, including com.rational.test.ft.script.RationalTestScript.unregister and unregisterAll. See the Rational Functional Tester API Reference for information about these methods.



EXAMPLE #2

Here you want to select a sub-item from the drop down list or combo box. whether you find a sub-item or not, you still need to unregister any bound references explicitly.



TestObject[] dropdownSelection = null;

try {

dropdownSelection = getObjectProperties(prop1, prop2);

((SelectGuiSubitemTestObject) (dropdownSelection[0])).select("PizzaHut");

unregister(dropdownSelection);

return true;

} catch (Exception e) {

unregister(dropdownSelection);

return false;

}







EXAMPLE #3

Now you discover an SAP TestObject based on a set of Properties. Whether you find a test object successfully or not, you still need to clear up the bound references with unregisterAll();




// Define a set of properties for a control (test object) to be searched

Property Props[] = new Property[4];

// property and value

Props[0] = new Property(".class", "Html.TABLE");

Props[1] = new Property(".customclass", "SAPEditControl");

Props[2] = new Property(".id", "WD019E-r");

Props[3] = new Property(".classIndex", "10");

try {

// find and store test objects into array

TestObject Obj[] = getRootTestObject().find(atDescendant(Props));

// perform a click on very first object.

((TextGuiSubitemTestObject) Obj[0]).click();

// set a text into SAP Edit Control

((TextGuiSubitemTestObject) Obj[0]).setText("ClaimedAmount");

} catch (Exception ex) {

ex.printStackTrace();

} finally {

//call unregisteAll to clear up the store reference.

unregisterAll();

}





Note: Act cautiously, when you deal directly with test objects that contain references to objects in the application-under-test. If you do so, the AUT might become unstable. Unregister these test objects as soon as possible.

Document information

More support for: Rational Functional Tester
Scripting

Software version: 6.1, 6.1.0.1, 6.1.1, 6.1.1.1, 7.0, 7.0.0.1, 7.0.0.2, 7.0.0.3, 7.0.1, 7.0.1.1, 7.0.1.2, 7.0.1.3, 8.0, 8.0.0.1, 8.0.0.2, 8.0.0.3, 8.0.0.4, 8.1, 8.1.0.1, 8.1.0.2, 8.1.0.3, 8.1.1, 8.1.1.1, 8.1.1.2, 8.1.1.3, 8.2, 8.2.0.1, 8.2.0.2

Operating system(s): Linux, Windows

Reference #: 1507963

Modified date: 05 August 2011