ouyangxu 发表于 2011-3-3 22:13:25

请教一个qtp问题

就是我们常在qtp的

file ->setting->resource选项卡中加载*.vbs脚本

有没有办法,直接在qtp脚本中引用这些*.vbs脚本,而不需要向上面那样操作:

下面这样引用不正确。
'引用公共脚本
'ExecuteFile "D:\autospace\aw\登陆.vbs"
'ExecuteFile "D:\autospace\aw\Global表中取列值.vbs"
'ExecuteFile "D:\autospace\aw\打开订单.vbs"

june.diny 发表于 2011-3-4 08:58:11

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtLibraries 'As QuickTest.TestLibraries ' Declare a test's libraries collection variable
Dim lngPosition

' Open QuickTest
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Launch QuickTest
qtApp.Visible = True ' Set QuickTest to be visible

' Open a test and get its libraries collection
qtApp.Open "C:\Tests\Test1", False, False ' Open a test
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object

' Add Utilities.vbs if it's not in the collection
If qtLibraries.Find("C:\Utilities.vbs") = -1 Then ' If the library cannot be found in the collection
    qtLibraries.Add "C:\Utilities.vbs", 1 ' Add the library to the collection
End If

lyscser 发表于 2011-3-4 09:59:49

'如下三个路径中只能保留需要加载的资源,文件格式必须正确,因为函数会加载该目录下所有文件
Dim frameRoot:frameRoot = "\\XXXXX\share\TestData\XXXX\XXXX子系统"

'如下两组参数中元素个数必须相等,否则无法执行
Dim whatToRep:whatToRep = "------------------------------------>,Reporter.ReportEvent 2,End Step,Expected Results,Description,Begin Step,Start recording here..."
Dim repToWhat:repToWhat = "**********************************************************************************,Report micPass,结束步骤,预期结果,操作描述,开始步骤,脚本操作内容请如下:"
Dim whatToRepArr:whatToRepArr = Split(whatToRep,",")
Dim repToWhatArr:repToWhatArr = Split(repToWhat,",")

Set fobjShell = CreateObject("Scripting.Filesystemobject")
Set QTPApplication = CreateObject("QuickTest.Application")
QTPApplication.Launch
QTPApplication.Visible = True

'脚本运行设置
QTPApplication.Test.Settings.Run.IterationMode = "rngAll"
QTPApplication.Test.Settings.Run.ObjectSyncTimeOut = 30000
QTPApplication.Test.Settings.Run.DisableSmartIdentification = True
QTPApplication.Test.Settings.Run.OnError = "Stop"

'参数表设置
QTPApplication.Test.Settings.Resources.DataTablePath = "<Default>"

'函数文件移除重新加载
Set AllFiles = fobjShell.GetFolder(frameRoot & "\Functions Library").Files
QTPApplication.Test.Settings.Resources.Libraries.RemoveAll
For Each sFile in AllFiles
   QTPApplication.Test.Settings.Resources.Libraries.Add(sFile.Path)
Next
Set AllFiles = Nothing

'场景恢复移除重新加载
Set AllFiles = fobjShell.GetFolder(frameRoot & "\Recovery Senario").Files
QTPApplication.Test.Settings.Recovery.RemoveAll
For Each sFile in AllFiles
   QTPApplication.Test.Settings.Recovery.Add(sFile.Path)
Next
Set AllFiles = Nothing

'配置文件加载
Set AllFiles = fobjShell.GetFolder(frameRoot & "\Environment").Files
For Each sFile in AllFiles
   QTPApplication.Test.Environment.LoadFromFile(sFile.Path)
Next
Set AllFiles = Nothing

'替换QC生成的指定注释内容和格式
For ainx = 1 to QTPApplication.Test.Actions.Count
   vbsContent = QTPApplication.Test.Actions.Item(ainx).GetScript
   For arr = 0 to UBound(whatToRepArr)
      vbsContent = Replace(vbsContent, whatToRepArr(arr), repToWhatArr(arr))
   Next
   vbsContent = Replace(vbsContent, "Quality Center", "Quality Center" & Chr(10))
   QTPApplication.Test.Actions.Item(ainx).SetScript(vbsContent)
Next

'保存测试脚本
QTPApplication.Test.Save
页: [1]
查看完整版本: 请教一个qtp问题