qtp test script

Post on 09-Apr-2018

229 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

8/7/2019 QTP Test Script

http://slidepdf.com/reader/full/qtp-test-script 1/5

Visit: www.gcreddy.com  for QTP Information

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("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 toDatabases (any Daatabase)

Set objConnection=CreateObject("Adodb.Connection")

Ex2: Using Rem Command followed by spaceRem Creating an Automation Object in FileSystemObject Class, that can be used to perform

Operations on Computer File systemRem Using this Automation Object we can work with Folders and Files

Set objFSO=CreateObject("Scripting.FileSystemObject")

iii) Utility Statements

Examples:

a) Launching Windows based applications

SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

OrInvokeApplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

b) Launching Web based applications

SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","www.gcreddy.com"

c) Closing all decent process

G C Reddy (91-9247837478), QTP Trainer,INDIA1

8/7/2019 QTP Test Script

http://slidepdf.com/reader/full/qtp-test-script 2/5

Visit: www.gcreddy.com  for QTP Information

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 DataTableDataTable.AddSheet "Gcreddy"

iv) Object Calls

Examples:

a) Standard Windows Environment

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

b) Visual Basic EnvironmentVbWindow("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

Reporter.ReportEvent micPass,"Res","Total is Correct"Else

Reporter.ReportEvent micFail,"Res","Total is InCorrect"End If 

b) Using Select case Statement

Select Case Keyword

Case "ln"

Result=Login("gcreddy@yahoo.com","abcd")DataTable(7,"TestStep")=Result

Case "ca"

Close_App()

Case "rn"Result=Register("gcreddy2@gmail.com")

DataTable(7,"TestStep")=Result

G C Reddy (91-9247837478), QTP Trainer,INDIA2

8/7/2019 QTP Test Script

http://slidepdf.com/reader/full/qtp-test-script 3/5

Visit: www.gcreddy.com  for QTP Information

Case "al"

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

End Select

c) Using For…Next Loop

For i=1 to MRowCount Step 1

DataTable.SetCurrentRow(i)

ModuleExe=DataTable(3,"Module")

If UCase(ModuleExe)="Y" ThenModuleID=DataTable(1,"Module")

Nextd) Using While…Wend Statement

While objRecordset2.EOF=False

Wscript.Echo objRecordset2.Fields.Item("DriveName"), _

objRecordset2.Fields.Item("DriveDescription")objRecordSet2.MoveNextWend

e) Using Do While …Loop

Do While objRs.EOF=False

a=objRs.Fields ("Agent")b=objRs.Fields ("Pwd")

myFile.Writeline a &","& br=r+1

objRs.MoveNext

Loop

f) Using Do Until …Loop

Do Until objRs.EOFa=objRs.Fields ("gcreddy")

b=objRs.Fields ("qtp")

myFile.Writeline a &","& br=r+1

objRs.MoveNextLoop

g) Using For Each …Next

For Each element In x

msgbox elementNext

vi) Function/Action Calls

G C Reddy (91-9247837478), QTP Trainer,INDIA3

8/7/2019 QTP Test Script

http://slidepdf.com/reader/full/qtp-test-script 4/5

Visit: www.gcreddy.com  for QTP Information

a) Function calls

Dim myDatemyDate=Date

Msgbox myDateMsgbox NOW ‘Built-in Function

Call Login (“gcreddy”,”mercury”) ‘User defined Function

b) Action Calls

RunAction "Registration [Orders]", oneIteration

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

viii) Output value statementsWindow("Flight Reservation").WinButton("Update Order").Output CheckPoint("Update Order")

ix) Synchronization point statementsWindow("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")

G C Reddy (91-9247837478), QTP Trainer,INDIA4

8/7/2019 QTP Test Script

http://slidepdf.com/reader/full/qtp-test-script 5/5

Visit: www.gcreddy.com  for QTP Information

e) Declaring Variables using Public statement

Public strName, intPhNumber

 ‘*************************************************************

With Best Wishes

http://www.gcreddy.com/

G C Reddy (91-9247837478), QTP Trainer,INDIA5

top related