load_pyg 发表于 2015-7-24 13:54:46

QTP外部资源导入的的问题

新建一个工程导入 外部资源 dll或者VBS文件,如下图








在重新打开新的工程,在File-Settings-Resource 下面就看看不到刚才导入的资源,如图






现在想在新工程也使用刚才的外部资源,不需要再次导入,麻烦问下有啥好的方法,谢谢!

子龙1028 发表于 2015-7-30 10:27:36

这个在前台手工快速设置目前也没有找到好的方法,不过新工程的话,可以通过vbs脚本启动自动加载外部资源及相应设置,使用Dictionary创建数组来管理外部资源,源码如下,可以参考下

Function Add_ARRAY_Library(pathName, byref itemCount)
Call ARRAY_Library.Add(cstr(itemCount), pathName)
itemCount = itemCount + 1
End Function

Function Add_ARRAY_Library_Delete(pathName, byref itemCount)
Call ARRAY_Library_Delete.Add(cstr(itemCount), pathName)
itemCount = itemCount + 1
End Function

Function IsExist(pathName)
IsExist= false
For j= 0 to ARRAY_Library.Count -1
    If ARRAY_Library.Item(cstr(j)) =pathName Then
      IsExist= true
      Exit function
    End If
Next
End Function

Dim MainPath, fso
Dim ARRAY_Library
Set ARRAY_Library = CreateObject("Scripting.Dictionary")
Dim ARRAY_Library_Delete
Set ARRAY_Library_Delete = CreateObject("Scripting.Dictionary")
MainPath = createobject("wscript.shell").currentdirectory & "\Main"
Set fso = CreateObject("scripting.filesystemobject")
Set qtApp = CreateObject("QuickTest.Application")
If not qtApp.Launched Then
If not fso.FolderExists(MainPath) then
    MsgBox MainPath & "路径不存在!" & vbCr & "请将VBS文件放到与Main平级的目录下执行!" & vbCr & "谢谢!", ,"Main路径错误"
    Wscript.Quit
End If
qtApp.Launch
qtApp.Open MainPath
qtApp.Visible = true
End If
Set fso = nothing
qtApp.Folders.RemoveAll
qtApp.Folders.Add(createobject("wscript.shell").currentdirectory & "\Addin")
qtApp.Folders.Add(createobject("wscript.shell").currentdirectory & "\Private")
qtApp.Folders.Add(createobject("wscript.shell").currentdirectory & "\Scripts")

'清除所有资源
qtApp.Test.Settings.Resources.Libraries.RemoveAll
'加载私有项目资源
Dim pos, delete_pos
pos = 0
delete_pos = 0
Call Add_ARRAY_Library("ProjectInit.vbs", pos)

'加载公共项目资源
Call Add_ARRAY_Library("ICall.dll", pos)
Call Add_ARRAY_Library("Recovery.vbs", pos)

'加载项目脚本
Call Add_ARRAY_Library("PUB\DosOracleExp.vbs", pos)


For i = 0 to ARRAY_Library.Count - 1
pathName = ARRAY_Library.Item(cstr(i))
If cstr(qtApp.Test.Settings.Resources.Libraries.Find(pathName)) = cstr(-1) then
    call qtApp.Test.Settings.Resources.Libraries.Add(pathName)
end if
Next

'原来类库中存在的则删除
For i = 1 to qtApp.Test.Settings.Resources.Libraries.Count
If not IsExist(qtApp.Test.Settings.Resources.Libraries.Item(i)) then
    Call Add_ARRAY_Library_Delete(qtApp.Test.Settings.Resources.Libraries.Item(i), delete_pos)
end if
Next

For i = 0 to ARRAY_Library_Delete.Count - 1
call qtApp.Test.Settings.Resources.Libraries.Remove(ARRAY_Library_Delete.Item(cstr(i)))
next

'直接运行
qtApp.Test.Run
Set qtApp = nothing
页: [1]
查看完整版本: QTP外部资源导入的的问题