WatiN开发用于测试WEB应用程序
公司要求所有人员必须使用自己的WEB产品,研发人员更不能例外,要命的是公司之前开发的用户行为及活跃度统计工具这会成了统计公司内部人员使用自己产品活跃度的一个工具了,而且BOSS会将活跃度记录隔段时间发出来抄送给大家,我并非讨厌自己的产品,只是对于这种强制性的要求有些反感,便想写一个工具自己跑,受应用于Ruby的WatiR启发,便在Google上搜了下找到.Net版的WatiN。于是下面的工作就开始了。
下面示例以模拟用百度搜索“WatiN”为例;
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using WatiN.Core;
5 using System.Diagnostics;
6
7 namespace Bino.LoginMail
8 {
9 class demo
10 {
11 public static void SearchForIE()
12 {
13 string strSearchKey = "WatiN";
14 string strUrl = "www.baidu.com";
15 Browser ie = new IE();
16 ie.GoTo(strUrl);
17 ie.TextField(Find.ById("kw")).Value = strSearchKey;
18 ie.Button(Find.ById("su")).Click();
19 Debug.Assert(ie.ContainsText(strSearchKey));
20 }
21
22 public static void SearchForFF()
23 {
24 string strSearchKey = "WatiN";
25 string strUrl = "www.baidu.com";
26 Browser ff = new FireFox();
27 ff.GoTo(strUrl);
28 ff.TextField(Find.ById("kw")).Value = strSearchKey;
29 ff.Button(Find.ById("su")).Click();
30 Debug.Assert(ff.ContainsText(strSearchKey));
31 }
32
33 }
34 }
35
2 using System.Collections.Generic;
3 using System.Text;
4 using WatiN.Core;
5 using System.Diagnostics;
6
7 namespace Bino.LoginMail
8 {
9 class demo
10 {
11 public static void SearchForIE()
12 {
13 string strSearchKey = "WatiN";
14 string strUrl = "www.baidu.com";
15 Browser ie = new IE();
16 ie.GoTo(strUrl);
17 ie.TextField(Find.ById("kw")).Value = strSearchKey;
18 ie.Button(Find.ById("su")).Click();
19 Debug.Assert(ie.ContainsText(strSearchKey));
20 }
21
22 public static void SearchForFF()
23 {
24 string strSearchKey = "WatiN";
25 string strUrl = "www.baidu.com";
26 Browser ff = new FireFox();
27 ff.GoTo(strUrl);
28 ff.TextField(Find.ById("kw")).Value = strSearchKey;
29 ff.Button(Find.ById("su")).Click();
30 Debug.Assert(ff.ContainsText(strSearchKey));
31 }
32
33 }
34 }
35
用WatiN框架开发Web测试很简单,必要的时候加个循环,活跃度就提升上去了;