2009-04-08 22 views
3

只要出現對話框且沒有附加的處理程序,watin自動關閉對話框。當您不想爲應用程序可能具有的不同/幾個簡單確認添加代碼時,這會很有幫助。如何在watin中出現對話框時默認測試失敗

問題是,使用此默認行爲可能會導致簡單的問題不被注意,就像出現在它不應該出現的場景中的確認對話框一樣。

我正在尋找一種簡單的方法來正常地在未處理的對話框出現時通過測試。優雅地說,當對話框出現異常時,測試就會停止,這會給你一個體面的信息,讓你知道這是一個意外的對話錯誤。

回答

3

另一個選擇可能是使用AlertAndConfirmDialogHandler。這個處理程序接近每個警報或確認對話框,彈出式菜單了,但首先它得通過對話,並將其存儲顯示的文字。您可以檢查此Alerts字符串數組並查看Count是否爲零。你可以在測試課的Teardown或FixtureTeardown中做到這一點。

繼從華廷單元測試測試的副本來告訴你如何使用這個處理程序:

 [Test] 
    public void AlertAndConfirmDialogHandler() 
    { 
     DialogWatcher dialogWatcher; 

     Assert.AreEqual(0, Ie.DialogWatcher.Count, "DialogWatcher count should be zero before test"); 

     // Create handler for Alert and confirm dialogs and register it. 
     var dialogHandler = new AlertAndConfirmDialogHandler(); 
     using (new UseDialogOnce(Ie.DialogWatcher, dialogHandler)) 
     { 
      Assert.AreEqual(0, dialogHandler.Count); 

      Ie.Button("helloid").Click(); 

      Assert.AreEqual(1, dialogHandler.Count); 
      Assert.AreEqual("hello", dialogHandler.Alerts[0]); 

      // remove the alert text from the queue by using Pop 
      Assert.AreEqual("hello", dialogHandler.Pop()); 

      Assert.AreEqual(0, dialogHandler.Count); 

      // Clear the queue 
      Ie.Button("helloid").Click(); 

      Assert.AreEqual(1, dialogHandler.Count); 

      dialogHandler.Clear(); 

      Assert.AreEqual(0, dialogHandler.Count); 

      dialogWatcher = Ie.DialogWatcher; 
     } 

     Assert.AreEqual(0, dialogWatcher.Count, "DialogWatcher count should be zero after test"); 
    } 

這也觸發了我,使自動關閉行爲更加可插拔。這將是很好,如果能註冊,而不是僅僅自動關閉對話框一個DialogHandler中,將調用如果沒有其他處理程序可以處理一個對話框。

HTH 吉榮麪包車梅嫩 鉛開發華廷

+0

我現在面臨的問題用這種方法,它有時工作,有時沒有。 – rahoolm 2013-11-21 00:02:28

1

現在我們正在使用:

browser.DialogWatcher.CloseUnhandledDialogs = false 

它具有以下(醜陋的)問題:

  1. 出現錯誤作爲下操作的超時時間(使用消息「超時而互聯網資源管理器繁忙「)。
  2. 由於上述原因,測試中存在不必要的延遲
  3. 出現意外彈出的實例保持打開狀態(處置後)。
相關問題