您的位置:首页 > 编程语言 > Qt开发

远程启动Qtp/UFT开始测试

2015-10-28 18:19 411 查看
On Error Resume Next 

'开始运行前关闭桌面所以的程序,避免出现意外错误

Close_Process("excel.exe") 

Set ExcelBook = CreateObject("Excel.Application")

Set ExcelSheet = CreateObject("Excel.Sheet")

Set myExcelBook = ExcelBook.WorkBooks.Open("D:\MyAutoTest\Config.xls")

Set myExcelSheet = myExcelBook.WorkSheets("ScriptPath")

GetExcleSheetRowsCount = myExcelSheet.UsedRange.Rows.Count

'设置自动化引擎的默认状态,脚本运行一旦出错(由场景恢复来写错误),则终止测试。

'采用qtp杀自己的方式不可行,采用杀这个引擎方式也不可取(不是qtp卡死,就是继续执行下个脚本)。

'最好的方式就是让这个脚本自己退出程序。

StatusRuned = "D:\MyAutoTest\StatusRuned.txt"

WriteNotepad StatusRuned,"Run"

'读取excel中每一行,然后分别启动qtp/uft 

For i = 1 To GetExcleSheetRowsCount
Set oppobj = createobject("quicktest.application","192.168.5.5")
oppobj.Launch 
oppobj.Visible = True
oppobj.windowstate = "Maximized"
oppobj.open myExcelSheet.cells(i,1).value
Set qtTest = oppobj.test
Set objRecovery = oppobj.test.settings.recovery
Set objResultsOpt = CreateObject("QuickTest.RunResultsOptions")
objResultsOpt.ResultsLocation = myExcelSheet.cells(i,2).value
qtTest.Run objResultsOpt
qtTest.Close
Set objResultsOpt = Nothing
Set qtTest = Nothing
Set oppobj = Nothing

'发现文件中为Err是停止循环

Set fso = CreateObject("Scripting.FileSystemObject")
Set fil = fso.OpenTextFile(StatusRuned, 1)
Do Until fil.AtEndOfStream
Temp = fil.ReadLine
exit do
Loop
if instr(Temp ,"Err")   then 
i = GetExcleSheetRowsCount
end if

fil.Close
Set fso = Nothing 

next

ExcelBook.Quit

set ExcelSheet = Nothing

Set ExcelBook = Nothing

'关闭uft进程

wscript.sleep 5000

wscript.sleep 5000

call Close_Process("UFT.exe")

 '写状态函数

Sub WriteNotepad(MyFile,MyStr)
Dim fso, fil

'创建fso对象
Set fso = CreateObject("Scripting.FileSystemObject")

Set fil = fso.OpenTextFile(MyFile, 2)
fil.Write(MyStr)

'关闭文件
fil.Close

'释放文件
Set fso = Nothing

End Sub

'关闭指定进程

sub Close_Process(ProcessName)  
On Error Resume Next  

    for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_ 'ѭ۷޸Ԍ  
  if Ucase(ps.name)=Ucase(ProcessName) then  
ps.terminate  
  end if  

    next  
end sub  

说明:

      如果想要通过其它电脑来运行这个脚本(通过telnet连接到qtp电脑),以启动UFT进行测试,需要实现QTP、EXCEL的 DCOM功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: