?
簡介
WatiN - Watir 的 .NET 版:
Welcome at the WatiN (pronounced as What-in) website . Inspired ? by Watir development of WatiN started in December 2005 to make a similar kind of Web Application Testing possible for the .Net languages. Since then WatiN has grown into an easy to use, feature rich and stable framework. WatiN is developed in C# and aims to?bring you?an easy way to automate your tests with Internet Explorer and FireFox using .Net.
?
目前最新版本: WatiN 2.0 RC 1
http://watin.sourceforge.net/releasenotes-2-0-20-1089.html
?
支持的測試環(huán)境:
? |
Windows XP |
Windows Vista |
Windows 2003 |
Windows 2008 |
IE 6 |
OK |
- |
- |
- |
IE 7 |
OK |
- |
- |
OK |
IE 8 |
OK |
- |
- |
- |
Firefox 2 |
OK |
- |
- |
- |
Firefox 3 |
OK |
- |
- |
OK |
?
?
WatiN? 的腳本錄制器 - WatiN Test Recorder :
http://watintestrecord.sourceforge.net/ ?
?
2.0 beta 版本需要 IE7 以上
?
WatiN vs. Selenium RC
Item |
WatiN |
Selenium RC |
Explorer Supported |
Known work ? ? IE 6 and IE 7 |
Known work ? ? IE 6 and IE 7 ? ? Firefox 1.5.0 and 2.0 ? ? Opera 8.5.4 and 9.0.2 Should work ? ? Firefox 0.8 to 2.0 ? ? Mozilla Suite 1.6+, 1.7+ ? ? Sea monkey 1.0 |
System supported |
Known work ? ? Windows XP and 2003 |
Known work ? ? Windows XP and 2003 ? ? Windows 2000(need to install install reg.exe in order to use IE) ? ? Mac OS X ? ? Linux |
Language supported |
? ? C# |
? ? C# ? ? Java ? ? Perl ? ? PHP ? ? Python ? ? Ruby |
Test environment supported |
? ? Visual Studio 2005 Team System |
? ? Visual Studio 2005 Team System |
AJAX |
Supports AJAX website testing |
l ? Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest) l ? The Selenium Server is great for testing complex AJAX-based web user interfaces under a Continuous Integration system |
Get/Post requests |
? |
We can send commands directly to the Server using simple HTTP GET/POST requests |
Https supported |
? |
Support for https |
Java scrīpt Supported |
Void Document.Runscrīpt(string) |
l ? We can write selenium RC tests in Javascrīpt with JsUnit. l ? it Allows a Selenium-enabled browser to run Javascrīpt on arbitrary websites. |
HTML |
Automates all major HTML elements and find elements by multiple attributes |
? |
HTML dialogs |
Supports HTML dialogs (modal and modeless) |
? |
Frame |
Supports frame (Cross domain) and iframes |
? |
Popup dialogs |
Supports popup dialogs like alert, confirm, login etc |
? |
Screenshots |
Support creating screenshots of web pages |
? |
? |
? |
對現(xiàn)有控件的兼容性不好。比如
文件上傳
控件和日歷控件就無法在
Selenium RC
中捕捉
http://bbs.51testing.com/thread-84131-1-6.html |
?
Developing Info
Item |
WatiN |
Selenium RC |
Developing Language |
? ? C# |
? ? Java and so on |
?
Methods Example
Item |
WatiN Example |
Selenium RC Example |
Set ? element event |
Document.button(Find.ById(btnG”)).click() |
DefaultSelenium.Type(“q”,”hello world”) |
Get element attributes |
Document.button (Find.ById(btnG”)) .Style. Height |
DefaultSelenium. GetElementHeight (“q”) |
especial methods |
????????????????????????????? Then we can’t hanle the time used for pages loading. ?????????????????????????? === 》 ? ? ? ? ? Link[1].Click() ? ? Link(Find.ByIndex(1)).Click() We can use these two methods to click the links that the value is null. |
? ? WaitForPageToLoad(“5000”) (if we want to go to another page and get the elements in the new page, we have to use the method, or we will in the old page.) ? ? 《 == ??? We can’t find the links that the value is null |
?
?
WatiN 測試 Google 的例子
?
using System;
using System.Collections.Generic;
using System.Text;
?
using WatiN.Core;
using System.Threading;
?
namespace ConsoleApplication1
{
? ?? class Program
??? {
??????? [ STAThread ]
??????? static void Main( string [] args)
??????? {
??????????? // Open a new Internet Explorer window and
??????????? // goto the google website.
??????????? IE ie = new IE ( "http://www.google.com.hk" , true );
?
???? ??????? // Find the search text field and type Watin in it.
??????????? ie.TextField( Find .ByName( "q" )).TypeText( "WatiN" );
?
??????????? // Click the Google search button.
??????????? ie.Button( Find .ByValue( "Google 搜索" )).Click();
?
??????????? // Uncomment the following line if you want to close
??????????? // Internet Explorer and the console window immediately.
??????????? //ie.Close();
??????? }
??? }
?
}
?
獲取頁面元素內(nèi)容:
??????????? // Open an new Internet Explorer Window and
??????????? // goto the google website.
??????????? IE ie = new IE ( "http://www.google.com.hk" , true );
?
??????????? // Find the search text field and type Watin in it.
??????????? ie.TextField( Find .ByName( "q" )).TypeText( "WatiN" );
?
??????????? // Click the Google search button.
??????????? ie.Button( Find .ByValue( "Google 搜索" )).Click();
?
??????????? // Find the table cell which shows the search result statistics.
??????????? Element element = ie.Element( Find .By( "id" , "resultStats" ));
??????????? string resultStats = element.Text;
?
??????????? // Write these statistics to the console window.
??????????? Console .WriteLine(resultStats);
?
??????????? // Uncomment the following line if you want to close
??????????? // Internet Explorer and the console window immediately.
??????????? //ie.Close();
?
參考:
Getting started with WatiN
http://watin.sourceforge.net/gettingstarted.html
WatiN and Thread.ApartmentState
http://watin.sourceforge.net/apartmentstateinfo.html
?
?
WatiN 支持的頁面元素
?
Html element |
WatiN Class |
WatiN Collection |
Example |
Version |
? |
? |
? |
? |
? |
<a /> |
Link |
LinkCollection |
Ie.Link(linkId) |
0.7 |
<area /> |
Area |
AreaCollection |
ie.Area(Find.ByAlt(alttext)) |
1.2 |
<button /> |
Button |
ButtonCollection |
Ie.Button(buttonId) |
0.9 |
<div /> |
Div |
DivCollection |
Ie.Div(divId) |
0.7 |
<form /> |
Form |
FormCollection |
Ie.Form(formId) |
0.7 |
<frame /> |
Frame |
FrameCollection |
Ie.Frame(frameId) |
0.7 |
<frameset /> |
- |
FrameCollection |
Ie.Frames |
0.7 |
<iframe /> |
Frame |
FrameCollection |
Ie.Frame(iframeId) |
0.9 |
<img /> |
Image |
ImageCollection |
Ie.Image(imageId) |
0.7 |
<input type=button/> |
Button |
ButtonCollection |
Ie.Button(buttonId) |
0.7 |
<input type=checkbox/> |
CheckBox |
CheckBoxCollection |
Ie.CheckBox(checkboxId) |
0.7 |
<input type=file/> |
FileUpload |
FileUploadCollection |
Ie.FileUpload(fileuploadId) |
0.9 |
<input type=hidden/> |
TextField |
TextFieldCollection |
Ie.TextField(hiddenId) |
0.7 |
? |
? |
? |
? |
no longer supported as of 2.0 beta 1 |
<input type=image/> |
Image |
ImageCollection |
Ie.Image(imageId) |
0.9.5 |
<input type=password/> |
TextField |
TextFieldCollection |
Ie.TextField(passwordId) |
0.7 |
<input type=radio/> |
RadioButton |
RadioButtonCollection |
Ie.RadioButton(radioId) |
0.7 |
<input type=reset/> |
Button |
ButtonCollection |
Ie.Button(resetId) |
0.7 |
<input type=submit/> |
Button |
ButtonCollection |
Ie.Button(submitId) |
0.7 |
<input type=text/> |
TextField |
TextFieldCollection |
Ie.TextField(textId) |
0.7 |
<label /> |
Label |
LabelCollection |
Ie.Label(elementId) |
0.7 |
<option /> |
Option |
OptionCollection |
Ie.Select(selectId).Options |
1.0 |
<p /> |
Para |
ParaCollection |
Ie.Para(pId) |
0.7 |
<select /> |
Select |
SelectCollection |
Ie.Select(selectId) |
0.7 |
<span /> |
Span |
SpanCollection |
Ie.Span(spanId) |
0.7 |
<table /> |
Table |
TableCollection |
Ie.Table(tableId) |
0.7 |
<tbody /> |
TableBody |
TableBodyCollection |
Ie.TableBody(tablebodyId) Ie.Table(tableid).TableBodies |
1.0 |
<td /> |
TableCell |
TableCellCollection |
Ie.TableCell(tablecellId) or Ie.Table(TableId).TableRows[0].TableCells[0] |
0.7 |
<textarea /> |
TextField |
TextFieldCollection |
Ie.TextField(textareaId) |
0.7 |
<tr /> |
TableRow |
TableRows |
Ie.TableRow(tablerowId) or Ie.Table(TableId).TableRows[0] |
0.7 |
All elements, also the ones not mentioned in this list |
Element and ElementsContainer |
ElementCollection |
Ie.Element(elementId) Ie.Element(tagname, elementId) |
0.9 ? 1.2 |
?
HTML Mapping Table
http://watin.sourceforge.net/htmlelementmapping.html
?
WatiN 中所有的控件以及控件的識別方法
在 WatiN 的源代碼中可以看到所有的控件識別設(shè)計類都是在繼承了與 element 相關(guān)的類
包括 Element, ElementAttributeBag, ElementCollection, ElementContainer, ElementSupport, ElementTag 。
首先來看 Element 的類可以看到它繼承 IAttributeBag 類 , 在 Elemental 類中寫到的方法有 :
1. Classname: Get the name of the stylesheet class assigned to this element; 得到傳輸給此控件默認(rèn)格式類的名稱。返回值為 string.
2. Complete: Boolean Value, Get a value indicating whether the element is completely loaded; 得到一個波爾值 , 查看是否此對當(dāng)前控件的操作完全加載。返回值為波爾值 .
3. Enabled: Get a Value indicating whether this element is enabled. 得到一個波爾值來確認(rèn)當(dāng)前的控件是否是可用的 . 返回值為波爾值 .
4. ID: Get the if of this element as specified in the HTML , 返回當(dāng)前控件在此 HTML 頁面中的識別 ID, 返回值為 string 。
5.TEXT: Get the inner text of this element(or all the inner text of all the elements contained in this elment). 返回當(dāng)前控件中的文本 , 或者是返回當(dāng)前控件所包含的控件中的所有文本 , 返回值為 string.
6.TextBefore: Returns the text displayed before this element when it ’ s wrapped in a Label element, otherwise it returns null. 返回當(dāng)前控件前面的 Label 的文本內(nèi)容 , 如果當(dāng)前控件前面的控件不是 Label 則返回 null, 返回值為 string.
7. InnerHtml: Gets the inner HTML of this element. 返回當(dāng)前控件的內(nèi)部 HTML 代碼。返回值不用說當(dāng)然為 string.
8. OuterText: Gets the outer text, 返回外部文檔 , 返回值為 string.
??? Shit, 這個控件我還真不知道怎么用 , 呵呵。查了一下解釋如下:
InnerText: 不包括標(biāo)志,標(biāo)志以內(nèi)的純文本 ??
? OuterText: 包括標(biāo)志,連標(biāo)記及標(biāo)志內(nèi)的文本 ??
? InnerHtml: 不包括標(biāo)志,標(biāo)志以內(nèi)的 Html 內(nèi)容 ??
? OuterHtml: 包括標(biāo)志,連標(biāo)記及標(biāo)志內(nèi)的 Html 內(nèi)容
9. TagName: Gets the tag name of this element 返回當(dāng)前控件的標(biāo)簽。返回值為 string.
10. Title: Get the title. 返回當(dāng)前頁面的標(biāo)題。返回值為 stieng.
11. NextSibling: Gets the next sibling of this element in the Dom of the HTML page. 返回當(dāng)前標(biāo)簽在此 HTML 頁面 Dom 控件中的下一個兄弟控件。返回值為控件即 (element)
12. PreviousSibling: Gets the previous sibling of this element in the Dom of the HTML page. 返回當(dāng)前標(biāo)簽在此 HTML 頁面 Dom 控件中的下一個兄弟控件 , 返回值為控件即 (element) 。
13. Parent: Gets the parent element of this element, If the parent type is known you can cast it to that type. 返回當(dāng)前控件的父級控件 , 如果父級的控件類型知道 , 可以定義一個和父級同類型的變量控件。返回類型為控件 (element). 這個比較難理解 , 下面是舉例 :
????? Div
??????? a id="watinlink" /
????????????????? a /
??????? Div
????? 上面的 HTML 所示第二個超鏈接沒有 id, 如何點擊它來實現(xiàn)超鏈接?這時可以使用 Parent 這個方法 :
???????? 首先定義一個變量 Div, 然后把這兩個超鏈接所在的 div 賦值給這個 Division 變量。
? Div watinDiv = ie.Link(“watinlink”).Parent;
然后去找第二個 Link, 可以把第一個 Link 看做是 Links[0], 那么第二個 Link 就是 Link[1]
watinDiv.Links[1].Click();
14.Style: Style is the element ’ s style, 返回當(dāng)前控件的格式。返回類型為 Style.
15.GetAttributeValue: This method can be used is the attribute is not available as a property of the element of a subclass of the element. Need a parameter’attributeName’, this parameter should be the name of the property exposed by IE on it’s element object. The return is the value of the attribute if available, otherwise null is returned. 當(dāng)控件的屬性不存在或者或者屬性屬于此控件的一個子類時此方法可以使用。但是需要傳遞給此方法一個參數(shù)即屬性名稱 ( 它應(yīng)該是被 IE 暴露的一個空間實體 ), 返回值為控件的屬性值或者為 null.
16. ToString: Returns a string that represents the current object, or null. 返回代表當(dāng)前實體的值 , 如果沒有則返回空。返回類型為 string.
17.Click: Click this element and waits till the event is completely finished(Page is loaded and ready). 點擊當(dāng)前控件然后等待 , 知道整個事件完成即 : 頁面被完全加載。無返回值 .
18.ClickNoWait: Click this instance and returns immediately. Use this method when you want to continue without waiting for the click event to be finished. Mostly used when a HTML Dialog is displayed after clicking the element. 觸發(fā)事件并立刻返回信息然后去判斷需要如何執(zhí)行 , 通常是在點擊或者跳轉(zhuǎn)頁面還沒完成時你需要其它操作。一般情況下是在當(dāng)彈出對話框時使用這個方法。無返回值。
19.Focus: Gives the input focus to this element. 聚焦在當(dāng)前這個輸入控件,我不是很明白這個方法。無返回值。
20.DoubleClick: Doubleclicks this element. 雙擊當(dāng)前的控件。無返回值。
21.KeyDown, KeyPress, KeyUp 三個方法分別為按下鍵盤不放 , 按一下鍵盤 , 和松開按鍵盤。很繞口 . 這個應(yīng)該是從 .Net 繼承的。
22. Blur: Fires the blur event on this element. 這個應(yīng)該是和 focus 相反的方法。取消對這個控件的 focus.
?
?
QTP + WatiN
?
Set IE = DotNetFactory.CreateInstance("WatiN.Core.IE","C:\Documents and Settings\Administrator\
桌面
\WatiN-2.0.10.928-net-2.0\WatiN-2.0.10.928-net-2.0\bin\WatiN.Core.dll")
Set Find=DotNetFactory.CreateInstance("WatiN.Core.Find","C:\Documents and Settings\Administrator\
桌面
\WatiN-2.0.10.928-net-2.0\WatiN-2.0.10.928-net- 2.0\bin\WatiN.Core.dll")
IE.GoTo("
http://www.zbitedu.com
")
IE.WaitForComplete
IE.TextField(Find.ByName("searchkey")).TypeText("vbs
測試
webservice")
IE.Button(Find.ByName("subjectsearch")).Click()
Set?? IEpage = IE.AttachToIE(Find.ByUrl("
http://www.zbitedu..com
"))
Set LinkObj = IEpage. Link(Find.ByUrl("
http://www.zbitedu.com/
)
IF LinkObj.Exists??? Then
???? LinkObj.Click()
?? ' IE.AttachToIE(Find.ByUrl("
http://www.zbiteducom
)
?? Set? ConsoleObj= DotNetFactory.CreateInstance("System.Console","System")
?? Consoleobj.Write("PASS")
???? ' Msgbox("PASS")
else
????????? Msgbox("FAILL")
End If
IE.Close
IEpage.Close
IE.AttachToIE(Find.ByUrl("
http://www.zbitedu.com).Close
?
?
WatiN 中常用的類
?
WatiN.Core.Find
最普遍使用的類就是
Find
類的,它是一個工廠類,主要使用它的靜態(tài)方法來實現(xiàn)一些查詢條件。比如像上面的例子中的這個語句
“ie.Button(Find.ByName("btnG")).Click();”
就調(diào)用了
Find
的靜態(tài)方法
ByName
來查詢一個
name
屬性為指定值的
HTML
元素,然后再調(diào)用
IE
對象的
Button
方法把這個元素轉(zhuǎn)換為按鈕對象。
WatiN.Core.IE
這應(yīng)該是最關(guān)鍵的類了。他常用的方法是和屬性為
屬性
HtmlDialogs
返回當(dāng)前對象用
JavaScript
打開的模式窗口(需然幫助文檔中說非模式窗口也包括在內(nèi),但在試用中發(fā)現(xiàn)用
window.open
打開的窗口沒有被)
Frames
返回當(dāng)前的象里的所有
Frames
方法
靜態(tài)方法
AttachToIE
與一個已經(jīng)找開的
IE
關(guān)連。
Button,TextField,Image,Div
等一系列方法。與
Find
對象共同使用用于返回
IE
中特定的按鈕,輸入框,等
HTML
元素。
WatiN 應(yīng)用中的一些技巧
1 、如何去捕獲一個新彈出的窗口。
背景:有些鏈接是從一個新彈出的窗口中打開的,我如果關(guān)連上這類型的窗口。
方案:下面以一個具體例子為例。系統(tǒng)中有一個登陸界面:
login.aspx
登陸成功能后會調(diào)用
JAVASCRIPT
的
window.open
方法打開系統(tǒng)的主窗口,然后關(guān)閉當(dāng)前這個窗
login.aspx
。
剛開始時,我的代碼是這樣寫的
? ?? ???public void Login(string uid, string passwd)
? ?? ???{
? ?? ?? ?? ?string url = Host + "login.aspx";
? ?? ?? ?? ?ie = new IE();
? ?? ?? ?? ?ie.GoTo(url);
? ?? ?? ?? ?ie.WaitForComplete();
? ?? ?? ?? ?ie.TextField(Find.ById("txtUserName")).Value = uid;
? ?? ?? ?? ?ie.TextField(Find.ById("txtPwd")).Value = passwd;
? ?? ?? ?? ?ie.Button(Find.ById("btnLogin")).Click;//
注意這里,我每次執(zhí)行到這里都出錯。下面會說明原因。
? ?? ?? ?? ?ie = IE.AttachToIE(Find.ByTitle(new WatiN.Core.Comparers.RegexComparer(new System.Text.RegularExpressions.Regex(".*
綜合信息系統(tǒng)
.*"))));
? ?? ?? ?? ?ie.WaitForComplete();
? ?? ?? ?? ?MainFrame = ie.Frame(Find.ByName("MainFrame_00001"));
? ?? ?? ?? ?MenuFrame = ie.Frame(Find.ById("leftMenu"));
? ?? ???}
看到上面的注譯沒有?那么執(zhí)行完后
WatiN
都會出現(xiàn)一個等待完成超時的異常,這是因為點擊了登陸按鈕后,如果登陸成功的話,系統(tǒng)已經(jīng)把這個窗口關(guān)閉了,因為它根本不可能完成。呵呵
~~```
所以要修改一下。
? ?? ???public void Login(string uid, string passwd)
? ?? ???{
? ?? ?? ?? ?string url = Host + "frmlogon.aspx";
? ?? ?? ?? ?ie = new IE();
? ?? ?? ?? ?ie.GoTo(url);
? ?? ?? ?? ?ie.WaitForComplete();
? ?? ?? ?? ?ie.TextField(Find.ById("txtUserName")).Value = uid;
? ?? ?? ?? ?ie.TextField(Find.ById("txtPwd")).Value = passwd;
? ?? ?? ?? ?ie.Button(Find.ById("btnLogin")).ClickNoWait();//
這個方法改成這樣,那點擊后就不會等代碼
IE
完成了。
? ?? ?? ?? ?//
下面這句就是處理登陸的技巧所在,系統(tǒng)打開了另一個窗口。
? ?? ?? ?? ?//
下面這句就是用正則表達式捕獲這個窗口。
? ?? ?? ?? ?ie = IE.AttachToIE(Find.ByTitle(new WatiN.Core.Comparers.RegexComparer(new System.Text.RegularExpressions.Regex(".*
綜合信息系統(tǒng)
.*"))));
? ?? ?? ?? ?ie.WaitForComplete();
? ?? ?? ?? ?MainFrame = ie.Frame(Find.ByName("MainFrame_00001"));
? ?? ?? ?? ?MenuFrame = ie.Frame(Find.ById("leftMenu"));//
把系統(tǒng)里的
Frame
先保存下來。
? ?? ???}
2 、對于 alert 、 confirm 等 javascript 彈出的窗口的捕獲。
背景:一個系統(tǒng)經(jīng)常會使用以上這些
javascript
來彈出一些提示信息,如果捕獲這些窗口,并模擬用戶點擊這些窗口上的
OK
或
Cancel
按鈕?
方案:其實
WatiN
在默認(rèn)情況下,都會自動地去點擊這些彈出式窗口上的
Cancel
按鈕的,但如果用戶要明確點擊哪些事件的話可以對
IE
對象增加一個
“
查看器
”
()
//
錯誤事例
? ?? ???protected void f()
? ?? ???{
? ?? ?? ?? ?WatiN.Core.DialogHandlers.ConfirmDialogHandler dh = new WatiN.Core.DialogHandlers.ConfirmDialogHandler();
? ?? ?? ?? ?ie.AddDialogHandler(dh);//
這句增加了一個控制器
? ?? ?? ?? ?/**/
? ?? ?? ?? ?/*
? ?? ?? ?? ?? ???
假設(shè)
yzp_dic_btn_cls
這個按鈕的
onclick
事件會用
JS
彈出一個
Confirm
窗口。
? ?? ?? ?? ?? ???
錯誤,測會在這里彈出一個窗口,然后等待用戶進行操作(隨便點擊一個按鈕才繼續(xù)執(zhí)行)
? ?? ?? ?? ?? ???
然后因為用戶已經(jīng)點擊了按鈕關(guān)閉
彈出窗口。下一句的
dh.WaitUntilExists(3);
將會超時,拋出異常
? ?? ?? ?? ?? ???*/
? ?? ?? ?? ?doc.Button(Find.ByName("yzp_dic_btn_cls")).Click();
? ?? ?? ?? ?dh.WaitUntilExists(3);//
等待彈出窗口的出來。最多等三秒。
? ?? ?? ?? ?dh.OKButton.Click();//
點擊這個窗口的
OK
按鈕
? ?? ?? ?? ?ie.RemoveDialogHandler(dh);
? ?? ?? ?? ?doc.Button(Find.ByName("btn_close")).Click();
? ?? ???}
正確的示例應(yīng)該是:
protected void f()
? ?? ???{
? ?? ?? ?? ?WatiN.Core.DialogHandlers.ConfirmDialogHandler dh = new WatiN.Core.DialogHandlers.ConfirmDialogHandler();
? ?? ?? ?? ?ie.AddDialogHandler(dh);
? ?? ?? ?? ?doc.Button(Find.ByName("yzp_dic_btn_cls")).ClickNoWait();//
把原來的
Click
改成這個方法。
? ?? ?? ?? ?dh.WaitUntilExists(3);//
等待彈出窗口的出來。最多等三秒。
? ?? ?? ?? ?dh.OKButton.Click();//
點擊這個窗口的
OK
按鈕
? ?? ?? ?? ?ie.RemoveDialogHandler(dh);
? ?? ?? ?? ?doc.Button(Find.ByName("btn_close")).Click();
? ?? ???}
3 、關(guān)于用 JS 彈出的 Modal 窗口(模式窗口)的處理 .
背景:有些地方需要彈出模式窗口來處理數(shù)據(jù)。
方解:當(dāng)點擊了彈出模式窗口的按鈕或連接后馬上用
IE
對像的
HtmlDialogs
屬生來獲取模式窗口。
? ?? ?? ?protected void f()
? ?? ???{
? ?? ?? ?? ?//
假設(shè)下面這行代碼會彈出一個模式窗口把原來的
Click
改成這個方法。
? ?? ?? ?? ?//
記住這里要用
ClickNoWait
而不能用
Click
,否則在模式窗口關(guān)閉之前代碼不會繼續(xù)執(zhí)行。
? ?? ?? ?? ?ie.Button(Find.ByName("yzp_dic_btn_cls")).ClickNoWait();
? ?? ?? ?? ?ie.HtmlDialogs[ie.HtmlDialogs.Length - 1].TextField(Find.ByName("Q")).Value = "Hello";
? ?? ?? ?? ?ie.HtmlDialogs[ie.HtmlDialogs.Length - 1].Button(Find.ByName("btn_query")).Click();
? ?? ???}
WatiN 插件 – QAliber
http://www.qaliber.net/Wiki/index.php?title=WatinN_Plug-in
?
Qaliber 主頁:
作者: Benny Cohen
包括兩個版本,其中 QAliber Test Developer 版本作為 VS.NET 的插件使用:
QAliber Test Developer (free open source) is a Visual Studio plug-in.
Create test cases as an integral part of your development solution.
QAliber Test Builder (free open source) is a robust testing framework for creating and executing tests with no coding skills.
?
TestAndTry.com 對這款工具的評價是“ Very Fast GUI Automation With Free QAliber ”:
http://www.testandtry.com/2010/03/04/very-fast-gui-automation-with-free-qaliber/
?
主要特點:
Create test cases as an integral part of your development solution.
Create GUI / API level test quick!
Record / Play GUI automation.
Supports Win32 / .NET forms / WPF / WEB GUI testing.
Run on all windows platforms with .NET framework 3.0 and up (XP,Vista,Win 7)
Write C#/VB.net code, use the .NET framework capabilities.
?
下載地址:
http://sourceforge.net/projects/qaliber/files/
?
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
