https://www.qatechies.com

QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 4

Latest Tosca,QTP,UFT,CodedUI Interview Questions

QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 4


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

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 4″ 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 3

 

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?
  10. How can you copy child objects of specific parent in one OR to specific parent of another OR?

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 (i.e copy child objects from one OR to another OR) and then focus on the solution.

How to copy child objects of one OR to another 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,parentObj2, 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 child objects of the parent of specific type like WebEdit , return the collection and store it in variable:

Set TOCollection = ORFrom.GetAllObjectsByClass(“WebEdit”,Parent1)

 

‘set the other parent object reference to parentObj2 variable:

Set parentObj2 = ORTo.GetObject(Parent2)

 

 

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 webedit type, hence renaming can be done directly. Copy the object of the first OR and then use the addobject method to add the copied object from first OR. And recursively call the method itself.

   
    For i = 0 To TOCollection.Count - 1
            
	Set toObject = TOCollection.Item(i)
			   
        Set copiedObject= ORTo.CopyObject toObject
			   
     	parentObj2.AddObject copiedObject,parentObj2
  
        CopyORObjectsToAnotherOR toObject
    Next

 

 

 

And later we are releasing the objects.

Set TOCollection = nothing

Set toObject = nothing

Set parentObj2= nothing

 

Complete Code

The below code discussion shows utilization and working with ObjectRepositoryUtil methods.

 

'How to copy child objects of one OR to another OR using OR-AOM?

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: CopyORObjectsToAnotherOR 
'Documentation: 'this recursive function adds objects or copy child
'                objects of one OR 
'                under test objects under a specified parent object
'                to another OR. 
'Created By: Prachur Saxena 
'Date : 13/1/2018 
'Modified By: NA 
'Revision Comments: NA 
'Return Values: nothing
'Example: CopyORObjectsToAnotherOR 
'         Proj1("some property").Parent1("some property"),
'         Proj2("some property").Parent2("some property")
'-------------------------------------------------------------'
Function CopyORObjectsToAnotherOR(Parent1,Parent2)

    Dim TOCollection,parentObj2, toObject

    Set TOCollection = ORFrom.GetAllObjectsByClass("WebEdit",Parent1)
    Set parentObj2 = ORTo.GetObject(Parent2)
     
    For i = 0 To TOCollection.Count - 1
            
	Set toObject = TOCollection.Item(i)
			   
        Set copiedObject= ORTo.CopyObject toObject
			   
        parentObj2.AddObject copiedObject,parentObj2
  
        CopyORObjectsToAnotherOR toObject
    Next

Set TOCollection = nothing

Set toObject = nothing

Set parentObj2= nothing

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, Copy child objects, Modifying the properties are uncommon actions and proper consideration should be made before taking approach in this direction.
  3. Getting objects as child objects, 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 4”, where we have learned how to copy child objects of One OR to another OR.

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

QTP or UFT and VBScript: Working with ObjectRepositoryUtil methods Part 3

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