2010-11-11 28 views
0

我正在實施一個Selenium 2項目,該項目目前不支持確認對話框。我可以使用什麼樣的模式?

對此限制有一個解決方法,您只需覆蓋window.confirm以返回您需要爲特定測試用例返回的值。

以下字符串可以被設置,然後執行:

public static final String CONFIRM_DIALOG_BOX = 
    "window.confirm = function(msg) { return true; }"; 

public static final String CANCEL_DIALOG_BOX = 
    "window.confirm = function(msg) { return false; }"; 

這似乎爲模板的方法很簡單,但是我也有同樣的頁面對象,我需要確認/否認相互作用後在多個測試用例與頁面。因此,使用單一方法一次完成所有這些測試是行不通的。

注入一個運行到測試方法的命令可能是有道理的,但我的最終目標是允許我們技術較差的人員通過將一些字符串寫入XML然後用Spring表達式語言執行它來創建測試;這會消除編寫測試的一些「簡單」。

需要注意的是,這個測試套件實際上是一個由於需求而定的應用程序,而不是一組單獨運行的測試用例。如果它們是小型測試用例,它會容易得多,因爲我可以擴展一個抽象測試用例並使用相同的設置和拆卸例程。

我最終尋找的是沿着這個模板方法的東西,但我需要能夠支持單個頁面對象上的多個測試用例。

public final void executeTest(boolean confirmDialogBoxResponse) { 

    // store normal functionality and allow us to return 
    // window.confirm to normal state upon completion of test. 
    prepare(confirmDialogBoxResponse); 

    testMethod(); // What about params to these methods? 

    /* Adding an interface to the method would be nice, but 
    * would make things a bit more cumbersome for our 
    * less technical staff, which would allow me to replace 
    * the above with this: 
    * 
    * executeTest(TestCommand command, confirmDialogResponse); 
    *   command.execute(); // Still have params issue 
    */ 

    // restore window.confirm to normal state -- if we cancel we stay 
    // on same page, and need to restore things as they were, the majority 
    // of our confirm cases take you to new pages whereby window.confirm 
    // will be restored for us 
    if (!confirmDialogResponse) { 
     restore(); 
    } 
} 

回答

0

有你看了Selenium Issue #27 recently (comment#46)?它附帶了一些補丁,提供對警報和確認的支持?

+0

我曾看過這些補丁,但想等待'官方'迴應。昨天我收到通知,這將在測試版本,這將有望看到即將到來的一天。 – Scott 2010-12-02 13:13:14

相關問題