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"

Monday, August 20, 2012

QTP Methods


       QTP methods are used to extract the properties of a selected object in an application, There are some list of properties that comes under QTP methods,
  1. Capture Bitmap
  2. Child Objects
  3. GetRoProperty
  4. GetToProperty
  5. GetToProperties
  6. SetToProperty
  7. GetVisibleText
  8. GetItem
  9. GetContent
  10. GetItemsCount       
Note: The properties under 8, 9, 10 indicates the (List & Combobox) so using the above properties we can enhance the qtp scripts more effective as per the business requirements with respect to the project.

Monday, August 13, 2012

Descriptive Programming (DP) in QTP


                         Descriptive Programming in QTP will be write in the case of the objects are not present in the Object Repository (OR), This method of programming reduces the time for automation testers in the time of CR in the project, Reduces the storage of space as compared to storage of objects, also avoids the modification of objects in the object repository.

There are two types of Programming in DP:

1. Static programming
2. Dynamic Programming

Static Programming:
 
 Syntax:

Window("Property1:=Value1","Property2:=Value2").Object("Property1:=Value1","Property2:=Value2"). Operation

The above syntax is the sample for static programming in qtp and below are the some of the Properties and Test Objects that we used in static method.




Web:

ClassName --> Micclass
Name --> WebEdit, Browser, Link, Image, WebCheckBox, webRadioGroup
URL --> Link, Image
href --> Link, Image

HWND:

alt --> Image
FileName --> WebCheckBox, WebRadioGroup, Image
Selection --> WebRadioGroup
Height
Width
x
y
abs_x
abs_y
Class --> WebElement
title --> page

Below i written a sample script for Yahoo login in static method:

Browser("Name:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!").WebEdit("Name:=login").Set"username"
Browser("Name:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!").WebEdit("Name:=Passwd").Set"passwd"
Browser("Name:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!").WebCheckBox("Name:=.persistent").Set"ON"
Browser("Name:=Yahoo! Mail: The best web-based email!").Page("title:=Yahoo! Mail: The best web-based email!").WebButton("Name:=Sign In").Click

Dynamic Programming:

Syntax:

1. SetObjname=Description.Create
2. ObjName("Prperty Name").Value=Property Value

Below i written a sample script for Google Search the keyword (QTP) in Dynamic method, save the below script as (filename.vbs) in any path in the Desktop:


Set Brw=Description.Create
Brw("Name").value="Google"
Set Pge=Description.Create
Pge("Title").value="Google"
Set txt=Description.Create
txt("Name").value="q"
Set btn=Description.Create
btn("Name").value="QTP"

Save the above script (filename.vbs) in any path in the Desktop:

Execute file "file.vbs"
Browser(brw).Page(pge).WebEdit(q).Set"Search"
Browser(brw).Page(pge).WebButton(btn).Click
Set brw=nothing
Set pge=nothing

While executing the above scripts in QTP (Execute file "file.vbs") script will refer the main script stored in the desktop as vbs file, the saved file can be use as a reusable framework and can be modify the objects as per the project business requirements when it's needed.

Below i written a sample scripts for (default available in QTP) Flight Reservation windows application in Dynamic method, save the below script as (flight.vbs) in any path in the Desktop:

Set lgn=Description.Create
lgn("text").value="Login"
Set uname=Description.Create
uname("attached text").value="Agent Name:"
Set pwd=Description.Create
pwd("attached text").value="Password:"
Set btn=Description.Create
btn("text").value="OK"
Set fr=Description.Create
fr("text").value="Flight Reservation"
Set dof=Description.Create
dof("attached text").value="Date of Flight:"
dof("nativeclass").value="MSMaskWndClass"
Set flyfrm=Description.Create
flyfrm("attached text").value="Fly From:"
Set flyto=Description.Create
flyto("attached text").value="Fly To:"
Set btn1=Description.Create
btn1("text").value="FLIGHT"
Set ft=Description.Create
ft("text").value="Flights Table"
Set list=Description.Create
list("attached text").value="From"
list("window id").value=2001
Set edit=Description.Create
edit("window id").value="1014"
Set radio=Description.Create()
radio("text").value="Business"
radio("regexpwndtitle").value="Business"
radio("windowstyle").value="1342177289"
Set orderbtn=Description.Create()
orderbtn("micclass").value="WinButton"
orderbtn("regexpwndtitle").value="&Insert Order"
Set updateorder=Description.Create()
updateorder("regexpwndtitle").value="&Update Order"

Save the above script (flight.vbs) in any path in the Desktop:


