利用NUnit和Watin进行web自动测试

来源:互联网 发布:金蝶初始数据如何录入 编辑:程序博客网 时间:2024/04/30 23:40

一两年前。从领导学习了一个进行自动测试的工具,很有意思,给大家介绍下。

1.首先,从官网上下载NUNIT和WATIN工具。

2.工具下载后,进行安装,两个工具安装成功后,在watin的bin目录中有Watin.core.dll,在NUNIT的bin目录中有nunit.framework.dll。这是两个很重要的库。

3.编写自动测试代码、无论你是采用VS2005还是VS2008,必须引用上面两个库。下面给大家编写个简单的测试方法:

using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WatiN.Core;
using NUnit.Framework;
namespace WatiNTest
{
    [TestFixture]
    public class WebTest
    {
        [Test]
        public void Test0001()
        {
          
            IE ie = new IE(http://passport.csdn.net/UserLogin.aspx
);//你想要测试的链接
            ie.WaitForComplete();
            ie.TextField(Find.ById("txtUser")).TypeText("你的邮件");
            ie.TextField(Find.ById("txtPassword")).TypeText("你的密码");
            ie.Button(Find.ById("btnLogin")).Click();
            Assert.AreEqual(true, ie.ContainsText("自己希望包含的文字"));
            ie.Close();

       
        }

    }
}

4.然后打开NUnit工具,加载刚才编写的工程的DLL文件,就可以运行了。感觉很是很爽的。

下面是我总结的watin方法列表:

利用NUnit和Watin进行web自动测试

这个是我截图的,可能不太清楚,如果有人想要的话,可以留下邮箱,我可以发给你。

原创粉丝点击