51Testing软件测试论坛

标题: 【QTP 访问远程文件代码片】 [打印本页]

作者: 假装不在    时间: 2008-10-9 19:19
标题: 【QTP 访问远程文件代码片】
Public Function  Log_in(ip,user,pw)
   Dim oShell
   Set oShell = CreateObject ("WSCript.shell")
   oShell.run  ip
   Set oShell = Nothing
   wait (2)
   If Dialog("nativeclass:=#32770","index:=0").exist(1) Then
        Dialog("nativeclass:=#32770","index:=0").WinEdit("nativeclass:=edit","index:=1").set  user
        Dialog("nativeclass:=#32770","index:=0").WinEdit("nativeclass:=edit","index:=2").set  pw
        Dialog("nativeclass:=#32770","index:=0").WinButton("nativeclass:=Button","index:=0").click
   End If
End Function

这个是远程登陆的代码片,要用的话,Log_in "\\192.168.1.1","admin","admin"
里面只做到了简单捕获对话框Dialog而已,如果有具体情况,还需要大家把这个片断去完善。
因为MSN群里的热心朋友问到这个问题,而采用的是sendkeys的方法,个人不推荐使用这个,所以写写普及下。
作者: heqingbluesky    时间: 2008-10-10 11:08
LZ,有两个问题。

1.Set oShell = CreateObject ("WSCript.shell")好像有错。
应该是:Set oShell=Wscript.CreateObject ("WSCript.shell")

2.其次,好像不能在QTP中运行WSH,因为QTP没有封装相应的方法。所以也就无从用起描述性编程了的好处了。
作者: 假装不在    时间: 2008-10-10 19:14
谢谢楼上的回帖。
你和我说的这2个问题,都用了“好像”,很谦虚。哈哈
你打开QTP把代码粘贴进去,运行看看就可以了,谢谢。
1.Set oShell = CreateObject ("WSCript.shell")好像有错。
应该是:Set oShell=Wscript.CreateObject ("WSCript.shell")

2个写法都是可以的。

2.其次,好像不能在QTP中运行WSH,因为QTP没有封装相应的方法。所以也就无从用起描述性编程了的好处了。

QTP没封装但QTP支持VBS这点就足够了。还有最后一句话,我不是哪么理解你说的意思。
作者: heqingbluesky    时间: 2008-10-13 14:26
其实不是谦虚,我也有很多不懂的地方。
对于QTP,如果这样写:Set oShell=Wscript.CreateObject ("WSCript.shell")
QTP会报错误信息的,
但是这样写:Set oShell=CreateObject ("WSCript.shell")
QTP就不会报错。

其次,把这段代码放到QTP中运行,还是给我一个报错信息:
General Run Error的消息框。(在运行oshell.run ip的时候)

Log_in "150.245.167.75","user","123456"

Public Function  Log_in(ip,user,pw)
   Dim oShell
   Set oShell =CreateObject ("WSCript.shell")
   oShell.run  ip
   Set oShell = Nothing
   wait (2)
   If Dialog("nativeclass:=#32770","index:=0").exist(5) Then
        Dialog("nativeclass:=#32770","index:=0").WinEdit("nativeclass:=edit","index:=1").set  user
        Dialog("nativeclass:=#32770","index:=0").WinEdit("nativeclass:=edit","index:=2").set  pw
        Dialog("nativeclass:=#32770","index:=0").WinButton("nativeclass:=Button","index:=0").click
   End If
End Function
作者: 假装不在    时间: 2008-10-13 22:24
因为你调用错了,写少了“\\”
作者: heqingbluesky    时间: 2008-10-14 10:29
看来我犯了常识性的错误 ,qtp的报错我有点看不懂了。

我们一般对于远程的机器的文件拷贝,例如Daily Build,一般使用systemutil.run方法调用。
不过两种方法都不错。
作者: 假装不在    时间: 2008-10-14 11:09
哈哈,人总会有犯错的时候。




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2