Executefile"C:\Documents and Settings\Bhaskar\Desktop\flight.vbs"
Dialog(lgn).winedit(uname).Set"admin"
Dialog(lgn).winedit(pwd).Set"mercury"
Dialog(lgn).winbutton(btn).Click
Window(fr).winobject(dof).type"08/24/12"
Window(fr).wincombobox(flyfrm).Select(1)
Window(fr).wincombobox(flyto).Select(2)
Window(fr).winbutton(btn1).Click
Window(fr).Dialog(ft).winlist(list).Select(2)
Window(fr).Dialog(ft).Winbutton(btn).Click
Window(fr).WinEdit(edit).Set"Antony"
WIndow(fr).WinRadioButton(radio).Set
Window(fr).WinButton(orderbtn).Click
Window(fr).WinButton(updateorder).Click

While executing the above scripts in QTP (Execute file "flight.vbs") script will refer the main script stored in the desktop as vbs file,

Friday, August 10, 2012

QTP Crypt Object


Crypt Object in QTP is used to Encrypt the given password, This scenario is just to confirm whether the given password is saving as Encrypted, This object is used in different ways in different methods,
Below scripts are done for a sample login page, to show how the given password is encrypted before the page get login

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE",
"test.sso.com"
Browser("IdPInitiated:Identity").Page("IdPInitiated:Identity").WebEdit("txtUserName").
Set"68testuser1"
pwd="abc123"
e_pwd=Crypt.Encrypt(pwd)
msgbox e_pwd
Browser("IdPInitiated:Identity").Page("IdPInitiated:Identity").WebEdit("txtPassword").SetSecure e_pwd
Browser("IdPInitiated:Identity").Page("IdPInitiated:Identity").WebButton("Login").Click
Browser("IdPInitiated:Identity").Page("SPInitiated:Identity Provider").WebButton("Goto Sdp").Click

















Before the password is getting entered it gets encrypted and shows the encrypted text in the (msgbox) as we declared in the script, Once the 'OK' button is clicked from the msgbox, the password get entered in to the password field for the next step to the login.

There is another method the password get encrypted directly to the password field for login by declaring below variable in different object method

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE",
"test.sso.com"
Browser("IdPInitiated:Identity").Page("IdPInitiated:Identity").WebEdit("txtUserName").
Set"68testuser1"
password = "abc123"
sEncryptedPwd = Crypt.Encrypt(password)
Browser("IdPInitiated:Identity").Page("IdPInitiated:Identity").WebEdit("txtPassword").Set"abc123"
Browser("IdPInitiated:Identity").Page("IdPInitiated:Identity").WebButton("Login").Click
Browser("IdPInitiated:Identity").Page("SPInitiated:Identity Provider").WebButton("Goto Sdp").Click

Thursday, August 9, 2012

Web based Test Objects and Test Operations


Test object is an object that qtp creates in the test to represent the actual object in the application.
Below are some of the web application Test Objects, based on the below syntax the test objects are been placed.

Syntax:

In which browser.In which page.In which object.what operation

As per above syntax the below script will be generate,

Browser("BrowserName").Page("PageName").Object("ObjectName").Operation

For Example:

