如果你没有.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
原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 、作者信息和本声明,否则将追究法律责任。
相关阅读: