Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Tuesday, July 26, 2011

HP ALM11 Business Process Model Vedio


QTP Secret Code Chart Revealed For DeviceReplay PressKey, KeyDown, KeyUp and PressNKeys

QTP Secret Code Chart Revealed For DeviceReplay PressKey, KeyDown, KeyUp and PressNKeys



Why this post?
Let’s face it. If you’ve been doing test automation for any length of time you’ve faced situations in which you need to perform mouse or keyboard actions using screen coordinates.
When the Set and Type Methods Suck:
Even though most objects have Set and Type methods, these methods -- for whatever reason -- may not work in all situations. If they don’t then your next step may be to try VBSCript’s sendkey method. But even sendkeys sometimes do not have a way to perform certain actions, such as pressing the left alt key. Hence the need for QTP’s undocumented Device Replay features.
No ASCII No Problem:
A few months back, I posted an article outlining three different ways to use keyboard input in QTP. I recently came across some more Device Replay Key codes for the PressKey, Keydown, Keyup and PressNKeys that I’d like to share with you. These methods are particularly helpful in certain situations in which you need to perform an action using a code that does not have an ASCII equivalent.
Chart of the keyboard key codes for the PressKey, Keydown, Keyup and PressNKeys:
The number keys:
KeystrokeCode to use
11
22
33
44
55
66
77
88
99
00
The keypad number keys:
KeystrokeCode to use
179
280
381
475
576
677
771
872
973
082
The Function keys:
KeystrokeCode to use
F159
F260
F361
F462
F563
F664
F765
F866
F967
F1068
F1187
F1288
The Letter keys:
KeystrokeCode to use
A30
B48
C46
D32
E18
F33
G34
H35
I23
J36
K37
L38
M50
N49
O24
P25
Q16
R19
S31
T20
U22
V47
W17
X45
Y21
Z44
The Enter,Space,Shift,Ctrl and Alt keys:
KeystrokeCode to use
ENTER28
SPACE57
LEFT SHIFT42
LEFT CTRL29
LEFT ALT56
RIGHT SHIFT54
RIGHT CTRL157
RIGHT ALT184
;39
'40
,51
.52
/53
The Weird/Other keys:
KeystrokeCode to use
-12
[26
]27
`41
=13
BACKSPACE14
CAPSLOCK58
DELETE211
DOWN208
END207
HOME199
INSERT210
LEFT203
NUMLOCK69
KEYPAD DECIMAL83
KEYPAD DIVIDE181
KEYPAD ENTER156
KEYPAD MINUS74
KEYPAD MULTIPLY55
PAUSE116
PAGE DOWN209
PAGE UP201
RIGHT205
SCROLL LOCK70
TAB15
UP20O
Examples:
'Device Replay Example using the calculator with the multiple key
Set myReplay = Createobject("Mercury.DeviceReplay")
SystemUtil.Run "calc.exe"
Window("regexpwndtitle:=Calculator").Activate
myReplay.PressKey 73'9
wait 1
myReplay.PressKey 55' Keypad Multiply
wait 1
myReplay.PressKey 81'3
wait 1
myReplay.PressKey 156'Enter
The end result should be 27
'Device Replay Example using notepad with the shift key
Set myReplay = Createobject("Mercury.DeviceReplay")
SystemUtil.Run "notepad.exe"
wait 1
Window("nativeclass:=Notepad").Activate
wait 1
myReplay.KeyDown 42''Hold shift key down
wait 1
myReplay.PressKey 36'T
wait 1
myReplay.PressKey 24'H
wait 1
myReplay.PressKey 18'I
wait 2
myReplay.KeyUp 42'Press shift key up
wait 1
myReplay.PressKey 57 'space
wait 1
myReplay.PressKey 36' t
wait 1
myReplay.PressKey 24 'h
wait 1
myReplay.PressKey 18 ie
The example should type out: THIthi

QTP ASCII CHR() CODE CHART

                                             QTP ASCII CHR() CODE CHART





ASCII
Entering/Reading ASCII codes - when using QTP - is sometimes needed to achieve certain functionality.
ASCII stand for American Standard Code for Information Interchange and it is a character encoding scheme based on the English alphabet.
QTP has two built in functions (ASC and Chr) that are helpful to know when you need to work with ASCII info.
ASC() Function
ASC()  is a QTP function that returns the code of the character passed to it. For example if you wanted to know what the ASCII/ANSI code for the pound symbol #:
Msgbox Asc(“#”)
The above will return the code 35
Chr() Function
If you wanted to enter or search for the pound key in a string you would use the QTP Chr() function. This function will return the character associated with the code passed to it. For example:
Msgbox Chr(35)
This will return the pound sign.
Common ASCII codes for QTP
Here are some of the most common ASCII codes I often use in QTP:
QTP CODESYMBOLDESCRIPTION
Chr(34)"Double Quotes
Chr(10) Line Feed
Chr(13) Carriage Return
Chr(32) Space
Chart for all the QTP Chr() codes:
QTP CODESYMBOLDESCRIPTION
Chr(0)NULNull char
Chr(1)SOHStart of Heading
Chr(2)STXStart of Text
Chr(3)ETXEnd of Text
Chr(4)EOTEnd of Transmission
Chr(5)ENQEnquiry
Chr(6)ACKAcknowledgment
Chr(7)BELBell
Chr(8)BSBack Space
Chr(9)HTHorizontal Tab
Chr(10)LFLine Feed
Chr(11)VTVertical Tab
Chr(12)FFForm Feed
Chr(13)CRCarriage Return
Chr(14)SOShift Out / X-On
Chr(15)SIShift In / X-Off
Chr(16)DLEData Line Escape
Chr(17)DC1Device Control 1 (oft. XON)
Chr(18)DC2Device Control 2
Chr(19)DC3Device Control 3 (oft. XOFF)
Chr(20)DC4Device Control 4
Chr(21)NAKNegative Acknowledgement
Chr(22)SYNSynchronous Idle
Chr(23)ETBEnd of Transmit Block
Chr(24)CANCancel
Chr(25)EMEnd of Medium
Chr(26)SUBSubstitute
Chr(27)ESCEscape
Chr(28)FSFile Separator
Chr(29)GSGroup Separator
Chr(30)RSRecord Separator
Chr(31)USUnit Separator
Chr(32) Space
Chr(33)!Exclamation mark
Chr(34)"Double quotes (or speech marks)
Chr(35)#Number
Chr(36)$Dollar
Chr(37)%Procenttecken
Chr(38)&Ampersand
Chr(39)'Single quote
Chr(40)(Open parenthesis (or open bracket)
Chr(41))Close parenthesis (or close bracket)
Chr(42)*Asterisk
Chr(43)+Plus
Chr(44),Comma
Chr(45)-Hyphen
Chr(46).Period, dot or full stop
Chr(47)/Slash or divide
Chr(48)0Zero
Chr(49)1One
Chr(50)2Two
Chr(51)3Three
Chr(52)4Four
Chr(53)5Five
Chr(54)6Six
Chr(55)7Seven
Chr(56)8Eight
Chr(57)9Nine
Chr(58):Colon
Chr(59);Semicolon
Chr(60)<Less than (or open angled bracket)
Chr(61)=Equals
Chr(62)>Greater than (or close angled bracket)
Chr(63)?Question mark
Chr(64)@At symbol
Chr(65)AUppercase A
Chr(66)BUppercase B
Chr(67)CUppercase C
Chr(68)DUppercase D
Chr(69)EUppercase E
Chr(70)FUppercase F
Chr(71)GUppercase G
Chr(72)HUppercase H
Chr(73)IUppercase I
Chr(74)JUppercase J
Chr(75)KUppercase K
Chr(76)LUppercase L
Chr(77)MUppercase M
Chr(78)NUppercase N
Chr(79)OUppercase O
Chr(80)PUppercase P
Chr(81)QUppercase Q
Chr(82)RUppercase R
Chr(83)SUppercase S
Chr(84)TUppercase T
Chr(85)UUppercase U
Chr(86)VUppercase V
Chr(87)WUppercase W
Chr(88)XUppercase X
Chr(89)YUppercase Y
Chr(90)ZUppercase Z
Chr(91)[Opening bracket
Chr(92)\Backslash
Chr(93)]Closing bracket
Chr(94)^Caret - circumflex
Chr(95)_Underscore
Chr(96)`Grave accent
Chr(97)aLowercase a
Chr(98)bLowercase b
Chr(99)cLowercase c
Chr(100)dLowercase d
Chr(101)eLowercase e
Chr(102)fLowercase f
Chr(103)gLowercase g
Chr(104)hLowercase h
Chr(105)iLowercase i
Chr(106)jLowercase j
Chr(107)kLowercase k
Chr(108)lLowercase l
Chr(109)mLowercase m
Chr(110)nLowercase n
Chr(111)oLowercase o
Chr(112)pLowercase p
Chr(113)qLowercase q
Chr(114)rLowercase r
Chr(115)sLowercase s
Chr(116)tLowercase t
Chr(117)uLowercase u
Chr(118)vLowercase v
Chr(119)wLowercase w
Chr(120)xLowercase x
Chr(121)yLowercase y
Chr(122)zLowercase z
Chr(123){Opening brace
Chr(124)|Vertical bar
Chr(125)}Closing brace
Chr(126)~Equivalency sign - tilde
Chr(127) Delete

