首页 测试 工具 查看内容

当WatiN爱上QTP

2014-8-30 12:43| 发布者: | 查看: 656| 评论: 0

摘要:   如果你没有.NET插件,怎么办?如果你发现QTP对某些.NET控件不能识别,怎么办?哈哈,有福了。WatiN给我们带来了很好的礼物,帮我们解决这些问题。  先看下面这段代码:Sub OpenGoogle()Set IE = DotNetFactory ...
Sub OpenGoogle()
Set IE = DotNetFactory.CreateInstance("WatiN.Core.IE","C:Documents and SettingsAdministrator桌面WatiN-2.0.10.928-net-2.0WatiN-2.0.10.928-net- 2.0binWatiN.Core.dll")
Set Find=DotNetFactory.CreateInstance("WatiN.Core.Find","C:Documents and SettingsAdministrator桌面WatiN-2.0.10.928-net-2.0WatiN-2.0.10.928-net- 2.0binWatiN.Core.dll")
IE.GoTo("http://www.google.com")
IE.WaitForComplete
IE.TextField(Find.ByName("q")).TypeText("WatiN")
IE.Button(Find.ByName("btnG")).Click()
End Sub

  怎么样?熟悉吧!将QTP的DotNetFactory对象用来调用WatiN的dll来完成一些操作会使我们的脚本更容易理解和阅读,更重要的是再也不怕.NET对象不能被识别了。

  OK,再看第二个Demo。

Set IE = DotNetFactory.CreateInstance("WatiN.Core.IE","C:Documents and SettingsAdministrator桌面WatiN-2.0.10.928-net-2.0WatiN-2.0.10.928-net-2.0binWatiN.Core.dll")
Set Find=DotNetFactory.CreateInstance("WatiN.Core.Find","C:Documents and SettingsAdministrator桌面WatiN-2.0.10.928-net-2.0WatiN-2.0.10.928-net- 2.0binWatiN.Core.dll")
IE.GoTo("http://www.51testing.com")
IE.WaitForComplete
IE.TextField(Find.ByName("searchkey")).TypeText("vbs测试webservice")
IE.Button(Find.ByName("subjectsearch")).Click()
Set   IEpage = IE.AttachToIE(Find.ByUrl("http://www.51testing.com/batch.search.php"))
Set LinkObj = IEpage. Link(Find.ByUrl("http://www.51testing.com/?uid-194902-action-viewspace-itemid-130043"))
IF LinkObj.Exists    Then
     LinkObj.Click()
   ' IE.AttachToIE(Find.ByUrl("http://www.51testing.com/?uid-194902-action-viewspace-itemid-130043"))
   Set  ConsoleObj= DotNetFactory.CreateInstance("System.Console","System")
   Consoleobj.Write("PASS")
     ' Msgbox("PASS")
else
          Msgbox("FAILL")
End If
IE.Close
IEpage.Close
IE.AttachToIE(Find.ByUrl("http://www.51testing.com/?uid-194902-action-viewspace-itemid-130043")).Close

  这个demo里不光使用了WatiN的dll,也使用了.NET20的基本类库。大家可以比较一下这里的Consoleobj.Write与Msgbox。

版权声明:本文出自aslandhu的51Testing软件测试博客:http://www.51testing.com/?194902

原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 、作者信息和本声明,否则将追究法律责任。

相关阅读:

WatiN与QTP的选择

尝试使用Web自动化测试框架WatiN进行TDD

用WatiN对ASP.NET页面进行单元测试

  如果你没有.NET插件,怎么办?如果你发现QTP对某些.NET控件不能识别,怎么办?哈哈,有福了。WatiN给我们带来了很好的礼物,帮我们解决这些问题。

  先看下面这段代码:


鲜花

握手

雷人

路过

鸡蛋

扫一扫关注最新动态

毒镜头:老镜头、摄影器材资料库、老镜头样片、摄影
爱评测 aipingce.com  
返回顶部