QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 3
August 31, 2018
QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 3
Welcome to this post! -“QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 3”
If you are looking for latest HP UFT QTP interview Questions, then you are at right place. This post – “QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 3″ consists of a technical interview question discussed in detail and also which have been part of many interviews either external or internal. Usually these are assumed to be known in deep to check the logical solvency efficiency of the candidate and of course suitability for the project and company. The complete post is divided into several parts as explaining each of the technical problems statement is impossible to read in one post and even not recommended. So Go ahead and enjoy reading…
This discussion will help you prepare well if you are going for the interview or you need the function to be used in your project.
Heads Up!
This post is in continuation with other post already published where a technical example is discussed in detail, if you want to follow that first before this one please click on below:
Click here ==>Working with ObjectRepositoryUtil methods – Part 2
In the interview usually, you might be questioned in different ways like:
- How to get child properties of any test object in the object repository?
- How can you add object to existing object repository using VBScript?
- How to get to the parent object in object repository?
- Setting property value of any test object in OR?
- Copying objects of one OR to another?
- How to retrieve child properties of any test object of any OR using OR-AOM?
- How to retrieve child objects of desired type and rename them of any OR using OR-AOM?
- How to retrieve child objects of desired type and remove them of any OR using OR-AOM?
- How to copy child objects of one OR to another OR using OR-AOM?
And so on.
***OR-AOM = Object Repository Automation Object Model
In this discussion we will focus on some methods or see working with ObjectRepositoryUtil methods one by one. We will understand the objective of our problem statement and then focus on the solution.
How to retrieve child objects of desired type and remove them of any OR using Object Repository Automation Object Model (OR-AOM)?
The problem statement is divided into smaller units to explain the logic and later combining the complete code.
Part 1: Variables And Assignments
Option Explicit Dim ORFrom, ORTo Set ORFrom = CreateObject("Mercury.ObjectRepositoryUtil") Set ORTo = CreateObject("Mercury.ObjectRepositoryUtil") ORFrom.Load "C:\Project1\Tests\Project1.tsr" ORTo.Load "C:\Project2\Tests\Project2.tsr" Dim TOCollection, toObject
ORFrom = object repository from which object is to be referred.
ORTo = object to be copied to this OR
Load = loading the OOR method
TOCollection = object collection returned variable
toObject = test object of any OR
‘get all the objects by class like image and return the collection and store it in variable:
Set TOCollection = ORTo.GetAllObjectsByClass(“Image”)
‘set the object reference to toObject variable:
Set toObject = TOCollection.Item(i)
Part 2: Execution and Releasing Objects
In this section we are iterating through the test objects of the OR, one by one. Since all the objects are of image type, hence renaming can be done directly.
For i = 0 To TOCollection.Count - 1 Set toObject = TOCollection.Item(i) TOClass = toObject.GetTOProperty("micclass") If TOClass = "Link" Then ORFrom.RemoveObject Root, toObject End If Fn_RecursivelyGetAllChildProperties toObject Next
And later we are releasing the objects.
Set TOCollection = nothing Set toObject = nothing
Complete Code
The below code discussion shows utilization and working with ObjectRepositoryUtil methods.
Option Explicit Dim ORFrom, ORTo Set ORFrom = CreateObject("Mercury.ObjectRepositoryUtil") Set ORTo = CreateObject("Mercury.ObjectRepositoryUtil") ORFrom.Load "C:\Project1\Tests\Project1.tsr" ORTo.Load "C:\Project2\Tests\Project2.tsr" '------------------------------------------------------------' 'Function Name: RemovingAllWebLinksTO 'Documentation: 'this recursive function removes all links ' under test objects under a specified parent object. 'Created By: Prachur Saxena 'Date : 13/1/2018 'Modified By: NA 'Revision Comments: NA 'Return Values: nothing 'Example: RemovingAllWebLinksTO "Proj1(some property)" '-------------------------------------------------------------' Function RemovingAllWebLinksTO(Root) Dim TOCollection, toObject Set TOCollection = ORFrom.GetChildren(Root) For i = 0 To TOCollection.Count - 1 Set toObject = TOCollection.Item(i) TOClass = toObject.GetTOProperty("micclass") If TOClass = "Link" Then ORFrom.RemoveObject Root, toObject End If Fn_RecursivelyGetAllChildProperties toObject Next Set TOCollection = nothing Set toObject = nothing End Function
Conclusion
Let’s conclude our discussion with few good points to be noted:
- Prior calling the function you must know which type of action you are targeting on the test object.
- Removing test objects, Modifying the properties are uncommon actions and proper consideration should be made before taking approach in this direction.
- Getting objects as children, children by class name, children by parent name are often used approaches to reach to the desired test object, be considerate in iteration.
- The large OR may take time to iterate through all objects and hence always focus on refactoring your logic into smaller modules.
- Performance is the major issue here, depending on the class type of object you are referring you may find slowness in iterating through the items.
- The function shared here can be part of any framework in hand, i.e. regardless of kind of framework it can be easily adapted.
This brings me to the end of our discussion on “QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 3”.
I really hope you have enjoyed reading the post. If you have any doubt on this please feel free to add your comment below.
And if you like to read more on UFT or QTP Technical Interview Questions please follow below links:
QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 1
QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 2
UFT Technical Interview Questions – Set 1
UFT Technical Interview Questions – Set 2
How to Download Resource From QC\ALM?
How to Upload Resource To QC\ALM?
Or if you prefer General Interview Questions please follow below links:
UFT General Interview Questions – Part 1
UFT General Interview Questions – Part 2
If you would like to keep track of further articles on UFT (QTP). I recommend you to SUBSCRIBE by Email and have new UFT articles sent directly to your inbox.