Qtp test

3,337 views

Published on

Types of Statements in QTP Test; Declarations, Comments, Utility Statements, Object Calls, Flow Control Statements, Function/Action Calls, Check point statements, Output value statements, Synchronization point statements, and VB Script statements.

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
3,337
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
226
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

Qtp test

  1. 1. Visit: www.gcreddy.com for QTP Information Types of Statements in QTP TestWe use different types of statements in QTP Test or Test scripti) Declarationsa) Declaring VariablesDim strCity, intNum, objExcel, myDatestrCity="Hyderabad"intNum=100myDate=#10/10/2010#Set objExcel=CreateObject("Excel.Application")b) Declaring ConstantsConst City="Hyderabad"Const Login="text:=Login", Agent="window id:=2001", Password="attached text:=Password:"ii) CommentsEx1: Using Apostrophe (‘) symbol before the StatementCreating 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 performOperations on Computer File systemRem Using this Automation Object we can work with Folders and FilesSet objFSO=CreateObject("Scripting.FileSystemObject")iii) Utility StatementsExamples:a) Launching Windows based applicationsSystemUtil.Run "C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe"OrInvokeApplication "C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe"b) Launching Web based applicationsSystemUtil.Run "C:Program FilesInternet ExplorerIEXPLORE.EXE","www.gcreddy.com"c) Closing all decent process G C Reddy (91-9247837478), QTP Trainer,INDIA 1
  2. 2. Visit: www.gcreddy.com for QTP InformationSystemUtil.CloseDescendentProcessesd) Defining Test ResultReporter.ReportEvent micPass,"Result","Test Passed"Reporter.ReportEvent micFail,"Result","Test Failed"e) Using environment VariablesEnvironment.Value("ProductDir")f) DataTable OperationsAdding a Sheet to Run-Time DataTableDataTable.AddSheet "Gcreddy"iv) Object CallsExamples:a) Standard Windows EnvironmentDialog("Login").WinButton("Cancel").Clickb) Visual Basic EnvironmentVbWindow("CALCULATOR").VbButton("CLEAR").Clickc) Web EnvironmentBrowser("Google").Page("Google").Link("Gmail").Clickv) Flow Control Statementsa) Using If statementIf Total=Tickets*Price Then Reporter.ReportEvent micPass,"Res","Total is Correct" Else Reporter.ReportEvent micFail,"Res","Total is InCorrect"End Ifb) Using Select case StatementSelect 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,INDIA 2
  3. 3. Visit: www.gcreddy.com for QTP Information Case "al" Result=App_Launch() DataTable(7,"TestStep")=Result End Selectc) Using For…Next LoopFor i=1 to MRowCount Step 1 DataTable.SetCurrentRow(i) ModuleExe=DataTable(3,"Module") If UCase(ModuleExe)="Y" Then ModuleID=DataTable(1,"Module") Nextd) Using While…Wend StatementWhile objRecordset2.EOF=FalseWscript.Echo objRecordset2.Fields.Item("DriveName"), _objRecordset2.Fields.Item("DriveDescription")objRecordSet2.MoveNextWende) Using Do While …LoopDo While objRs.EOF=Falsea=objRs.Fields ("Agent")b=objRs.Fields ("Pwd")myFile.Writeline a &","& br=r+1objRs.MoveNextLoopf) Using Do Until …LoopDo Until objRs.EOFa=objRs.Fields ("gcreddy")b=objRs.Fields ("qtp")myFile.Writeline a &","& br=r+1objRs.MoveNextLoopg) Using For Each …NextFor Each element In xmsgbox elementNextvi) Function/Action Calls G C Reddy (91-9247837478), QTP Trainer,INDIA 3
  4. 4. Visit: www.gcreddy.com for QTP Informationa) Function callsDim myDatemyDate=DateMsgbox myDateMsgbox NOW ‘Built-in FunctionCall Login (“gcreddy”,”mercury”) ‘User defined Functionb) Action CallsRunAction "Registration [Orders]", oneIterationvii) 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, 30000x) VB Script statementsExamples:a) Synchronization using Wait StatementWait 10b) Code Optimization Using With and End With StatementsWith Dialog("Login") .Activate .WinEdit("Agent Name:").Set "vdfdg" .WinEdit("Password:").SetSecure "4d52b150608f41854dfd1714582004f58c475d84" .WinButton("OK").ClickEnd Withc) Defining Private Functions using Private statementPrivate Function Login(UserId, Password)--------Statements--------------------End Functiond) Storing Object Reference using Set StatementSet myPage=Browser("QuickTest Professional").Page("QuickTest Professional") G C Reddy (91-9247837478), QTP Trainer,INDIA 4
  5. 5. Visit: www.gcreddy.com for QTP Informatione) Declaring Variables using Public statementPublic strName, intPhNumber‘*************************************************************With Best Wisheshttp://www.gcreddy.com/ G C Reddy (91-9247837478), QTP Trainer,INDIA 5

×