QTP : Methods GetTOproperties, GetTOproperty & GetROproperty
SetTOproperty : method is used to set the value of a particular property of an object in the object repository.
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.
'#############################################
'### Set TO Property
'#############################################
Systemutil.Run "iexplore.exe", "http://www.mail.yahoo.com"
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").Set "tester"
'Changing the login object name property value from "login" to "passwd"
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").SetTOProperty "name","passwd"
'Below statement enters value in password field
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").Set "xyz@123"
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebButton("Sign In").Click
'#############################################
'### Set TO Property & Get TO property ###
'#############################################
Systemutil.Run "iexplore.exe", "http://www.mail.yahoo.com"
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").Set "tester"
oldName = Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").GetTOProperty("name")
MsgBox oldName
'Changing the login object name property value from "login" to "passwd"
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").SetTOProperty "name","passwd"
'Below statement enters value in password field
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").Set "xyz@123"
newName = Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebEdit("login").GetTOProperty("name")
MsgBox newName
Browser("Yahoo! India").Page("Yahoo! Mail: The best").WebButton("Sign In").Click
'##############
'### Result:###
'##############
' Old Name ->login
' New Name ->passwd
'### End of Script ###
GetROProperty: This method is used to get the runtime value of a property in an application object.
'#######################
'### Get RO Property ###
'#######################
oWebEdit=Browser("Yahoo! India").Page("Yahoo! India").WebEdit("p") 'have some text entered in the username field
msgbox oWebEdit
'###############
'### Result: ###
'###############
'### text from username field will be displayed
'### End of Script ###
GetTOproperties: method is used to read the properties and their corresponding values from the test objects(Test Objects > Objects which are stored in object repository).
The following example explains the usage of GetTOproperties method:
'################################'###
'##### Get TO Properties Script
'################################
Systemutil.Run "iexplore.exe", "http://www.yahoo.com"
Set oWebEdit=Browser("Yahoo! India").Page("Yahoo! India").WebEdit("p") 'Create webedit object
Set TOProperties=oWebEdit.GetTOProperties 'Get TO Properties
For i = 0 to TOProperties.count - 1
sName=TOProperties(i).Name
sValue=TOProperties(i).Value
print sName & " -> " & sValue
Next
'##############
'### Result:###
'##############
name -> p
micclass -> WebEdit
html tag -> INPUT
abs_x -> 416
'### End of Script ####
Note:To run above scripts add two objects to OR, yahoo mail username field object and sign in button.
No comments:
Post a Comment