当我们运行 CodedUI 测试并且测试用例失败时,我们通过Kill()
以下调用终止 Internet Explorer 进程:
private static readonly HashSet<string> ProcessesToKill =
new HashSet<string>(new[] { "iexplore" });
public static void Kill()
{
var runningProcessesToKill = (from p in Process.GetProcesses()
where ProcessesToKill.Contains(p.ProcessName,
StringComparer.OrdinalIgnoreCase)
select p).ToArray();
// First try to close the process in a friendly way
CloseProcess(runningProcessesToKill);
// Then wait for a while to give the processes time to terminate
WaitForProcess(runningProcessesToKill);
// If not closed kill the process.
KillProcess(runningProcessesToKill);
}
杀死是通过首先调用CloseMainWindow()
和Close()
进程来完成的,然后等待一段时间,然后再调用Kill()
进程。
不幸的是,这不会关闭 JavaScript 警报弹出窗口。测试运行完成后,它会保留在屏幕中,阻止下一个测试,如下所示:
为什么它没有关闭警报,我们如何解决这个问题?