Browser("Google").Page("Google").webedit("q").set "QTP 11.0"
Browser('Google").Page("Google").webbutton("Googlesearch").Click

Properties of an Object Names:

Browser Name: Google
Page Name: Google
Edit box: q
Button Name: Googlesearch

Test Objects:














Test Operations:

There will be no change in Test Operations, For and Windows the test operations will be same 



Wednesday, August 8, 2012

Windows based Test Objects and Test Operations


Below are some of the windows application Test Objects, Based on the object stored in repository the test objects are been created in Recording and also by manually giving the scripts in test window.

Syntax:

In which window.In which object.what operation

window("Window Name").Object("Object Name").Operation

As per above syntax below script will be generate for windows based application













Also here i given some of the operation that can be perform based on the created Test Object, listed operation is common for both web and windows based application.




Types of Objects


1. Run Time Object:

        Physical description of an object is called an run time object.
Ex:  (Editor, Button, Link, Checkbox, RadioButton, ComboBox, Window, DialogBox)

2. Test Object:

         This is the reference of Run Time Object used to write the test script based on the application environment,
Ex: (WinEdit, WebButton, VBCheckbox, Swfwindow)

3. Automation Object (or) User defined Object:

           The user can create that can be used across the project, The objects can stored in Repository as like in below format,

        Local Repository --> (.mtr)
        Shared --> (.tsr)

Tuesday, August 7, 2012

Concept of Object Repository (OR)


Add Objects:

Resources --> Object Repository (Ctrl+R) --> Objects --> Add Objects to Local --> Choose the Auto (or) Object --> All object Type

By doing above operations in Resources menu in QTP objects are been added                         
Save OR:

OR - Window --> Export Local Object -->  File Name

By doing above operations in Object Repository menu under Resources in QTP OR is saved.

Associate Repository:

Resources --> Associate Repository --> (+) click --> Choose tsr file --> Available Action --> Action 1 -->   Associate Action --> OK

By doing above operations the created objects (.tsr) are been added to the Associate Repository

(or)

we can add the path of the .tsr file which indicates the repository where it get stored

RepositoriesCollection.Add "C:\Program Files (x86)\HP\QuickTest Professional\TSR\flight.tsr"
Systemutil.Run(""C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4b.exe")
Dialog("Login").Active
Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close

So, as per the above script if the qtp play backs these scripts, even if the objects are not assigned to associate repository (RepositoriesCollection.Add "C:\Program Files (x86)\HP\QuickTest Professional\TSR\flight.tsr") the given script will bring the stored objects from the targeted path.

Keyword Driven

Object:

         As very simple to describe about object, "Each and everything that we seeing in Application is called an Object", The identified objects are been stored in object repository,

                          QTP --> OR --> Application

        When the QTP play back the recorded scripts, At first QTP will look for objects that we stored in the repository, "Object Repository" is the place where it holds its properties and its values, Here we can store all the object information's which is available  in the application, and it acts as a interface between QTP and Application

Steps to go for Object Repository:

1. Open QTP
2. Click on "Resources" menu
3. Click on "Object Repository" (Ctrl+R)

After the above steps, Click on "Add Objects to local" Menu



















In above screenshot i just captured the all objects of "www.google.co.in", Here the selected Test Object is "Google" the object Properties of the google is the same highlighted in Right side of the page,

Name: Google
Class: Browser
Repository: Local (Stored in Local system)

By having the above object properties we can generate the script without recording, since the captured object is get stored in local,

Browser("Google").Page("Google").WebEdit("q").Set"QTP"
Browser("Google").Page("Google").WebButton("Google Search").Click

the above script will "Google Search" the word "QTP" once it get playback from the "Object Repository"

Monday, August 6, 2012

Generation of Scripts for Windows Application

Record and Playback:

Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close

Above scripts are recorded for default "flight reservation" free windows application available in QTP,

Variation of scripts for Windows and Web:

There are some difference in scripts that we can see here for recording windows and web application,
for web application we are using the "object" of the text box as WebEdit (" ") and for button "WebButton"
for windows application the "object" of the text box here we used as WinEdit(" ") and for button "WinButton".

By keeping the above recorded scripts to bring up the same for the basic framework level we need to implement some validation codes to run the recorded scripts once giving play back in QTP,

Systemutil.Run(""C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4b.exe")
Dialog("Login").Active
Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close

The above code will give the best output while QTP play back the scripts.

Dialog("Login").Active -  Indicates the login window should active to display whenever the user playback the scripts

Sunday, August 5, 2012

Generation of Scripts for Web Application

Record and Playback:

Browser("name of the application in the browser").Page("name of the page in the browser").object("name of the object identified").Operation

So, This is the basic steps of how QTP generates the scripts while Recording.

The above scripts will be play back once the browser is in default open state, If the browser is closed and you need to play back the script automatically in qtp just you need to add the below script,

Systemutil.run"C:\Program Files\Internet Explorer\iexplore.exe","www.google.co.in"
Browser("name of the application in the browser").Page("name of the page in the browser").object("name of the object identified").Operation

Outcome of Running the QTP Scripts

1. Test Fusion Report
2. Customized Report (Framework)

Saturday, August 4, 2012

Debug the QTP Scripts

1. Pause
2. Step into
3. Stepout
4. Stepover
5. Debug Viewer

Enhancing the Scripts for Automation

1. VB Scripts
2. QTP Methods
3. Parameterization
4. Checkpoints
5. Synchronization
6. Regular Expression
7. Recovery Scenarios
8. Environment Variable

Three types of Recording in QTP

1. Normal Recording
2. Analog Recording
3. Low Level Recording

Generation of QTP Scripts (Types)


1. Record and Playback
2. Keyword driven Method (Object Repository)
3. Descriptive Programming (Object Repository & Value)

Steps to follow before starting Automation

Analyze the Manual Test Cases
           
          a) Requirement Test suite creation
          b) Application Stability
          c) Implement the frame work

                     i) Linear Framework
                     ii) Data driven Framework
                     iii) Modular Framework
                     iv) Key-Word driven Framework
                      v) Hybrid Framework
                      vi) BPT Framework