WatiN——Web自動化測試(三)【彈出窗口處理】軟件測試
上一節我們說了關于WatiN的自動化的框架的設計,一般的系統應用應該可以。關于Case的本身的編寫在實際應用中也會有一些問題和難題。這一節我將 WatiN的彈出框作一下詳細的總結。在實際網頁中,操作按鈕可能彈出各種樣式的彈出框,如何進行有效的處理呢?1、Alert DialogAlert對話框很簡單,彈出之后只是一個提示作用,彈出之后進行確認即可。
public static void CaptureAlertDialog(this Browser browser, Action
{
var handler = new AlertDialogHandler();
using (new UseDialogOnce(browser.DialogWatcher, handler))
{
operation(handler);
handler.WaitUntilExists(waitTimeInSeconds);
if (handler.Exists())
handler.OKButton.Click();
}
}
CaptureAlertDialog:是處理alert對話窗方法,其傳入的參數分別是:Browser瀏覽器對象、Acation
context.Browser.CaptureAlertDialog((AlertDialogHandler handler) => { btn.WaitUntilExistsAndClickNoWait(context.TestConfig.Timeout); }, 5);
btn.WaitUntilExistsAndClickNoWait(context.TestConfig.Timeout); 為button的點擊事件。
2、Confirm Dialog
public static void CaptureConfirmDialog(this Browser browser, Action
{
var handler = new ConfirmDialogHandler();
using (new UseDialogOnce(browser.DialogWatcher, handler))
{
operation(handler);
handler.WaitUntilExists(waitTimeInSeconds);
if (handler.Exists())
{
handler.OKButton.Click();//確認按鈕 handler.CancelButton.Click();取消按鈕
文章來源于領測軟件測試網 http://www.kjueaiud.com/