When we run our CodedUI tests and the test cases fail we kill the Internet Explorer process by calling Kill()
below:
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);
}
Killing is done by calling CloseMainWindow()
and Close()
on the processes first, then waiting for a while and then calling Kill()
on the processes.
Unfortunately, this does not close a JavaScript alert popup. When the test run is finished this remains in the screen blocking the next test, like so:
Why does it not close the alert, and how can we fix this?