Wednesday, July 21, 2010

QTP quick reference sample code

References:
http://qtp.blogspot.com/2007/05/checkpoints-in-qtp-quicktest.html
http://www.learnqtp.com/
http://www.qtp10.com/

Indexing:
Browser("Amazon.com: Online Shopping").Page("Amazon.com: Online Shopping").WebElement("Movies, Music & Games").Clickwait(5)Browser("Amazon.com: Online Shopping").Page("Amazon.com: Online Shopping").Link("Movies & TV").Clickwait(5)Browser("Amazon.com: Online Shopping").Page("Amazon.com Movies & TV:").Link("text:=Anime","index:=1").Click'Browser("Amazon.com: Online Shopping").WinToolbar("ToolbarWindow32").Click

---------------------
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\test","open"
Browser("Welcome: Mercury Tours").Page("Page").Sync
Browser("Welcome: Mercury Tours").CloseAllTabs
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("password").SetSecure "4c3c2d6874ae8db13192471656044dee3a37c0b6"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click 4,2
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebRadioGroup("tripType").Select "oneway"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select "Seattle"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").ActiveX("Java Plug-in 1.6.0_20").WinButton("View Calendar").Click
Window("Select Departure Date").WinButton("29").Click
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("toPort").Select "Portland"
Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").Image("findFlights").Click 57,14
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Sync




SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\test","open"

Browser("Welcome: Mercury Tours").Navigate "http://newtours.demoaut.com/"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Sync

Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("name:= userName", "type:=text").Set"mercury"
Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("name:= password", "type:=password").Set"mercury"

Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").Image("Sign-In").Click
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Link("outertext:=Hotels").Click
Browser("Welcome: Mercury Tours").Page("Select a Flight: Mercury").Link("name:=Image").Click
'Dialog("QuickTest Professional").Activate
'Dialog("QuickTest Professional").Activate


Browser(“Browser”).Page(“Page”).Link(“outertext=”&objval, “index=”&k).Click
--------------------------
Recording Types:
· Normal
· Analog
· Low level

Object Repository
· Local repository
· Shared repository - .tsr


Username – webedit – set
Radio button – webradiogroup – select
Password – setsecure –

Regular expression – User for dynamic objects
Object repository – change the outertext value.

Parameterization
Create an excel sheet in C drive and give the data to be parameterized
Add the following in the starting of the code
Datatable.importsheet “C:test.xls”
Un = datatable.value (“Username”)
Pwd = datatable.value (“password”)
Eml = datatable.value (“Email”)
Msgbox Un
Msgbox Pwd
Msgbox Eml

To get a particular row from datatable
Datatable.importsheet “C:test.xls”
R = datatable.getrowcount
For i= 2 to 3
Datatable.setcurrentrow (i)
Un = datatable.value (“Username”)
Pwd = datatable.value (“password”)
Eml = datatable.value (“Email”)
Msgbox Un
Msgbox Pwd
Msgbox Eml

To take alternative data from the datatable
R= datatable.getrowcount
Msgbox R
For i=1 to R step 2

Topics :
· Parametization
· Object spy
· Regular exp
· Action concept
· Data tables
· Basics of descriptive programming
· Virtual objects
· Recovery scenario

Example:
Datatable.importsheet "C:/test.xlsx,1,1"
Un = datatable.value ("Username")
Pwd = datatable.value ("password")
'Eml = datatable.value (“Email”)
Msgbox Un
Msgbox Pwd
'Msgbox Eml
SystemUtil.Run "iexplore","","C:\Documents and Settings\test",""
Browser("Browser").Page("Page").Sync
Browser("Browser").Navigate "http://www.amazon.com/"
Browser("Browser").Page("Amazon.com: Online Shopping").Link("Start here").Click
Browser("Browser").Page("Sign In").WebEdit("email").Set "yasothai@ustglobal.com"
Browser("Browser").Page("Sign In").WebRadioGroup("action").Select "new-user"
Browser("Browser").Page("Sign In").Image("sign in using our secure").Click 46,12
Browser("Browser").Page("Amazon.com Registration").WebEdit("userName").Set "Un"
Browser("Browser").Page("Amazon.com Registration").WebEdit("emailCheck").Set "yasothai@ustglobal.com"
Browser("Browser").Page("Amazon.com Registration").WebList("month").Select "March"
Browser("Browser").Page("Amazon.com Registration").WebList("day").Select "06"
Browser("Browser").Page("Amazon.com Registration").WebEdit("password").Set Pwd
Browser("Browser").Page("Amazon.com Registration").WebEdit("passwordCheck").Set pwd
Browser("Browser").Page("Amazon.com Registration").Image("continue-blue-arrow._V19219331").Click 55,8


Checkpoint:
Instead of checkpoints they use IF conditions.
XML checkpoints & Database checkpoints are for standalone/desktop applications.
a. Standard
b. Text
c. Text area – used for desktop applications
d. Bitmap
e. Database
f. Accessibility
g. XML

IF condition instead of checkpoints:
Browser("welcome:Mercury Tours").page("welcome:mercury tours").webedit ("username").set "tutorial"
X= Browser("welcome:Mercury Tours").page("welcome:mercury tours").webedit ("username").GetROProperty("value")
If trim(x)="tutorial" then
Browser("welcome:Mercury Tours").page("welcome:mercury tours").webedit ("password").set "tutorial"
else reporter.ReportEvent.micfail."entering user name", "failed"
Y= Browser("welcome:Mercury Tours").page("welcome:mercury tours").webedit ("password").GetROProperty("value")
if trim( y)=tutorial then
Browser("welcome:Mercury Tours").page("welcome.mercury.tourse").image("sign-in").click
End if
End if

Paramterization
Browser(“Browser”).Page(“Page”).Link(“outertext=”&objval, “index=”&k).Click
Datatable.importsheet "D:\Data2.xls",1,1
Un = Datatable.Value ("Username")
Pwd = datatable.Value ("Password")
Msgbox Un
Msgbox Pwd
Datatable.value(“Res”)=”Pass”
Database.Export”D”\Data2.xls”

1.Record and Run a scenario
2. Runtime settings ->sync seconds =0; use page.sync
3.Object Repository
4.Regular Expressions
5. Capture “Anime” in Amazon.com using regular exp.
6. Create Objects in Object Repository and highlight in the application
7.Parameterization
- Import a sheet
-Run with diff set of username and passwd
- Set current row/particular row
8.Descriptive Programming
9.Recovery scenario


*Functions, Data table export, Get Runtime Object property, Fire event,

' record web page and click on insert checkpoints while recording
Browser("Sign-on: Mercury Tours").Page("Welcome: Mercury Tours").SyncBrowser("Sign-on: Mercury Tours").Navigate "http://newtours.demoaut.com/"Browser("Sign-on: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Set "tutorial"Browser("Sign-on: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Check CheckPoint("userName")'Window("Test Results").Page("Welcome: Mercury Tours").Check CheckPoint("Welcome: Mercury Tours")DbTable("DbTable").Check CheckPoint("DbTable")
Browser("Sign-on: Mercury Tours").Page("Sign-on: Mercury Tours").Image("html").Check CheckPoint("html")Dialog("QuickTest Professional").Activate

No comments: