Академический Документы
Профессиональный Документы
Культура Документы
Session-4: Agenda
QTP Scripting language Declaring variables Operators If statement overview Case statement overview For statement overview While & do While loop overview Functions overview Call Statement Procedure overview Difference between functions & procedures Creating a library file SystemUtil Object Q&A
2
Declaring Variables
Variables can be declared explicitly in the script using 1. Dim statement 2. Public statement 3. Private statement
For example,
Dim Degrees
Operators
Arithmetic operators example: +, -, *, /
Assignment operators
example: = Comparison operators example: <, =,<>, <= Concatenation operators example: &, + Logical operators example: Not, And ,Or
If statement overview
Conditionally executes a group of statements, depending on the value of an expression. Syntax: If condition Then statements [Else elsestatements] End If Eg: OrderNo = InputBox("Enter Order Number") If OrderNo <= 0 Then Msgbox "You entered an invalid order number." Else Msgbox "You entered valid order number." End If
6
statements-n: One or more statements executed if testexpression matches any part of expressionlist-n.
elsestatements-n: One or more statements executed if test expression doesn't match any of the Case clauses.
For Statement
Repeats a group of statements a specified number of times. SYNTAX For counter = start To end [Step step] [statements] [Exit For] [statements] Next Arguments Counter : Numeric variable used as a loop counter. Start : Initial value of counter. End : Final value of counter. Step : Amount counter is changed each time through the loop . If not specified, step defaults to one. The step argument can be either positive or negative.
10
For Statement(contd.)
Statements: One or more statements between For and Next that are executed the specified number of times. Eg: For I = 1 To 10 For J = 1 To 10 For K = 1 To 10 ... Next Next Next
11
Syntax:
Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop
12
13
Loop
14
WhileWend Statement
Executes a series of statements as long as a given condition is True. While condition [statements] Wend Arguments
condition
- Numeric or string expression that evaluates to True or False. If condition is Null, condition is treated as False. statements - One or more statements executed while condition is True.
15
Msgbox Counter
Wend
16
Exit Statement
Exit statement: Exits a block of Do...Loop, For...Next, Function, or Sub code. Exit Do Exit For Exit Function
Exit Sub
17
Functions Overview
Function: A name that define the behavior/ or a collection of the statement that on complete execution return some value to the caller The creation of function starts with the Function keyword and closes with End Function. SYNTAX [Public [Default] | Private] Function name [(arglist)]
[statements]
[name = expression] [Exit Function] [statements] [name = expression] End Function
18
Function Example
Example: Function MyFunction(text)
MsgBox text
End Function Call MyFunction("Hello World")
19
Call Statement
SYNTAX for Call Statement : [Call] name [argumentlist] Arguments Call - Optional keyword. If specified, you must enclose argumentlist in parentheses. For example: Call MyProc(0) name - Required. Name of the procedure to call. argumentlist
20
Procedures
Procedure : Procedure is a sub-routine and return no value SYNTAX: [Public [Default] | Private] Sub name [(arglist)] [statements]
[Exit Sub]
[statements] End Sub
21
Procedure Example
Eg: Sub CalcAndShowSalary(Hours, Salary) Dim dblResult dblResult = Hours * Salary txtResult = dblResult
End Sub
Call CalcAndShowSalary(dblHours, dblSalary)
22
Procedures Vs Functions
23
SystemUtil Object
SystemUtil object used to control applications and processes during a run session
SystemUtil.Run method
You can run any application from a specified location using a SystemUtil.Run statement
Ex: Systemutil.run"E:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","E:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
24
Syntax:
InputBox(prompt[, title][, default][, xpos][, ypos][, helpfile, context]) Example: Dim Input Input = InputBox("Enter your name") MsgBox ("You entered: " & Input)
26
What is library
A collection of subroutines and functions stored in one or more files, usually in compiled form, for linking with other programs.
Libraries are linked with the user's program to form a complete executable program.
27
28
29