c# WaitN编写自动化测试

1)下载WatiN.Core.dll和Interop.SHDocVw.dll,下载地址http://download.csdn.net/detail/czh4869623/4584335

2)用VS创建测试项目(File—New—Project—Test—Test Project)

3) 添加引用:在项目中添加文件夹dll然后将WatiN.Core.dll和Interop.SHDocVw.dll放入dll文件夹中,然后添加WatiN.Core.dll引用。

4)编写代码如下

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WatiN.Core;

namespace TestProject7
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            //打开baidu
            using (IE ie = new IE("http://www.baidu.com"))
            {
                //给id为kw的文本框添加文字hyddd
                ie.TextField(Find.ById("kw")).TypeText("hyddd");
                //单击id为su的按钮
                ie.Button(Find.ById("su")).Click();
                //判断打开的页面时否包含“hyddd - 博客园”
                Assert.IsTrue(ie.ContainsText("hyddd - 博客园"));
                ie.Link(Find.ByText("hyddd - 博客园")).Click();
            }
        }
    }
}


5)按F5查看结果。

你可能感兴趣的:(IE,测试,C#,File,Class,dll)