当WatiN爱上QTP

发表于:2009-8-27 12:22

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:aslandhu    来源:51Testing博客

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

  先看下面这段代码:

Sub OpenGoogle()
Set IE = DotNetFactory.CreateInstance("WatiN.Core.IE","C:\Documents and Settings\Administrator\桌面\WatiN-2.0.10.928-net-2.0\WatiN-2.0.10.928-net- 2.0\bin\WatiN.Core.dll")
Set Find=DotNetFactory.CreateInstance("WatiN.Core.Find","C:\Documents and Settings\Administrator\桌面\WatiN-2.0.10.928-net-2.0\WatiN-2.0.10.928-net- 2.0\bin\WatiN.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 Settings\Administrator\桌面\WatiN-2.0.10.928-net-2.0\WatiN-2.0.10.928-net-2.0\bin\WatiN.Core.dll")
Set Find=DotNetFactory.CreateInstance("WatiN.Core.Find","C:\Documents and Settings\Administrator\桌面\WatiN-2.0.10.928-net-2.0\WatiN-2.0.10.928-net- 2.0\bin\WatiN.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页面进行单元测试

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号