[转贴]watin的一些例子

Some WatiN Examples
Below are some examples of WatiN codes for testing:
// find div by id
var div = browser.Div("divId");
 
// find div by class
var div = browser.Div(Find.ByClass("divClass"));
 
// click a div
browser.Div("divId").Click();
 
// click a button
browser.Button("buttonId").Click();
 
// get <li></li> elements inside a div
var lisCollection= browser.Div("divId").ElementsWithTag("li");
// click the first <li></li>
lisCollection.FirstOrDefault().Click();
// click the one contains a particular inner text
lisCollection.Where(li => li.Text.Contains("some text")).FirstOrDefault().Click();
 
// get <a></a> elements inside a div
var links = browser.Links.Filter(a => a.Parent.Parent.Parent.ClassName == "divClass");
var links = browser.Links.Filter(a => a.Parent.Parent.Parent.Parent.Id == "divId");
 
// select from a select dropdown
browser.SelectList("selectId").Option("option text").Select();
 
// assert a div exists
Assert.IsTrue(browser.Div("divId").Exists);
 
// assert header(s) with a particular text exists
Assert.IsTrue(browser.ElementsWithTag("h1").Any(x => x.Text == "heading text"));
 
// assert only one header with a particular text exists
Assert.IsTrue(browser.ElementsWithTag("h3").Where(x => x.Text == "heading text").Count() == 1);
 
// assert a particular text exists inside a table td
Assert.IsTrue(browser.Table("tableId").TableCells.Any(x => x.Text == "text inside td"));

上一篇:EBS 系统当前完成请求时间监测


下一篇:《学习opencv》笔记——矩阵和图像操作——cvCalcCovarMatrix,cvCmp and cvCmpS