【www.gdgbn.com--.Net开发】
asp.net ui 工具测试
当你测试的用户界面,你正在测试人类活动。正因为如此,你应该让计算机执行的任务
是很好的,你应该执行的任务的类型,你是好惹的。当开发人员和测试人员首先对可用
于测试的UI工具学习,他们往往认为一切都可以实现自动化,这是很远的现实。第7章本
书的测试ASP.NET Web应用程序[,由杰夫McWherter和本厅(书号:978-0-470-49664-0
,Wrox出版社,2009年,版权威利出版公司)]关于深入会谈,手工测试但现在重要的是
我们了解,手动测试仍是一个测试周期非常重要的测试纪律。
弗雷德里克布鲁克斯教授在题为“没有银弹 - 本质和软件工程事故,”1987年的软件开
发人员的文件,没有在软件开发银弹,这意味着,没有一个工具,可以解决整个工作你
希望完成。界面测试不应该被认为是最终所有即将所有的测试。当用户界面进行适当的
测试是一个非常强大的测试工具。
在您实现用户界面自动化测试的重要性,下一个最重要的决定提出的,是你的工具将使
用创建的测试。有三种思想流派如何测试用户界面。
模拟浏览器
这是一个无头一套脚本发送的请求来模拟浏览器相同类型的,但措施的响应时间,而不
内容表述,被送回。这种类型的UI测试是伟大的发现在Web应用的瓶颈。这一类型的测试
的缺点是,你不是研究和验证试验的反应情况。这种类型的测试只能用于量,压力和负
载测试方案。
网络容量分析工具(冷原子捕集)是一个轻量级的HTTP负载生成工具,目的是模拟的并
发用户数,提出请求到一个站点。冷原子捕集用简单的脚本来模拟浏览器和充分行使一
个网站:
新的交易
的classid = 1
新请求的HTTP
动词=“获得”
网址=“http://www.google.com”
using NUnit.Framework;
using System.Net;
using System.IO;
namespace ParseHttp
{
[TestFixture]
public class ParseHttp
{
[Test]
public void Should_Navigate_To_Google_And_Return_Results_For_AspNet()
{
string urlToTest =
"http://www.google.com/search?
hl=en&rlz=1G1GGLQ_ENUS295&q=asp.net&btnG=Search";
string result = GetPage(urlToTest);
Assert.IsTrue(result.IndexOf("The Official") >0, "Asp.net Page
");
}
private string GetPage(string urlToTest)
{
// create a web client object to load the page from local server
WebClient client = new WebClient();
string result = string.Empty;
// dump the contents of the page we navigated to into a stream
using (StreamReader reader = new
StreamReader(client.OpenRead(urlToTest)))
{
result = reader.ReadToEnd();
}
return result;
}
}
}
浏览器
在这个界面测试方法(如在未来上市),该测试将打开一个物理浏览器,执行的行为,
然后该测试将在测试验证您输入的标准为基础的HTML。这种自动界面测试类型是手动测
试最接近你会得到。由于测试需要打开浏览器,执行测试,并报告结果支持这一类型的
测试非常脆弱。这些类型的测试往往是复杂的,如果你的计划是只压力测试您的应用程
序这种类型的测试将是矫枉过正:
using NUnit.Framework;
using WatiN.Core;
using WatiN.Core.Interfaces;
namespace SimpleWatinTest
{
[TestFixture]
public class SimpleWatinTests
{
[Test]
public void
Should_Click_Search_On_Google_And_Return_Results_For_AspNet()
{
using (IBrowser ie =
BrowserFactory.Create(BrowserType.InternetExplorer))
{
ie.GoTo("http://www.google.com");
ie.TextField(Find.ByName("q")).Value = "asp.net";
ie.Button(Find.ByName("btnG")).Click();
Assert.IsTrue(ie.ContainsText
("The Official Microsoft ASP.NET Site"));
}
}
}
}
using NUnit.Framework;
using WatiN.Core;
using WatiN.Core.Interfaces;
namespace SimpleWatinTest
{
[TestFixture]
public class SimpleWatinTests
{
[Test]
public void
Should_Click_Search_On_Google_And_Return_Results_For_AspNet()
{
using (IBrowser ie =
BrowserFactory.Create(BrowserType.InternetExplorer))
{
ie.GoTo("http://www.google.com");
ie.TextField(Find.ByName("q")).Value = "asp.net";
ie.Button(Find.ByName("btnG")).Click();
Assert.IsTrue(ie.ContainsText
("The Official Microsoft ASP.NET Site"));
}
}
}
}
Below is a table of how HTML elements can be obtained using the WatiN
framework.WatiN HTML Mapping:
HTML ELEMENT WatiN Class Example
Link Ie.Link(linkId)
Button Ie.Button(buttonId)
Div Ie.Div(divId)
<frame /> Frame
Ie.Frame(frameId)
<iframe /> Frame Ie.Frame(iframeId)
Image Ie.Image(imageId)
Button Ie.Button(buttonId)
CheckBox Ie.CheckBox(checkboxId)
FileUpload Ie.FileUpload(fileuploadId)
Image Ie.Image(imageId)
word/> TextField Ie.TextField(passwordId)
RadioButton Ie.RadioButton(radioId)
Button Ie.Button(submitId)
TextField Ie.TextField(textId)
Label
Ie.Label(elementId)
Option Ie.Select(selectId).Options
Para Ie.Para(pId)
Select Ie.Select(selectId)
Table Ie.Table(tableId)
TableBody Ie.TableBody(tablebodyId)
Ie.Table(tableid).TableBodies
TableCell Ie.TableCell(tablecellId)
Ie.Table(TableId).TableRows[0].TableCells[0]
TextField Ie.TextField(textareaId)
TableRow Ie.TableRow(tablerowId)
Ie.Table(TableId).TableRows[0]
All elements, also the ones not mentioned in this list Element and
ElementsContainer Ie.Element(elementId)
Ie.Element(tagname, elementId)