51Testing软件测试论坛

标题: 关于QTP脚本自动调用 [打印本页]

作者: qijunhaha    时间: 2008-8-22 10:06
标题: 关于QTP脚本自动调用
我在QTP里的代码是:
ExecuteFile "f:\xx\temp.vbs"
Call a()

我的temp.vbs的代码是:
Public Function a()
dim WshShell
dim s

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.run "cmd"
WshShell.AppActivate"c:\windows\system32\cmd.exe"
WScript.Sleep 200

WshShell.SendKeys"ftp localhost"
WshShell.SendKeys"{ENTER}"
WshShell.AppActivate"ftp.exe "
WshShell.SendKeys"toptea"
WshShell.SendKeys"{ENTER}"
WshShell.SendKeys"toptea"
WshShell.SendKeys"{ENTER}"

'读文件
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("D:\QTP\Tests\ChinaMobileBOMC\put.txt", 1)
s = ts.ReadLine
ts.Close

'在远程生成文件夹并改变远程目录到新建文件夹下
WshShell.SendKeys"mkdir "+s                       
WshShell.SendKeys"{ENTER}"
WshShell.SendKeys"cd "+s                                
WshShell.SendKeys"{ENTER}"

WshShell.SendKeys"put D:\QTP\Tests\ChinaMobileBOMC\"+s+"\Report\Results.xml"        '上传本地文件到远程
WshShell.SendKeys"{ENTER}"

WshShell.SendKeys"bye"
WshShell.SendKeys"{ENTER}"
End function


现在一运行就报缺少wscript对象错误.我的脚本双击执行是可以的,请问我这个问题出在什么地方啊?应该怎么解决啊?谢谢了.
作者: zhuyuancan    时间: 2008-8-22 10:17
Set WshShell = WScript.CreateObject("WScript.Shell")
改为
Set WshShell = CreateObject("WScript.Shell")

作者: qijunhaha    时间: 2008-8-22 13:00
改过以后报语法错误!大家侃侃怎么解决啊?先谢谢大家了,会的朋友帮个忙
作者: 厍仕杰    时间: 2008-8-22 14:28
可以在QTP里面这样写:Dim oShell
Set oShell =CreateObject ("WSCript.shell")
oShell.run "cmd /K wscript f:\xx\temp.vbs"
Set oShell = Nothing
作者: LittleDuck    时间: 2008-8-22 14:50
我以前也碰到过这个问题,就是在第一行报错:缺少wscript对象。
当时新建了一个.vbs文件,把lib里面的内容(也就是类似于你的temp.vbs)拷贝进去,把executefile的对象指向新建的这个文件。就OK了。
你可以试试。
作者: qijunhaha    时间: 2008-8-22 16:22
问题已经解决了,去掉WScript.Sleep 200这句就正常了,大家的方法我也试试,先谢谢大家了,呵呵




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