简介

WatiN-Watir.NET版:

http://watin.sourceforge.net/

WelcomeattheWatiN(pronouncedasWhat-in)website.InspiredbyWatirdevelopmentofWatiNstartedinDecember2005tomakeasimilarkindofWebApplicationTestingpossibleforthe.Netlanguages.SincethenWatiNhasgrownintoaneasytouse,featurerichandstableframework.WatiNisdevelopedinC#andaimstobringyouaneasywaytoautomateyourtestswithInternetExplorerandFireFoxusing.Net.

目前最新版本:WatiN2.0RC1

http://watin.sourceforge.net/releasenotes-2-0-20-1089.html

支持的测试环境:

WindowsXP

WindowsVista

Windows2003

Windows2008

IE6

OK

-

-

-

IE7

OK

-

-

OK

IE8

OK

-

-

-

Firefox2

OK

-

-

-

Firefox3

OK

-

-

OK

WatiN的脚本录制器-WatiNTestRecorder

http://watintestrecord.sourceforge.net/

.0beta版本需要IE7以上

WatiNvs.SeleniumRC

Item

WatiN

SeleniumRC

ExplorerSupported

Knownwork

IE6andIE7

Knownwork

IE6andIE7

Firefox1.5.0and2.0

Opera8.5.4and9.0.2

Shouldwork

Firefox0.8to2.0

MozillaSuite1.6+,1.7+

Seamonkey1.0

Systemsupported

Knownwork

WindowsXPand2003

Knownwork

WindowsXPand2003

Windows2000(needtoinstallinstallreg.exeinordertouseIE)

MacOSX

Linux

Languagesupported

C#

C#

Java

Perl

PHP

Python

Ruby

Testenvironmentsupported

VisualStudio2005TeamSystem

VisualStudio2005TeamSystem

AJAX

SupportsAJAXwebsitetesting

lSeleniumServercommunicatesdirectlywiththebrowserusingAJAX(XmlHttpRequest)

lTheSeleniumServerisgreatfortestingcomplexAJAX-basedwebuserinterfacesunderaContinuousIntegrationsystem

Get/Postrequests

WecansendcommandsdirectlytotheServerusingsimpleHTTPGET/POSTrequests

Httpssupported

Supportforhttps

JavascrīptSupported

VoidDocument.Runscrīpt(string)

lWecanwriteseleniumRCtestsinJavascrīptwithJsUnit.

litAllowsaSelenium-enabledbrowsertorunJavascrīptonarbitrarywebsites.

HTML

AutomatesallmajorHTMLelementsandfindelementsbymultipleattributes

HTMLdialogs

SupportsHTMLdialogs(modalandmodeless)

Frame

Supportsframe(Crossdomain)andiframes

Popupdialogs

Supportspopupdialogslikealert,confirm,loginetc

Screenshots

Supportcreatingscreenshotsofwebpages

对现有控件的兼容性不好。比如文件上传控件和日历控件就无法在SeleniumRC中捕捉
2.
不支持https连接方式??

http://bbs.51testing.com/thread-84131-1-6.html

DevelopingInfo

Item

WatiN

SeleniumRC

DevelopingLanguage

C#

Javaandsoon

MethodsExample

Item

WatiNExample

SeleniumRCExample

Setelement

event

Document.button(Find.ById(btnG”)).click()

DefaultSelenium.Type(“q”,”helloworld”)

Getelementattributes

Document.button(Find.ById(btnG”)).Style.Height

DefaultSelenium.GetElementHeight(“q”)

especialmethods

Thenwecan’thanlethetimeusedforpagesloading.

===》

Link[1].Click()

Link(Find.ByIndex(1)).Click()

Wecanusethesetwomethodstoclickthelinksthatthevalueisnull.

WaitForPageToLoad(“5000”)

(ifwewanttogotoanotherpageandgettheelementsinthenewpage,wehavetousethemethod,orwewillintheoldpage.)

==Wecan’tfindthelinksthatthevalueisnull

WatiN测试Google的例子

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingWatiN.Core;

usingSystem.Threading;

namespaceConsoleApplication1

{

classProgram

{

[STAThread]

staticvoidMain(string[]args)

{

//OpenanewInternetExplorerwindowand

//gotothegooglewebsite.

IEie=newIE("http://www.google.com.hk",true);

//FindthesearchtextfieldandtypeWatininit.

ie.TextField(Find.ByName("q")).TypeText("WatiN");

//ClicktheGooglesearchbutton.

ie.Button(Find.ByValue("Google搜索")).Click();

//Uncommentthefollowinglineifyouwanttoclose

//InternetExplorerandtheconsolewindowimmediately.

//ie.Close();

}

}

}

获取页面元素内容:

//OpenannewInternetExplorerWindowand

//gotothegooglewebsite.

IEie=newIE("http://www.google.com.hk",true);

//FindthesearchtextfieldandtypeWatininit.

ie.TextField(Find.ByName("q")).TypeText("WatiN");

//ClicktheGooglesearchbutton.

ie.Button(Find.ByValue("Google搜索")).Click();

//Findthetablecellwhichshowsthesearchresultstatistics.

Elementelement=ie.Element(Find.By("id","resultStats"));

stringresultStats=element.Text;

//Writethesestatisticstotheconsolewindow.

Console.WriteLine(resultStats);

//Uncommentthefollowinglineifyouwanttoclose

//InternetExplorerandtheconsolewindowimmediately.

//ie.Close();

参考:

GettingstartedwithWatiN

http://watin.sourceforge.net/gettingstarted.html

WatiNandThread.ApartmentState

http://watin.sourceforge.net/apartmentstateinfo.html

WatiN支持的页面元素

Htmlelement

WatiNClass

WatiNCollection

Example

Version

Link

LinkCollection

Ie.Link(linkId)

0.7

Area

AreaCollection

ie.Area(Find.ByAlt(alttext))

1.2

Button

ButtonCollection

Ie.Button(buttonId)

0.9

Div

DivCollection

Ie.Div(divId)

0.7

Form

FormCollection

Ie.Form(formId)

0.7

Frame

FrameCollection

Ie.Frame(frameId)

0.7

-

FrameCollection

Ie.Frames

0.7