0% found this document useful (0 votes)
5 views5 pages

QTP Script Statement Overview

i) QTP uses different types of statements in test scripts including declarations, comments, utility statements, object calls, flow control statements, function/action calls, check points, output value statements, synchronization points, and VBScript statements. ii) Declarations are used to define variables and constants. Comments explain parts of the script using apostrophes or the Rem command. Utility statements launch applications and perform tasks like closing processes. iii) Object calls interact with application objects using identifiers. Flow control statements include if/else, select case, loops, and more to control script flow. Functions/actions group reusable steps.

Uploaded by

kiranpatil570
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

QTP Script Statement Overview

i) QTP uses different types of statements in test scripts including declarations, comments, utility statements, object calls, flow control statements, function/action calls, check points, output value statements, synchronization points, and VBScript statements. ii) Declarations are used to define variables and constants. Comments explain parts of the script using apostrophes or the Rem command. Utility statements launch applications and perform tasks like closing processes. iii) Object calls interact with application objects using identifiers. Flow control statements include if/else, select case, loops, and more to control script flow. Functions/actions group reusable steps.

Uploaded by

kiranpatil570
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

QTP Test

Types of Statements in QTP Test


We use different types of statements in QTP Test or Test script

i) Declarations
a) Declaring Variables

Dim strCity, intNum, objExcel, myDate

strCity="Hyderabad"
intNum=100
myDate=#10/10/2010#
Set objExcel=CreateObject("[Link]")

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("[Link]")

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("[Link]")

iii) Utility Statements


Examples:

a) Launching Windows based applications


[Link] "C:\Program Files\HP\QuickTest
Professional\samples\flight\app\[Link]"

Or
InvokeApplication "C:\Program Files\HP\QuickTest
Professional\samples\flight\app\[Link]"

b) Launching Web based applications


[Link] "C:\Program Files\Internet Explorer\[Link]","[Link]"

c) Closing all decent process


[Link]

d) Defining Test Result

[Link] micPass,"Result","Test Passed"

[Link] micFail,"Result","Test Failed"

e) Using environment Variables


[Link]("ProductDir")

f) DataTable Operations
'Adding a Sheet to Run-Time DataTable
[Link] "Gcreddy"

iv) Object Calls


Examples:

a) Standard Windows Environment


Dialog("Login").WinButton("Cancel").Click

b) Visual Basic Environment


VbWindow("CALCULATOR").VbButton("CLEAR").Click

c) Web Environment
Browser("Google").Page("Google").Link("Gmail").Click

v) Flow Control Statements


a) Using If statement

If Total=Tickets*Price  Then
          [Link] micPass,"Res","Total is Correct"
          Else
   [Link] micFail,"Res","Total is InCorrect"
End If
b) Using Select case Statement

Select Case Keyword
                   Case "ln"
                             Result=Login("gcreddy@[Link]","abcd")
          DataTable(7,"TestStep")=Result

                             Case "ca"


                             Close_App()

                             Case "rn"


                             Result=Register("gcreddy2@[Link]")
          DataTable(7,"TestStep")=Result

                     Case "al"


                             Result=App_Launch()
          DataTable(7,"TestStep")=Result
                   End Select

c) Using For…Next Loop

For i=1 to MRowCount Step 1


          [Link](i)
          ModuleExe=DataTable(3,"Module")
         
          If UCase(ModuleExe)="Y"  Then
                   ModuleID=DataTable(1,"Module")
          Next

d) Using While…Wend Statement

While [Link]=False
[Link] [Link]("DriveName"), _
[Link]("DriveDescription")
[Link]
Wend

e) Using Do While …Loop

Do While [Link]=False
a=[Link] ("Agent")
b=[Link] ("Pwd")
[Link] a &","& b
r=r+1
[Link]
Loop

f) Using Do Until …Loop

Do Until [Link]
a=[Link] ("gcreddy")
b=[Link] ("qtp")
[Link] a &","& b
r=r+1
[Link]
Loop

g) Using For Each …Next

For Each element In x


msgbox element
Next

vi) Function/Action Calls

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

vii) Check point statements
Window("Flight Reservation").WinEdit("Name:").Check CheckPoint("Name:")

viii) Output value statements


Window("Flight Reservation").WinButton("Update Order").Output CheckPoint("Update
Order")

ix) Synchronization point statements


Window("Flight Reservation").WinButton("Delete Order").WaitProperty "enabled", True,
30000

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")

e) Declaring Variables using Public statement

Public strName, intPhNumber

'******************************************

You might also like