You are on page 1of 28

3.

28

SDB
WatiN

/10096

2012-11-15


DVP05T01 V2.8 /

SDB

Date

2012-11-15

Revision
Version

1.00

CR ID

Sec No.

Change Description

Author

CR

228

SDB


1.............................................................................................................................................5
1.1 ......................................................................................................................................... 5
1.2 ......................................................................................................................................... 5
1.3 ..........................................................................................................................5
2 Hello,The World! .........................................................................................................................5
3 ......................................................................................................................................7
3.1 Qaliber Developer Standalone ...............................................................................7
3.2 ...........................................................................................................9
4 WatiN ......................................................................................................................10
4.1 WatiN ..............................................................................................................10
4.2 WatiN ..........................................................................................................11
4.3 WatiN ..................................................................................................11
4.4 WatiN , , ......................................................................17
5 ....................................................................................................................................24

328

SDB

SDB
WaitNexplorer

428

SDB

1
1.1
SDBWatiNWatiN

1.2
WatiN Web watir C#
WatiN
2.0 Firefox http://watin.org/
Internet Explorer 6, 7, 8, 9 FireFox 2 3

1.3
Windows XpWindows 7
Microsoft Visual Studio 2010 QaliberWatiN

2 Hello,The World!
WatiN WatiN

Watin , Watin
WatiNTestTestCasesPackage(2-1)Watin.Core.dll(22)WatiN.Core(2-3)

2-1

528

SDB

2-2

2-3
SearchForWatiNOnBaidu()

628

SDB

public bool SearchForWatiNOnBaidu()


{
bool Ret = false;
//IEwww.baidu.com
IE ieBaidu = new IE("http://www.baidu.com", true);
//WatiN
//* Id"kw" TypeText

//*"WatiN"
ieBaidu.TextField(Find.ById("kw")).TypeText("WatiN");
//
//* Id"su" Click
//*
ieBaidu.Button(Find.ById("su")).Click();
//WatiN
Ret =ieBaidu.ContainsText("WatiN");
return Ret;
}

IE

3
3.1 Qaliber Developer Standalone
IdkwIdsu?

QAliber Developer Standalone IEIE (3-11)QAliber Developer Standalone3-1-2http://www.baidu.com

728

SDB

3-1-1

3-1-2
TextFields highlight control
IDkw nameclass(3-1-3)

3-1-3
Buttons highlight control
IDsu3-1-4

828

SDB

3-1-4

3.2
Qaliber IE
IE---3-1-53-1-6

3-1-5

3-1-6
<HTML>

928

SDB

<input name="wd" class="s_ipt" id="kw" type="text" maxLength="100" autocomplete="off"/>


idkw namewdclasss_ipt

3-1-7
<HTML>

<input class="s_btn" id="su" onmouseout="this.className='s_btn'" onmousedown="this.className='s_btn


s_btn_h'" type="submit" value=""/>
idsu

3-1-8

4 WatiN

4.1 WatiN
WatiN.Core: Watin

1028

SDB

WatiN.Core.DialogHandlers:
AlertDialogHandler,

ConfirmDialogHandler,

FileUploadDialogHandler,

PrintDialogHandler,

and

LogonDialogHandler
WatiN.Core.Exceptions:

ElementNotFoundException, IENotFoundException, TimeoutException, and a generic WatiNException

4.2 WatiN
IE : Web IE
Goto(string):
Close() :
ContainsText(string):
CaptureWebPageToFile(string): web
ClearCache(): Cache
ClearCookie(): Cookie

Find : web
ById() : id
ByName(): name

4.3 WatiN
<A>
<a> DOM Anchor Html
< a id ="baidu" href = "http://wwww.baidu.com"> </ a > Watin <a>
ie.Link(Find .Byid("baidu" )).Text;//
web href Find.ByUrl url

<input type="text">
<input type="text"> HTML DOM Text

1128

SDB

1228

SDB

