2

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:

Popup remains in screen

Why does it not close the alert, and how can we fix this?

user2609980
  • 10,264
  • 15
  • 74
  • 143

1 Answers1

1

You can brute force this using the taskkill command from the command line:

C:\>taskkill /F /IM iexplore.exe

This, of course, doesn't help you with your tests. Instead, use Process.Start(...):

public static void Kill()
{
    System.Diagnostics.Process.Start("taskkill", "/F /IM iexplore.exe");
}

This will shut down all Internet Explorer processes, regardless of whether or not they have an alert or confirm dialog visible.

References:

Community
  • 1
  • 1
Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92