我正在使用此功能等待WPF应用程序完成。
while (stillRunning)
{
if (timeOut > maxTime)
{
Log["Error"]("The App failed to shutdown correctly.");
break;
}
else
{
if (Aliases[process]["Exists"])
{
timeOut+=1000;
if ((timeOut % 1000) == 0)
{
Log["Message"]("The Application process is still running. " + (timeOut / 1000) + " seconds and waiting");
}
}
else
{
stillRunning = false;
}
}
}
Log["Message"]("The Application process has been shutdown correctly.");
}
现在,问题是TestComplete 9无法识别应用程序何时关闭。我的意思是......我可以清楚地看到过程在任务管理器中不再存在,而TC会一直计数直到达到极限时间(在这种情况下绰绰有余)。
任何线索?
答案 0 :(得分:0)
使用此代码:
function test()
{
var timeout = 5000;
var startTime = GetTickCount();
var pClosed = waitProcessClose("notepad", timeout);
var endTime = GetTickCount();
var closeTimeS = Math.round((endTime - startTime) / 100) / 10;
if (pClosed) {
Log.Message("The process was closed in " + closeTimeS + " seconds.");
}
else {
Log.Warning("The process was not closed in " + (timeout / 1000) + " seconds.");
}
}
function waitProcessClose(processName, timeout)
{
var endTime = GetTickCount() + timeout;
var proc = Sys.WaitProcess(processName);
while (proc.Exists) {
var secondsLeft = Math.floor((endTime - GetTickCount()) / 1000);
Delay(200, "Waiting for the '" + processName + "' process to be closed: " + secondsLeft);
if (GetTickCount() > endTime) {
Log.Warning("The process is not closed within '" + timeout + "' ms.");
return false;
}
}
return true;
}