< input id ="Text1" type ="text" /></ p >


Watin <a>
ie.TextField (Find .Byid(" Text1 " )).Value;//
ie.TextField (Find .Byid(" Text1 " )).TypeText("Watin" );// Watin
<input type="button">
<input type="button"> HTML DOM Button

1328

SDB

< input id ="btn" type ="button" /></ p >


Watin <a>
Ie.Button (Find .Byid(" btn " )).Text;//
ie.Button (Find .Byid(" btn " )).Click();//
<input type="checkbox">
<input type="Checkbox"> HTML DOM Checkbox
< input id ="chk" type ="checkbox" /></ p >
Watin <a>
d4t#t
ie.CheckBox (Find .Byid(" chk " )).Text;//
<area>
<area> HTML DOM area

< img src ="map/map.jpg" alt =" " width ="1004" height ="601"
border ="0" usemap ="#Map" />
< map name ="Map" id ="Map">
<

area

shape

="rect"

alt

="a1"

coords

="134,59,255,92"

href

="345,122,464,160"

href

="edushiMap.html" />
<

area

shape

="rect"

alt

="a2"

coords

="edushiMap.html" />
</ map >
Watin <area>
ie.Area(Find .ByAlt("a1" )).Url;//areaurl
ie.Area(Find .ById("area1" )).Click();//area
ie.Area(Find .ByAlt("a1" )).Click();//area
<Select>
<Select> HTML DOM Select

1428

SDB

< select id ="Select1">


< option > 1</ option >
< option > 2</ option >
</ select >
Watin <Select>
ie.SelectList(Find .ById("Select1" )).Select(string);//

1528

SDB

<table>
<table> HTML DOM table
< table style =" width :100% ;" id ="table1" class = "class1">
< tr >
< td class ="style1">
11</ td >
< td class ="style1">
&nbsp;
12</ td >
</ tr >
< tr >
< td >
21</ td >
< td >
&nbsp;
22</ td >
</ tr >
</ table >

1628

SDB

Watin <table>
ie.Table(Find .ByClass("class1" )).TableRows[0].TableCells[1].Text;//

4.4 WatiN , ,

web
< input id ="Button1" type ="button"

value

="button"

onclick

="openwindow()" />
< script type ="text/javascript">
function openwindow()
{
window.open("http://localhost/Test/test2.htm" );
}
</ script >
, Button1 , test2.htm. test2.htm
Watin :
IE ie =new IE ("http://localhost/Test/" );
//test2
confirm
web confirm
51Testing2oH

1728

SDB

< input id ="myButton1" type ="button" value ="this is a button" B d

1828

SDB

1928

SDB

{d)P FVy0
Console .ReadLine();
jk q%E l~
Alert
web Alert

2028

SDB

< input id ="myButton2" type ="button" value ="this is a button2"


Watin :

IE ie =new IE ("http://localhost/Test/" ); Ko
Fileupload
web Fileupload
< input id ="File1" type ="file" /></ p >
Watin :

2128

SDB

2228

SDB

IE ie =new IE ("http://localhost/Test/test2.htm" );
//
ie.FileUpload(Find .ById("File1" )).Set(@"D:/Data.txt" );

2328

SDB

5
linkedin
1Linkedin
1http://www.linkedin.com/5-1

5-1
2namesession_keyidsession_key-loginclass5-2

5-2
2namesession_passwordidsession_password-loginclass.5-3

5-3
3nameidbtn-loginclassbtn-secondary5-4

2428

SDB

5-4
2

//linkedin
IE ie = new IE("http://www.linkedin.com/", true);
//
ie.TextField(Find.ByName("session_key")).TypeText("SDBbyTest@126.com");
//
ie.TextField(Find.ById("session_password-login")).TypeText("dpidev");
//
ie.Button(Find.ByClass("btn-secondary")).Click();

2528

SDB

Html element

WatiN Class

WatiN Collection

Example

