51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1649|回复: 2
打印 上一主题 下一主题

[原创] 请教一个qtp问题

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2011-3-3 22:13:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
就是我们常在qtp的

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

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

下面这样引用不正确。
'引用公共脚本
'ExecuteFile "D:\autospace\aw\登陆.vbs"
'ExecuteFile "D:\autospace\aw\Global表中取列值.vbs"
'ExecuteFile "D:\autospace\aw\打开订单.vbs"
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    开心
    2017-3-3 10:21
  • 签到天数: 4 天

    连续签到: 1 天

    [LV.2]测试排长

    2#
    发表于 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
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
    发表于 2011-3-4 09:59:49 | 只看该作者
    1. '如下三个路径中只能保留需要加载的资源,文件格式必须正确,因为函数会加载该目录下所有文件
    2. Dim frameRoot:frameRoot = "\\XXXXX\share\TestData\XXXX\XXXX子系统"

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

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

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

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

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

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

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

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

    48. '保存测试脚本
    49. QTPApplication.Test.Save
    复制代码
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-20 22:23 , Processed in 0.067332 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表