1
votes

My objective is to get an object from Object Repository file (.tsr) and perform some action on that object like click, set... In the below code "WebButton" object is captured. But when I perform "click" action on this object (brObj). Getting error message in UFT " The test run cannot continue due to unrecoverable error line(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

So is there another way in UFT to perform an action on object which is retrived

from Object Repository file (.tsr)

2

2 Answers

1
votes

The COM objects you access from that library are not the same objects the UFT run-time engine uses during playback. If you want to load an object repository file at run-time, you can use the RepositoriesCollection utility object to add the file to the available object repositories. Once loaded, you can access the test objects like you would any other test object in UFT.

Dim ObjectRepositoryPath, brObj

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

Set brObj = Browser("Title").Page("Title").WebButton("Login")
brObj.Click
0
votes

There is an another way to get the test object from the string using the "Execute" statement and it is suitable for playback.

str = "Browser("+""""+"Title"+""""+")"
pgStr = "Page("+""""+"Title"+""""+")"
btnStr = "WebButton("+""""+"Login"+""""+")"
Execute "set brObj = "+str+"."+pgStr+"."+btnStr"
brObj.Click