QuickTest底层VB脚本驱动

sample Codes:


'****  Author: Wally Yu (俞戴龙)
'***   Import common functions into report function   ****
Dim fso : set fso = createobject("scripting.filesystemobject")
executeglobal fso.opentextfile("C:\Framework\FrameworkCore\Common\common.vbs", 1).ReadAll
executeglobal fso.opentextfile("C:\Framework\FrameworkCore\Common\report.vbs", 1).ReadAll
set fso = Nothing
'***   End of importing     ******************************


'On Error Resume Next

'###  Report dim area  ####
'On Error Resume Next
Dim StartTime, EndTime, stTime, enTime, ServerName
Dim testWorkBook, testCaseSheet, startSheet

'***************INITIALISATION***************************
testWorkBook = "c:\framework\testcase.xls"
testCaseSheet = "testcase"
startSheet = "start"
'**************************************************************



ServerName = "."  '****** Confirm Server Name before run test ********
runtime = Date & "-"& Hour(Now) & Minute(Now)& Second(Now)
runtime = changeString(runtime, "/", "-")
folderPath="c:\Framework\Report\"&runtime
emailAddress = ReadExcelCell(testWorkBook, startSheet, 1,1)
StartTime = Timer
stTime = Time
LogReportFlag = True
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

'#####    initReport    #####
Call CreatFolderIfNotExist("c:\Framework")
Call CreatFolderIfNotExist("c:\Framework\report")
Call initReport("c:\Framework\Report", "c:\Framework\Report\"&runtime)

Set obj = CreateObject("QuickTest.Application") 'Creates an instance of the QTP
call Mbox("Invoking QTP...",2,msgbox2)    
'WScript.Echo "Invoking QTP..."

obj.Launch
obj.Visible = true
obj.WindowState = "Maximized" 'Maximizes the application window of the QTP


folderfile="C:\Framework\FrameworkCore\Common\FoldersFile.vbs"

   If fso.FileExists(folderfile) Then
        Set f = fso.OpenTextFile(folderfile)
        s = f.ReadAll
        f.Close
        ExecuteGlobal s
   End If    

   
obj.open "c:\framework\frameworkcore\core data\test"

call Mbox("Loading library files into QTP scripts...",2,msgbox3)    
'WScript.Echo "Loading library files into QTP scripts..."

Set oExcel = CreateObject("Excel.Application") 'open Excel Application
Set oWorkbook = oExcel.Workbooks.Open(testWorkBook)
Set oWorksheet1 = oWorkbook.Worksheets.Item(startSheet) 'Set up the worksheet
'Set url = oWorksheet1.cells

obj.Test.Environment.Value("gbl_emailAddress") = oworksheet1.textbox1.text
obj.Test.Environment.Value("folderPath")=folderPath
obj.Test.Environment.Value("TransactionCode")=""
obj.Test.Environment.Value("BatchID")=""
obj.Test.Environment.Value("ExecutionFlag")=""
obj.Test.Environment.Value("ClaimsReimbursement")=""
obj.Test.Environment.Value("con")=""

'obj.Test.Environment.Value("gbl_app") = oWorksheet1.ComboBox1.text
'obj.Test.Environment.Value("gbl_app_url") = oworksheet1.range("G21").text

gbl_emailAddress = oworksheet1.textbox1.text
'gbl_app = oWorksheet1.ComboBox1.text

'gbl_emailAddress=url(1,1)
'gbl_app=oWorksheet1.ComboBox1.text
'gbl_app_url=url(21,7)

oWorkbook.close FALSE
oExcel.quit
set oExcel = Nothing

Set qtLibraries = obj.Test.Settings.Resources.Libraries ' Get the libraries collection object

If qtLibraries.Find("c:\framework\frameworkcore\Common\main.vbs") = -1 Then
    qtLibraries.Add "c:\framework\frameworkcore\Common\main.vbs", 1
End If
'If qtLibraries.Find("c:\framework\frameworkcore\Common\core data\action.vbs") = -1 Then
'    qtLibraries.Add "c:\framework\frameworkcore\Common\core data\action.vbs", 1
'End If
If qtLibraries.Find("C:\Framework\FrameworkCore\Common\Globalvariable.vbs") = -1 Then
    qtLibraries.Add "C:\Framework\FrameworkCore\Common\Globalvariable.vbs", 1
End If    
If qtLibraries.Find("C:\Framework\FrameworkCore\Common\Report.vbs") = -1 Then
    qtLibraries.Add "C:\Framework\FrameworkCore\Common\Report.vbs", 1
End If
If qtLibraries.Find("C:\Framework\FrameworkCore\Common\Common.vbs") = -1 Then
    qtLibraries.Add "C:\Framework\FrameworkCore\Common\Common.vbs", 1
End If

'Set qtTestRecovery = obj.Test.Settings.Recovery

'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE1", 1
'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE2", 2
'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE3", 3
'qtTestRecovery.Add "C:\Framework\FrameworkCore\Common\Recovery.qrs", "MIE4", 4

'' Enable all scenarios
'For intIndex = 1 To qtTestRecovery.Count ' Iterate the scenarios
' qtTestRecovery.Item(intIndex).Enabled = True ' Enable each Recovery Scenario (Note: the 'Item' property is default and can be omitted)
'Next
'
'' Enable the recovery mechanism (with default, on errors, setting)
'qtTestRecovery.Enabled = True
'
''Ensure that the recovery mechanism is set to be activated only after errors
'qtTestRecovery.SetActivationMode "OnError"
'OnError is the default, the other option is "OnEveryStep".

call Mbox("Running Qtp in Silent Mode...",2,msgbox4)
'WScript.Echo "Running Qtp in Silent Mode..."

obj.Test.Run 'Runs the script

'wscript.sleep(7000)

call Mbox("QTP script execution completed...",2,msgbox5)
'WScript.Echo "QTP script execution completed..."


obj.Test.Close ' Close the test
call Mbox("Closing Qtp....",2,msgbox6)
'WScript.Echo "Closing Qtp...."
obj.quit 'Close QTP
'Call CloseIE() 'close IE


'#####    endReport    #####
Call EndReport("c:\Framework\Report")
'####     emailReport    #####

WScript.Sleep (9000)
Call CloseIE() 'close IE
'Call CloseExcels()

Set oautoIt = Nothing
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值