2015-09-30 52 views
2

當我們運行CodedUI測試和測試案例失敗,我們通過下面的調用Kill()殺死Internet Explorer進程:殺試運行後,所有IEXPLORE進程失敗

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警報彈出窗口。當測試運行結束,這仍然在屏幕遮擋下一個測試,像這樣:

Popup remains in screen

爲何不關閉警告,以及我們如何解決這一問題?

回答

1

您可以蠻力攻擊使用taskkill命令在命令行:

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

這當然不幫你測試。相反,使用Process.Start(...)

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

這將關閉所有Internet Explorer進程,不管他們是否擁有一個警告或確認對話框中可見。

參考文獻:

相關問題