Saturday, February 26, 2011

GetTOproperties, SetTOproperty, GetTOproperty & GetROproperty - methods explained with sample scripts.


Before we get started, I would like to take some time explaining about the TO, RO, Get and Set part of the methods.

TO : Stands for Test Object (The object that we have recorded in our object repository)
RO : Stands for Runt-time Object (The application object we are testing against the object in the Object repository)
Get : Is used to get (return) the current property/ies of a Run-time or a test object.
Set : Is used to set (return) the property of a test object.

GetTOproperties:
This method is used to return get the properties and their corresponding values from the recorded object in our object repository.

The following example explains the usage of GetTOproperties method:

'################################
'### Get TO Properties Script ###
'################################

systemutil.Run "iexplore.exe", "http://www.google.com"

Set oWebEdit=Browser("Google").Page("Google").WebEdit("q") 'Create webedit object

Set TOProperties=oWebEdit.GetTOProperties 'Get TO Properties

For i = 0 to TOProperties.count - 1 'Looping through all the properties
    sName=TOProperties(i).Name ' Name of the property
    sValue=TOProperties(i).Value 'Value of the property
    isRegularExpression=TOProperties(i).RegularExpression 'Is it a Regular expression
    Msgbox sName & " -> " & sValue & "->" & isRegularExpression 
Next

'##############
'### Result:###
'##############
' type -> ext -> true
' name -> q -> true
'### End of Script ####


SetTOproperty :

This method is used to set the value of a particular property of an object in the object repository.

GetTOproperty:

This method is used to get the current value of a property of an object in the object repository. If we had used the SetTOproperty method to change the existing property of an object in the OR, GetTOproperty method would only retrieve the current value of the property (ie, what ever value was set using SetTOproperty).

Note : Whatever value we set during the script execution is not retained after the execution is complete. The values in the OR automatically gets back to what it was at the beginning of the execution just like the run-time data tables.
'#############################################
'### Set TO Property & Get TO property ###
'#############################################

oldName = oWebEdit.GetTOProperty("name")
msgbox "Old Name ->" & oldName
oWebEdit.SetTOProperty "name","New Value"
NewName = oWebEdit.GetTOProperty("name")
msgbox "New Name ->" & NewName

'##############
'### Result:###
'##############
' Old Name ->q
' New Name ->New Value
'### End of Script ###


GetROProperty:
This method is used to get the runtime value of a property in an application object.

Note : SetROproperty method is not supported by QTP, hence it is unavailable.

'#######################
'### Get RO Property ###
'#######################

oWebEdit=Browser("Google").Page("Google").WebEdit("q").GetROProperty("value") 
msgbox oWebEdit

'###############
'### Result: ###
'###############

'### The text in the webedit control is displayed
'### End of Script ###


For more QTP & VBScripts click here.

1 comment:

  1. SetToProperty : SetToProperty change the value of test object during runtime. For example while testing a web application "name" property of web button was "Login" but in next release it changes to "Sign-In" but chnage is only for one build only & you got build very frequently so if you run your test , it will fail as in OR "name" is set as "Login" & in object it is "Sign-In". By using "SetToProperty" you can change its name property to "Login" to again & pass you test.
    This chnaged value is applicable for duration of test run only & does not affect OR,Active screen etc.Basic use of this property is when you dont want to add same type of multiple objects with different property description.

    ReplyDelete

Please leave your comment here...