TestComplete: Closing Unexpected Windows

@ Fr, 21 December 2007, 11:20
TestComplete allows to handle event OnUnexpectedWindow and specify actions you want to perform if this event occurs. For example, when an unhandled exception occurs in the tested application, or database is disconnected, etc.

 

However, this event will work only if unexpected window prevents TestComplete to work with application. In case of non-modal windows, or if the window doesn’t affect tested application, this event will not occur and TestComplete will continue working.

 
If you need to handle such windows, you can use Timer object.
Below you will find an example, how to close Calculator window during script delaying for 60 seconds.
 
First of all, we need to create a function which checks whether Calculator exists and terminates it’s process if true.
 
// TestComplete JScript
function KillCalculator()
{
 if(Sys.WaitProcess("calc", 1, 1).Exists)
 {
    Log.Message("Calculator has been found");
    Sys.Process("calc").Terminate();
 }
}
 
And here is the function which uses just created KillCalculator function.
 
function test_timer()
{
 Utils.Timers.Add(500, "MyUnit.KillCalculator", true);
 BuiltIn.Delay(60000);
}
 

Here,

  • 500 is interval in milliseconds the timer will wait before executing the timer routine;
  • MyUnit.KillCalculator - the script routine that will be executed (please note, that unit name is required);
  • parameter true means that timer is active.
 If you run the second function and open calculator several times, it will be closed immediately by TestComplete.
You must be logged in in order to post comments