Types of Statements in QTP Test: I) Declarations
Types of Statements in QTP Test: I) Declarations
Types of Statements in QTP Test: I) Declarations
www.gcreddy.com
i) Declarations
a) Declaring Variables
Dim strCity, intNum, objExcel, myDate
strCity="Hyderabad"
intNum=100
myDate=#10/10/2010#
Set objExcel=CreateObject("Excel.Application")
b) Declaring Constants
Const City="Hyderabad"
Const Login="text:=Login", Agent="window id:=2001", Password="attached text:=Password:"
ii) Comments
Ex1: Using Apostrophe () symbol before the Statement
'Creating an Automation Object in Database Connection Class, that can be used to connect to
Databases (any Daatabase)
Set objConnection=CreateObject("Adodb.Connection")
Ex2: Using Rem Command followed by space
Rem Creating an Automation Object in FileSystemObject Class, that can be used to perform
Operations on Computer File system
Rem Using this Automation Object we can work with Folders and Files
Set objFSO=CreateObject("Scripting.FileSystemObject")
G C Reddy
Visit:
www.gcreddy.com
SystemUtil.CloseDescendentProcesses
d) Defining Test Result
Reporter.ReportEvent micPass,"Result","Test Passed"
Reporter.ReportEvent micFail,"Result","Test Failed"
e) Using environment Variables
Environment.Value("ProductDir")
f) DataTable Operations
'Adding a Sheet to Run-Time DataTable
DataTable.AddSheet "Gcreddy"
G C Reddy
Visit:
www.gcreddy.com
Case "al"
Result=App_Launch()
DataTable(7,"TestStep")=Result
End Select
c) Using ForNext Loop
For i=1 to MRowCount Step 1
DataTable.SetCurrentRow(i)
ModuleExe=DataTable(3,"Module")
If UCase(ModuleExe)="Y" Then
ModuleID=DataTable(1,"Module")
Next
d) Using WhileWend Statement
While objRecordset2.EOF=False
Wscript.Echo objRecordset2.Fields.Item("DriveName"), _
objRecordset2.Fields.Item("DriveDescription")
objRecordSet2.MoveNext
Wend
e) Using Do While Loop
Do While objRs.EOF=False
a=objRs.Fields ("Agent")
b=objRs.Fields ("Pwd")
myFile.Writeline a &","& b
r=r+1
objRs.MoveNext
Loop
f) Using Do Until Loop
Do Until objRs.EOF
a=objRs.Fields ("gcreddy")
b=objRs.Fields ("qtp")
myFile.Writeline a &","& b
r=r+1
objRs.MoveNext
Loop
g) Using For Each Next
For Each element In x
msgbox element
Next
G C Reddy
Visit:
www.gcreddy.com
a) Function calls
Dim myDate
myDate=Date
Msgbox myDate
Msgbox NOW Built-in Function
Call Login (gcreddy,mercury) User defined Function
b) Action Calls
RunAction "Registration [Orders]", oneIteration
x) VB Script statements
Examples:
a) Synchronization using Wait Statement
Wait 10
b) Code Optimization Using With and End With Statements
With Dialog("Login")
.Activate
.WinEdit("Agent Name:").Set "vdfdg"
.WinEdit("Password:").SetSecure "4d52b150608f41854dfd1714582004f58c475d84"
.WinButton("OK").Click
End With
c) Defining Private Functions using Private statement
Private Function Login(UserId, Password)
-------Statements
------------------End Function
d) Storing Object Reference using Set Statement
Set myPage=Browser("QuickTest Professional").Page("QuickTest Professional")
G C Reddy
Visit:
www.gcreddy.com
http://www.gcreddy.com/
G C Reddy