https://www.qatechies.com

QTP or UFT and VBScript: Working with ObjectRepositoryUtil Methods Part 1

Latest Tosca,QTP,UFT,CodedUI Interview Questions

QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods – Part 1


Welcome to this post! -“QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 1”

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 1″ consists of several 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 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.

 

In the interview usually, you might be questioned in different ways like:

 

  1. How to get child properties of any test object in the object repository?
  2. How can you add object to existing object repository using VBScript?
  3. How to get to the parent object in object repository?
  4. Setting property value of any test object in OR?
  5. Copying objects of one OR to another?
  6. How to retrieve child properties of any test object of any OR using OR-AOM?
  7. How to retrieve child objects of desired type and rename them of any OR using OR-AOM?
  8. How to retrieve child objects of desired type and remove them of any OR using OR-AOM?
  9. 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 properties of any test object 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, TestObject, PropColl, Property

 

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

TestObject = test object of any OR

PropColl = property collection variable

Property = property of a test object

 

‘get the children of desired parent object

Set TOCollection = ORFrom.GetChildren(Root)

 

‘store and reference each of the test object

Set TestObject = TOCollection.Item(i)

 

‘get the properties of test object

Set PropColl = TestObject.GetTOProperties()

 

‘get the single property out of collection

Set Property = PropColl.Item(n)

 

Part 2: Execution and Releasing Objects

In this section we are iterating through the test objects of the OR, one by one and printing the values of property value pair. The test object for current loop value, is then passed to the same function i.e. calling itself again, so that we get all the child objects and their properties values.

    For i = 0 To TOCollection.Count - 1

         Set TestObject = TOCollection.Item(i)

         print ORFrom.GetLogicalName(TestObject) & vbNewLine

         Set PropColl = TestObject.GetTOProperties()


         For n = 0 To PropColl.Count - 1

                Set Property = PropColl.Item(n)

                print Property.Name & "-" & Property.Value & vbNewLine                  

            Next

         Fn_RecursivelyGetAllChildProperties TestObject

    Next

 

 

 

And later we are releasing the objects.

Set TOCollection = nothing

Set TestObject = nothing

Set PropColl = nothing

Set Property = 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\Flights.tsr"
ORTo.Load "C:\Project2\Tests\Default.tsr"

'------------------------------------------------------------' 
'Function Name: Fn_RecursivelyGetAllChildProperties 
'Documentation: 'function recursively enumerates
'  		all the test objects directly under
'		a specified parent object.
'Created By: Prachur Saxena 
'Date : 13/1/2018 
'Modified By: NA 
'Revision Comments: NA 
'Return Values: nothing
'Example: Fn_RecursivelyGetAllChildProperties "Proj1(some property)"
'-------------------------------------------------------------'


Function Fn_RecursivelyGetAllChildProperties(Root)

    Dim TOCollection, TestObject, PropColl, Property

    Set TOCollection = ORFrom.GetChildren(Root)

    For i = 0 To TOCollection.Count - 1
            
	Set TestObject = TOCollection.Item(i)
            
	print ORFrom.GetLogicalName(TestObject) & vbNewLine
            
	Set PropColl = TestObject.GetTOProperties()

        For n = 0 To PropColl.Count - 1
           Set Property = PropColl.Item(n) 
           print Property.Name & "-" & Property.Value & vbNewLine			
        Next
           
        Fn_RecursivelyGetAllChildProperties TestObject
    Next

	
	
End Function

 

 


Conclusion

Let’s conclude our discussion with few good points to be noted:

  1. Prior calling the function you must know which type of action you are targeting on the test object.
  2. Removing test objects, Modifying the properties are uncommon actions and proper consideration should be made before taking approach in this direction.
  3. 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.
  4. The large OR may take time to iterate through all objects and hence always focus on refactoring your logic into smaller modules.
  5. 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.
  6. 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 1”.

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 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.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

advanced-floating-content-close-btn
https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5034726663464946 (adsbygoogle = window.adsbygoogle || []).push({});
advanced-floating-content-close-btn 
*************************** Do you want to learn TOSCA? Do you want to excel in Career? Try my New Courses: 1. Tricentis Tosca and Working with Excel   2. Tricentis Tosca and UI Automation Great News!!   Price has been slashed down for limited period of time.So Hurry!!! Click The Shown Links and Enjoy Learning. ***************************
 
error: Content is protected !!