QTP Scripting Examples

         QTP Scripting Examples



 'Count Lines in a Text File

Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents and Settings\Administrator\Desktop\qtpthiru.txt")

While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
objTextstream.ReadLine
Wend
Msgbox LineCount

objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing


'Read a Text File from 4th line and perform Data Driven Testing for Login operation

Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents andSettings\Administrator\Desktop\qtpthiru.txt")

While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
myLine=objTextstream.ReadLine
If LineCount >= 4 Then
        myField=Split(myLine,",")
    SystemUtil.Run "C:\Program Files\HP\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTestProfessional\samples\flight\app\","open"
    Dialog("Login").Activate
    Dialog("Login").WinEdit("Agent Name:").Set myField(0)
    Dialog("Login").WinEdit("Password:").Set myField(1)
    Wait 2
    Dialog("Login").WinButton("OK").Click
    Window("Flight Reservation").Close
End If

Wend

objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing

'Read a Text File from 4th line to 6th Line and perform Data Driven Testing for Login operation

Dim objFso, objTextstream, LineCount
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objTextstream=objFso.OpenTextFile ("C:\Documents and Settings\Administrator\Desktop\qtpthiru.txt")

While objTextstream.AtEndOfStream=False
LineCount=LineCount+1
myLine=objTextstream.ReadLine
If LineCount >= 4 and LineCount<=6 Then
        myField=Split(myLine,",")
    SystemUtil.Run "C:\Program Files\HP\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTestProfessional\samples\flight\app\","open"
    Dialog("Login").Activate
    Dialog("Login").WinEdit("Agent Name:").Set myField(0)
    Dialog("Login").WinEdit("Password:").Set myField(1)
    Wait 2
    Dialog("Login").WinButton("OK").Click
    Window("Flight Reservation").Close
