Script playback fails, application instance already running
The problem: You might have a case where the application being tested fails to close. Rational Functional Tester script playback then might begin to fail, reporting that another instance of the application is already running. Rational Functional Tester does not close the application, and additional attempts by Rational Functional Tester to open the application eventually results in an unresponsive computer. All instances of he application must be closed before Rational Functional Tester can resume.
The solution: There are two ways to resolve this problem, by adding custom code to your Rational Functional Tester script. For more information on adding custom code to your scripts, see the Rational Functional Tester documentation.
Solution 1: Using ProcessTestObject, test if the
application is active before the Rational Functional Tester script
exits. If the application is active, run the kill() method
of ProcessTestObject to ensure that the application exits.
See the following example code:
ProcessTestObject top = startApp("NOTEPAD");
sleep(5);
// Window: NOTEPAD.EXE: Untitled - Notepad
edittext().click(atPoint(149,36));
untitledNotepadwindow().close();
sleep(3);
if (top.isAlive()) {
logInfo("killing notepad");
top.kill();
}
Solution 2: Override the onAmbigousRecognition exception
to get the ProcessTestObject for both the applications, then
determine which is the older process, and kill it. See the following
code example:
public class Script1 extends Script1Helper
{
ProcessTestObject pto;
/**
* Script Name : Script1
* Generated : Nov 18, 2010 11:01:15 AM
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @since 2010/11/18
* @author shinoj
*/
public void onAmbiguousRecognition(
ITestObjectMethodState testObjectMethodState, TestObject[] choices,
int[] scores) {
if (choices.length > 1)
{
TestObject tob1 = (TestObject)choices[0];
TestObject tob2 = (TestObject)choices[1];
ProcessTestObject pto1 = tob1.getProcess();
ProcessTestObject pto2 = tob2.getProcess();
if (pto.equals(pto1))
pto2.kill();
else
pto1.kill();
}
testObjectMethodState.findObjectAgain();
//super.onAmbiguousRecognition(testObjectMethodState, choices, scores);
}
public void testMain(Object[] args)
{
pto = startApp("ClassicsJavaA");
sleep(5);
placeOrder().click();
//pto.kill();
}
}