日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WatiN——Web自动化测试(三)【弹出窗口处理】

發布時間:2025/4/5 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WatiN——Web自动化测试(三)【弹出窗口处理】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上一節我們說了關于WatiN的自動化的框架的設計,一般的系統應用應該可以。關于Case的本身的編寫在實際應用中也會有一些問題和難題。這一節我將 WatiN的彈出框作一下詳細的總結。在實際網頁中,操作按鈕可能彈出各種樣式的彈出框,如何進行有效的處理呢? 1、Alert Dialog Alert對話框很簡單,彈出之后只是一個提示作用,彈出之后進行確認即可。

public static void CaptureAlertDialog(this Browser browser, Action<AlertDialogHandler> operation, int waitTimeInSeconds)
{
??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<AlertDialogHandler> alert句柄、waitTimeSeconds 等待時間

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<ConfirmDialogHandler> operation, int waitTimeInSeconds)
{
??var handler = new ConfirmDialogHandler();
??using (new UseDialogOnce(browser.DialogWatcher, handler))
??{
????operation(handler);
????handler.WaitUntilExists(waitTimeInSeconds);
????if (handler.Exists())
????{
??????handler.OKButton.Click();//確認按鈕 handler.CancelButton.Click();取消按鈕
????}
??}
}

context.Browser.CaptureConfirmDialog((ConfirmDialogHandler handler) =>
{
btn.WaitUntilExistsAndClickNoWait(context.TestConfig.Timeout);
}, 5);


btn.WaitUntilExistsAndClickNoWait(context.TestConfig.Timeout);為Button點擊事件

3、文件下載對話框FileDownloadHandler

var btn = "獲取button按鈕";

var fileName = System.Windows.Forms.Application.StartupPath + "保存路徑文件名";
FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(fileName);
using (new UseDialogOnce(context.Browser.DialogWatcher, fileDownloadHandler))
{
??btn.WaitUntilExistsAndClickNoWait(context.TestConfig.Timeout);
??context.Browser.WaitUntil(5);
??fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(60);
??fileDownloadHandler.WaitUntilDownloadCompleted(200);
}

4、網頁對話框(window.open) 有的網頁對話框通過window.open的方式進行打開的是其他的頁面,比如通過其他的頁面進行添加分類等等,遇到此處的時候應該如何處理呢?其實這等窗口是頁 面,內容可以通過Browser對象來進行獲取。

首先需要將主瀏覽器對象進行保存,讓這個browser對象再打開新窗口,從中獲取窗口頁面的URL

如下代碼:

var orginBrowser = context.Browser;//context.Browser瀏覽器對象
try
{
??Div.Button(btn => btn.ClassName == "ButtonStyle").WaitUntilExistsAndClick(context.TestConfig.Timeout);//Button按鈕,進行onclick事件
??context.Browser.WaitUntil(3);//等待3秒
??context.Browser = WatiN.Core.Browser.AttachTo(context.Browser.GetType(), Find.ByUrl(url => url.IndexOf("頁面名稱") > -1), context.TestConfig.Timeout);//查找新窗口的頁面名稱
??context.Browser.Refresh();//進行刷新
??///
??///對窗口中的內容進行操作
??///
??context.Browser.Close();
}
catch { }
?context.Browser = orginBrowser;

在WatiN自動化測試中,一般遇到的彈出窗口也就上面的四種,基本上都可以解決網頁中的問題。

轉載于:https://www.cnblogs.com/stonespawn/archive/2011/04/08/2009341.html

總結

以上是生活随笔為你收集整理的WatiN——Web自动化测试(三)【弹出窗口处理】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。