End If

Wend

objTextstream.Close
Set objTextstream=Nothing
Set objFso=Nothing

'Open 1 to 10 Orders in Flight Reservation Application and export all fields to excel file (3rd sheet)
 

Dim objExcel, objWorkbook, objWorksheet

Set objExcel=CreateObject("Excel.Application")
Set objWorkbook=objExcel.Workbooks.Open("C:\Documents andSettings\Administrator\Desktop\qtpthiru.xls")
Set objWorksheet=objWorkbook.Worksheets(3)
 

objWorksheet.Cells(1,1)="OrderNo"
objWorksheet.Cells(1,2)="Date of Flight"
objWorksheet.Cells(1,3)="Fly From"
objWorksheet.Cells(1,4)="Fly To"
objWorksheet.Cells(1,5)="C_Name"
objWorksheet.Cells(1,6)="Tickets"

For i= 1 to 10 Step 1
    Window("Flight Reservation").Activate
    Window("Flight Reservation").WinButton("Button").Click
    Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
    Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
    Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click

objWorksheet.Cells(i+1,1)=i
    Wait 1
    objWorksheet.Cells(i+1,2)= Window("Flight Reservation").WinObject("Date of Flight:").GetROProperty("text")
    Wait 1
    objWorksheet.Cells(i+1,3) = Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")
    Wait 1
    objWorksheet.Cells(i+1,4)= Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("text")
    Wait 1
    objWorksheet.Cells(i+1,5) = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
    Wait 1
    objWorksheet.Cells(i+1,6) = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
   
Next
objWorkbook.Save
objExcel.Quit

Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing

Loading...