Tuesday, September 4, 2012

GetROProperty Method in QTP

   
                    GetROProperty method is used to identify an object in an Run time, It retrieves the properties and values where the QTP is recorded also the property is listed in the script. 

Here we can see the few examples that how the Getroproperty is work for an real time applications.
Below scripts will get the entire object properties in a msgbox for the declared unique properties in the scripts. So that we can ensure those object Properties are present in the application.

'www.google.com

Set wsh=Createobject("wscript.shell")
Set olink=Description.Create
olink("micclass").value="Link"
Set olinkcoll=Browser("name:=Google").Page("title:=Google").ChildObjects(olink)
'The script will pass the total number of links present in the message box
msgbox olinkcoll.count
For i=0 to olinkcoll.count -1
lslink=olinkcoll(i).getroproperty("name")
lsurl=olinkcoll(i).getroproperty("text")
wsh.Popup lslink,1,"The link name is"
wsh.Popup lsurl,1,"The url of the link is"
Next

'www.yahoo.com

Set wsh=Createobject("Wscript.Shell")
Set olink=Description.Create
olink("micclass").value="Link"
Set olinkcoll=Browser("name:=Yahoo! India").Page("title:=Yahoo! India").ChildObjects(olink)
'The script will pass the total number of links present in the message box
msgbox olinkcoll.count
For i=0 to olinkcoll.count-1
lslink=olinkcoll(i).GetROProperty("name")
lsurl=olinkcoll(i).GetRoproperty("Link")
wsh.Popup lslink,1,"The Link name is"
wsh.Popup lsurl,1,"The url of the link is"

'www.rediff.com

Set wsh=CreateObject("Wscript.Shell")
Set olink=Description.Create
olink("micclass").value="name"
Set olinkcoll=Browser("name:=Rediff.com - India, Business, Stock, Sports, Cricket, Entertainment, Bollywood, Music, Video and Breaking news, Rediffmail NG, Shopping").Page("title:=Rediff.com - India, Business, Stock, Sports, Cricket, Entertainment, Bollywood, Music, Video and Breaking news, Rediffmail NG, Shopping").ChildObjects(olink)
'The script will pass the total number of links present in the message box
msgbox olinkcoll.Count
For i=0 to olinkcoll.count-1
lslink=olinkcoll(i).GetROProperty("name")
lsurl=olinkcoll(i).GetROProperty("Link")
wsh.Popup lslink,1,"The link name is"
wsh.Popup lsurl,1,"The url of the link is"
Next

'Default flight Application


Dlgname=Dialog("nativeclass:=#32770").GetROProperty("text")
msgbox Dlgname
lsbtnstatus=Dialog("text:="&Dlgname).winbutton("text:=OK").getroproperty("enabled")
If lsbtnstatus Then
msgbox "PASS"
End if



Monday, September 3, 2012

Child Objects Method in QTP


 Child Objects

              This method will display the count of the needed objects that we needed specifically from the application.

For Example:

           1. We might be need the no. of Links (Links)
           2. We might be need the no. of Buttons (WinButton, WebButton)
           3. We might be need the no. of Editbox (WinEdit, WebEdit)  

To display the count of the objects present in the same name we can declare the below syntax.

Example: 1

'Display the count of the links present in the google page:

Set lnk=Description.Create
lnk("micclass").value="Link"
Set brw=Description.Create
brw("name").value="Google"
Set olinks=Browser("name:=Google").Page("title:=Google").ChildObjects(lnk)
msgbox olinks.count

Example: 2

'Display the count of the buttons present in the qtp default flight application landing page:

Set btns=Description.Create
btns("micclass").value="WinButton"
Set dlg=Description.Create
dlg("name").value="Login"
Set ocollection=Dialog("text:=Login").ChildObjects(btns)
msgbox ocollection.count

Example: 3

'Display the count of the Edit Boxes present in the qtp default flight application landing page:

Set btns=Description.Create
btns("micclass").value="WinEdit"
Set dlg=Description.Create
dlg("name").value="Login"
Set ocollection=Dialog("text:=Login").ChildObjects(btns)
msgbox ocollection.count


Capture Bitmap Method in QTP


Capture Bitmap:

            This method is used to capture the image from the selected object. The captured image will be save in the given path in the bitmap (.bmp) format. Below syntax will show how to insert this (Capture Bitmap) property in to the script

Syntax:
Objhierarchy.Capturebitmap"filename.bmp",True

Example: Scripts to capture Google window:

Browser("Google").Capturebitmap "C:\name.bmp", True
'True is used to exist the image if it  is already present in the path
Browser("Google").Window("security Alert").Capturebitmap  "C:\filename.bmp",True

Capture a Desktop:
Desktop.Capturebitmap"D:\Desktop.bmp",True

Above are some of the sample scripts that describes the property of "Capture Bitmap"