Wednesday, July 20, 2011

How to use GetROProperty and GetTOProperty?

After reading this topic you will be able to answer following questions:

1. What is the difference between GetROProperty and GetTOProperty?

2. What is GetTOProperties?

3. How does SetTOProperty work?

4. When and how to use all these properties?

Lets see one by one.

While recording a application, QTP stores the information of objects in the form of properties in the object repository. When the same test is run again, QTP will automatically create a temporary version for each and every object so that user can manipulate the properties. And every time a test is run, QTP will create a new temporary version for the objects and the changes that are made by the user will affect only the temporary version of the object but not to the actual object present in Object repository. As the temporary version will be available only during that run session, the changes made will also be available only in that run session. And lastly if there are no changes made to the object's properties values, temporary version will also have the all the same property values that are stored in Object repository. 

SetTOProperty is a method which is used to set the value of any object's property in the temporary version. And as discussed above, this property value will be changed only in temporary version and the change will be avaialble only in that run session. 

GetTOProperty is a method which is used to retrieve a specific property value of an object that is stored in temporary version. GetTOProperty retrieves the information only from temporary version that is created by QTP and not from Object repository.

Lets see these properties with a small example. Here I have recorded clicking on "Google Search" button present in Google home page. The label of the button "Google Search" is stored under a property called "name" in object repository. I have changed the name of the button from "Google Search" to "My Search" using SetToProperty in third statement. To remind you again, now the property value will be changed only in the temporary version of Object and the actual object repository will have the initially recorded value i.e., "Google Search". In the 4th statement I am trying to retrieve the property value using GetTOProperty. As we have discussed that GetTOProperty will retrieve from Temporary Version of object, the output for this would be "My Search".


Dim GTP

Browser("Google").Page("Google").WebButton("Google Search").Click

Browser("Google").Page("Google").WebButton("Google Search").SetTOProperty "name", "My Search"

GTP=Browser("Google").Page("Google").WebButton("Google Search").GetTOProperty("name")

Msgbox "Result when Get TO property is used: "&GTP




GetTOProperties is a method which is used to retrieve all the properties of an object that are stored in temporary version. The only difference between GetTOProperty and GetTOProperties is that GetTOProperty returns a specific property value of the desired object where as GetTOProperties will return all the properties of the desired object that are stored.

I am using the same example which is used above. 

Dim GTPS, GTPScount, PropertiesLis

Browser("Google").Page("Google").WebButton("Google Search").Click 'Statement that got recorded

Browser("Google").Page("Google").WebButton("Google Search").SetTOProperty "name", "My Search"'Changing the name of button

Set GTPS=Browser("Google").Page("Google").WebButton("Google Search").GetTOProperties 'Using GetToProperties to get list of all properties for the button

GTPScount=GTPS.count 'Counting the number of properties available for that object 

PropertiesList = "List of properties when Get TO Properties is used:" & vbNewLine 'Text that needs to get displayed in message box 

For i = 0 to GTPScount-1 'Looping to display all properties available for that object in the message box 

PropertiesList = PropertiesList & GTPS(i).name & ":" & GTPS(i).value & vbNewLine

Next

MsgBox PropertiesList




GetROProperty is the method used to retrieve a specific value of an object during run time i.e., while the application is running. This property method is most widely used as most of the times the values in the application keep changing and you need to have the latest value available during the run session. This will ignore the value that is present in either Object repository or temperory vesrion of the object for the specified property and will get it only from application during the run session.

I am using the same example here also. 

Dim GRP 

Browser("Google").Page("Google").WebButton("Google Search").Click

Browser("Google").Page("Google").WebButton("Google Search").SetTOProperty "name", "My Search" 'changing the name of the button from Google Search to My Search 

GRP=Browser("Google").Page("Google").WebButton("Google Search").GetROProperty("name")

'Retrieving the Runtime value of the object from the application 

Msgbox "Result when Get RO property is used: "&GRP



In short, SetTOProperty is used only when:

-- Some property value of an object has to be changed during run time. 

GetTOProperty is used when either

-- Some property value has been set using SetTOProperty and the updated value has to be used in the test Or

-- To make use of the value that is present in the temp version(i.e., Object repository value if nothing is changed) instead of using actual value in the application during the run time. 

GetROProperty is used when:

-- Actual property value of an object (whose values keep changing) should be used in the test during the run session.

No comments:

Post a Comment