如何在.NET中应用Watin

 

 WatiN是一个开源的web功能测试工具 
        下载地址: http://watin.sourceforge.net/选择:Download进行下载

如何在.NET中应用Watin
(条件:已安装:Microsoft Visual Studio 2008)   

1步:.Net中引用Watin

操作步骤:

1References处右键选择Add ReferenceBrowse选择WatiN安装目录" WatiN- 2.0.20 .1089-net-2.0\bin\"下的WatiN.Core.dll

 WatiN学习:
IE ie = new IE();
ie.GoTo("http://www.google.com");
ie.TextField(Find.ByName("q")).TypeText("WatiN");
ie.Button(Find.ByName("btnG")).Click();
ie.WaitForComplete();   //等待ie下载完成
检查点:
if (ie.ContainsText("上传成功!"))
{
     //SSystem.Console.WriteLine("上传文件成功");
     //MessageBox.Show("上传文件成功");
}
捕捉弹出的ie窗口:
引用:using System.Text.RegularExpressions;
下面语句://使用正则表达式捕获这个窗口
ie = IE.AttachTo<IE>(Find.ByTitle(new Regex("的网络相册")));  
ie.WaitForComplete();  //等待ie下载完毕

等待ie的加载:
方法1:  ie.WaitUntilExists();
方法2:using System.Threading;
             
thread.sleep(5);
编辑器输入文本:
方法1:
 ie.Frame(Find.ById("PostBody")).RunScript("document.write(\"strreply content\")");
或者:
ie.RunScript("document.frames(\"mce_editor_0\").document.write(\"test\")");
方法2:using System.Windows.Forms;
   找到输入框的焦点,然后用下面方法
  SendKeys.SendWait("strreply content");

输入框:ie.TextField(Find.ByName("q")).value ="WatiN"; 
按钮点击:ie.Button(Find.ByName("btnG")).Click();  
ie.Image(Find.BySrc=\'#\'" //xx/ss/insert.gif")).Click();
单选框:ie.RadioButton(Find.ById("RadioButtonID")).Checked = true; 

列表清除:ie.SelectList(Find.ById("SelectListID")).SelectedOption.Clear();
列表选择:ie.SelectList(Find.ById("SelectListID")).Option("OptionItem").Select(); 
复选框不选:ie.CheckBox(Find.ById("CheckBoxID")).Checked = false;  
上传图片:

ie.FileUpload(Find.ById("ctl00_bcr_EditPost_PostForm_ctl00_file1")).Set("c:\\test.jpg");

 

你可能感兴趣的:(.net,学习,职场,休闲,Watin)