<a />

Link

LinkCollection

Ie.Link(linkId)

<area />

Area

AreaCollection

ie.Area(Find.ByAlt(alttext))

<button />

Button

ButtonCollection

Ie.Button(buttonId)

<div />

Div

DivCollection

Ie.Div(divId)

<form />

Form

FormCollection

Ie.Form(formId)

<frame />

Frame

FrameCollection

Ie.Frame(frameId)

<frameset />

FrameCollection

Ie.Frames

<iframe />

Frame

FrameCollection

Ie.Frame(iframeId)

<img />

Image

ImageCollection

Ie.Image(imageId)

<input type=button/>

Button

ButtonCollection

Ie.Button(buttonId)

<input type=checkbox/>

CheckBox

CheckBoxCollection

Ie.CheckBox(checkboxId)

<input type=file/>

FileUpload

FileUploadCollection

Ie.FileUpload(fileuploadId)

<input type=hidden/>

TextField

TextFieldCollection

Ie.TextField(hiddenId)

<input type=image/>

Button

ButtonCollection

Ie.Button(imageId)

<input type=image/>

Image

ImageCollection

Ie.Image(imageId)

<input type=password/>

TextField

TextFieldCollection

Ie.TextField(passwordId)

<input type=radio/>

RadioButton

RadioButtonCollection

Ie.RadioButton(radioId)

<input type=reset/>

Button

ButtonCollection

Ie.Button(resetId)

<input type=submit/>

Button

ButtonCollection

Ie.Button(submitId)

<input type=text/>

TextField

TextFieldCollection

Ie.TextField(textId)

<label />

Label

LabelCollection

Ie.Label(elementId)

<option />

Option

OptionCollection

Ie.Select(selectId).Options

<p />

Para

ParaCollection

Ie.Para(pId)

<select />

Select

SelectCollection

Ie.Select(selectId)

<span />

Span

SpanCollection

Ie.Span(spanId)

<table />

Table

TableCollection

Ie.Table(tableId)

<tbody />

TableBody

TableBodyCollection

Ie.TableBody(tablebodyId)
Ie.Table(tableid).TableBodies

2628

SDB
<td />

TableCell

TableCellCollection

Ie.TableCell(tablecellId) or
Ie.Table(TableId).TableRows[0].TableCells[0]

<textarea />

TextField

TextFieldCollection

Ie.TextField(textareaId)

<tr />

TableRow

TableRows

Ie.TableRow(tablerowId) or
Ie.Table(TableId).TableRows[0]

All elements, also the


ones not mentioned in
this list

Element and

ElementCollection

ElementsContainer

Ie.Element(elementId)
Ie.Element(tagname, elementId)

2728

SDB

ie.RemoveDialogHandler(adh);
Console .WriteLine(ie.Button(Find .ById("myButton2" )).Value);
Console .ReadLine();
51Testing)ZX!y R F
onclick ="alertMe(); return false;">< br />
< script >
function alertMe() {
var answer = alert("this is a alert dialog" );
if (answer)
document.getElementById("myButton2" ).value="Clicked OK" ;
}
</ script >
fl5j5Mm
51Testing4y Q g S-C y
if (answer)
document.getElementById("myButton1" ).value="Clicked OK" ;
else
document.getElementById("myButton1" ).value="Clicked Cancel" ;
}
</ script >
51TestingV UtS*EL9N'b
ie.Button(Find .ById("Button1" )).Click();
//test2IE
IE newie =IE .AttachTo<IE >(Find .ByTitle("test2" ));
//IE
newie.TextField(Find .ById("Text1" )).TypeText("this is new ie" );
ie.CheckBox (Find .Byid(" chk " )).Click();//
ie.CheckBox (Find .ById(" chk " )).Checked =true ;//Checkbox
ie.Link(Find .Byid("baidu" )).Url;//Url
ie.Link(Find .Byid("baidu" )).Click();//

2828