1

我的目标是从对象存储库文件 (.tsr) 中获取一个对象,并对该对象执行一些操作,例如单击、设置...在下面的代码中,“WebButton”对象被捕获。但是当我对这个对象(brObj)执行“点击”操作时。在 UFT 中收到错误消息“由于不可恢复的错误行 (20):brObj.Click 无法继续测试运行”

  Dim RepositoryFrom, brObj
  Dim ObjectRepositoryPath, str, pgStr, btnStr  

  ObjectRepositoryPath="C:\Repository2.tsr"

  Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
  RepositoryFrom.Load ObjectRepositoryPath

  str = "Browser("+""""+"Title"+""""+")"
  pgStr = "Page("+""""+"Title"+""""+")"
  btnStr = "WebButton("+""""+"Login"+""""+")"

  'MsgBox str 

  set brObj =  RepositoryFrom.GetObject(str+"."+pgStr+"."+btnStr) 
  brObj.Click 'Getting error for this line

那么 UFT 中是否有另一种方法可以对检索的对象执行操作

来自对象存储库文件 (.tsr)

4

2 回答 2

1

您从该库访问的 COM 对象与 UFT 运行时引擎在播放期间使用的对象不同。如果要在运行时加载对象存储库文件,可以使用 RepositoriesCollection 实用程序对象将文件添加到可用的对象存储库。加载后,您可以像访问 UFT 中的任何其他测试对象一样访问测试对象。

Dim ObjectRepositoryPath, brObj

ObjectRepositoryPath = "C:\Repository2.tsr"
RepositoriesCollection.Add ObjectRepositoryPath

Set brObj = Browser("Title").Page("Title").WebButton("Login")
brObj.Click
于 2014-06-18T12:13:02.937 回答
0

还有另一种使用“Execute”语句从字符串中获取测试对象的方法,它适用于回放。

str = "Browser("+""""+"Title"+""""+")"
pgStr = "Page("+""""+"Title"+""""+")"
btnStr = "WebButton("+""""+"Login"+""""+")"
Execute "set brObj = "+str+"."+pgStr+"."+btnStr"
brObj.Click
于 2014-06-25T07:31:37.710 回答