Documente Academic
Documente Profesional
Documente Cultură
2
August 2007
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Use of this material to deliver training without prior written permission from HP is prohibited.
© Copyright 2007 by Hewlett-Packard Development Company, L.P.
The information contained herein is subject to change without notice. The only warranties for HP products
and services are set forth in the express warranty statements accompanying such products and services.
Nothing herein should be construed as constituting an additional warranty. HP shall not be liable for
technical or editorial errors or omissions contained herein.
This is an HP copyrighted work that may not be reproduced without the written permission of HP. You may
not use these materilas to deliver training to any person outside of your organization without the written
permission of HP.
n
io
Printed in the USA
at
Advanced QuickTest Professional 9.2
lic
QTP92Adv-Instruct-01B
up
Instructor Guide
rD
August 2007 Fo
ot
-N
n
io
at
If you have any comments or suggestions regarding this document, please send them via
uc
http://www.merc-training.com/feedback
Ed
e
ar
ftw
So
P
H
Introduction..............................................................................................................................1
Course Objectives ................................................................................................................2
Course Outline .....................................................................................................................3
Instructional Methods ..........................................................................................................5
Class Introductions ..............................................................................................................6
Sample Test Applications ....................................................................................................8
n
io
An Overview of Object Oriented Programming..................................................................6
at
Objects in QuickTest ...........................................................................................................7
lic
Classes in QuickTest ...........................................................................................................8
up
Common Windows and Web Objects..................................................................................9
rD
Common Methods in QuickTest........................................................................................10
Fo
Elements of a QuickTest Script .........................................................................................11
ot
Summary............................................................................................................................16
Ed
n
io
Viewing the Run-Time Value of a Variable ......................................................................10
at
Adding the Reporter Utility Object ...................................................................................11
lic
Using the Reporter Utility Object ......................................................................................12
up
Filtering Events..................................................................................................................13
rD
Discussion: Output in Results............................................................................................14
Fo
Summary............................................................................................................................15
ot
n
io
The If ... Then Conditional Statement ...............................................................................16
at
Using the If ... Then Statement for Custom Checkpoints ..................................................17
lic
Using the Select Case Statement .......................................................................................18
up
Discussion: Output in Results............................................................................................19
rD
Commonly Used VBScript Functions ...............................................................................20
Fo
Manipulating Strings with Functions.................................................................................21
ot
Summary............................................................................................................................26
Ed
n
io
Connecting to a Database ....................................................................................................8
at
Executing a SQL Query .......................................................................................................9
lic
Examining the Query Results ............................................................................................10
up
Closing the Database Session ............................................................................................11
rD
Working with Text Files ....................................................................................................12
Fo
Reading from a File ...........................................................................................................13
ot
Summary............................................................................................................................15
n
n
io
at
Handling QuickTest Exceptions .............................................................................................1
lic
Overview of Exceptions.......................................................................................................2
up
Handling Positive and Negative Test Data ..........................................................................3
rD
Benefits of Exception Handling...........................................................................................4
Fo
An Overview of the Recovery Scenario Wizard..................................................................5
ot
Summary............................................................................................................................15
P
Introduction
1
n
Purpose
io
at
lic
This course covers the EXPERT VIEW inQuickTest Professional 9.2. This course explains
up
how to create steps that work with dynamic objects and data, use VBScript conditional
rD
and looping statements to control the flow of tests and components, and use DATA
Fo
TABLE methods and database Connection objects to retrieve external data.
ot
-N
This manual includes hands-on exercises are included that are based on real-life
examples. These materials and labs provide learners with the knowledge necessary to
n
io
1-1
Introduction
Course Objectives
After completing this course, you will be able to:
n
io
•
at
Use constants and variables in tests.
lic
up
• Identify when programmatic descriptions are useful.
rD
• Fo
Create tests that include VBScript operators, functions, and statements.
ot
•
uc
Use the DATA TABLE object to store run-time data and drive actions.
Ed
•
ftw
Course Outline
Instructor Notes
This course includes ten lessons. The lessons include discussion slides that require the students to discuss and
report their findings. The answers for these discussion slides are mentioned as instructor notes on the same slide.
The lessons also include lab exercises that provide hands-on experience for students to test their understanding.
• Lesson 1: Introduction
This lesson introduces the structure of the course and sample test applications present in Mercury QuickTest
Professional.
n
This lesson introduces scripting in EXPERT VIEW. In this lesson, you work with VBScript and QuickTest
io
at
objects and methods.
lic
•
up
Lesson 3: Using Expert View
rD
This lesson describes how to work in EXPERT VIEW. The lesson provides an exercise that enables
students to enter, run, and debug a script using EXPERT VIEW.
Fo
•
ot
This lesson covers the skills and knowledge needed to retrieve object properties and use that information in
scripts.
n
io
•
at
This lesson explains how to use programmatic descriptions for dynamic objects in QuickTest scripts.
Ed
This lesson explains how to use VBScript operators, statements, and functions. It covers the functionality of
ftw
H
This lesson explains how to retrieve data from application objects and work with the retrieved data. The lesson
discusses the VBScript looping statements. The lesson also explains how DATA TABLES are used to iterate
actions.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Instructional Methods
• Slides and lecture: Slides will be used to explain course concepts.
• Classroom exercises: At regular intervals you will apply what you learn to hands-on
classroom exercises.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Class Introductions
• Your name
• Your company
• Your job
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Instructor Notes
Slides
Some of the slides in this course include animation. The presence of the Mercury logo at the bottom-left of a slide indicates that
the next mouse-click will advance to a new slide.
Technical setup
The following are general requirements for all exercises in this course:
-- QuickTest Professional 9.2 is installed on student machine.
-- Mercury Tours web application is installed on student machine.
-- Flight Reservation application is installed on student machine.
-- The user name/password of training/mercury works on both applications.
-- The following is true for all Mercury Tours tests:
. . . . Each test requires the application server to be started.
. . . . Each test will launch the MercTours application at the beginning of a run session and close the application at the end of the
run.
. . . . Each test uses an OBJECT REPOSITORY named MercTours.tsr located in C:\Training\QTP92Advanced\objects.
n
-- The following is true for all Flight Reservation tests:
io
. . . . Each test will launch the Flight application at the beginning of a run session and close the application at the end of the run.
at
. . . . Each test uses an OBJECT REPOSITORY named FlightReservation.tsr located in C:\Training\QTP92Advanced\objects.
lic
up
-- Shortcuts on the desktop are provided for the following:
. . . . QuickTest Professional application
rD
. . . . Mercury Tours application
. . . . Flight Reservation application Fo
. . . . Apache start server
ot
. . . . Apache stop server
-N
See merc-training for detailed setup instructions, Flight Reservation installation files, and test files.
Classroom delivery
n
io
Each exercise includes an analysis section followed by a class discussion. Instructors may choose to conduct the analyses in any
at
-- Have participants perform the analysis independently, have faster participants wait for the slower participants, reconvene the
class for discussion when all/most are done with the analysis.
Ed
-- Pair or group participants for the analysis, reconvene the class for discussion when the groups are done.
-- Have participants perform the analysis independently, allow the 1-2 exceptional participants to move independently (either
e
ar
slower or faster), reconvene the class for discussion when most are done.
ftw
-- Have participants perform the entire exercise independently including skipping the analysis questions if they choose.
-- Conduct the analysis questions altogether as a class.
So
In other words, use your judgment of the needs of the participants as your guide.
P
Sample solutions are provided for each exercise. At the end of each exercise, you may choose a successful participant to present
H
their solution to the class or you may use the sample solution.
Additional challenge steps are provided at the end of some exercises. These are displayed in instructor notes only and are up to
your discretion when to use them.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
QuickTest Professional has been set up on your workstation with two sample test
ftw
applications that can be accessed from the desktop: the Mercury Tours web application
So
You may use TRAINING as the user name and MERCURY as the password to login to both
applications.
n
io
at
lic
Purpose
up
This lesson introduces you to scripting in EXPERT VIEW. In this lesson, you work with VBScript and QuickTest
rD
objects and methods.
Fo
ot
Objectives
-N
n
•
uc
•
ftw
Explain how VBScript and Object Oriented Programming are relevant to QuickTest
So
Professional.
P
2-1
Introduction to Expert View
n
io
at
lic
up
rD
Fo
ot
-N
n
io
In QuickTest Professional, tests and components are coded in VBScript. EXPERT VIEW
Ed
displays the VBScript code that corresponds to the steps that you create for your test or
e
component.
ar
You have already worked with KEYWORD VIEW in the basic course. This course covers the EXPERT
ftw
VIEW.
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Figure 2-2 Keyword View and Expert View
Fo
ot
KEYWORD VIEW and EXPERT VIEW represent a step in a test script differently.
-N
In KEYWORD VIEW:
n
io
at
• The hierarchy from parent objects to child objects is shown in sequential rows.
e
ar
In EXPERT VIEW:
ftw
So
Figure 2-2 shows KEYWORD VIEW and EXPERT VIEW for a step in a test. In this step,
you type MERCURY into the USERNAME edit field on the home page of sample Flight
application. The hierarchy of the step displays:
• The class and logical name of the object on the page: WEBEDIT(“USERNAME”).
An Overview of VBScript
VBScript is a programming language developed by Microsoft. It is a lightweight version
of the Visual Basic programming language.
• It is a scripting language.
n
• It defines tests and components in QuickTest Professional.
io
at
lic
• It helps automate tasks in Windows environments.
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The data within an object is referred to as the properties of the object. The functions
within an object are referred to as the methods of the object. Consider a bicycle as an
example of an object. The data for the bicycle includes the color, number of gears,
current gear, and current speed. The functions of the bicycle include changing gears and
n
io
applying brakes.
at
lic
The types of objects are defined by classes. For example, the bicycle object is an
up
instance of the class of bicycles. In this case, all bicycle objects share the same
rD
properties and methods. However, at any moment, the values of properties of all bicycle
Fo
objects and the method that is executed could be different for each bicycle.
ot
-N
Objects in QuickTest
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
The OBJECT REPOSITORY displays all the objects in the application under test (AUT)
ftw
that are used in the test while recording or added to the OBJECT REPOSITORY directly.
So
Figure 2-3 shows the logical name, class, and properties of the object password.
Classes in QuickTest
n
io
at
lic
up
rD
Fo
ot
-N
The types of objects that QuickTest can recognize and work on are set by the following
at
• STANDARD WINDOWS
e
ar
• ACTIVE X
ftw
So
• VISUAL BASIC
P
H
• WEB
• UTILITY OBJECTS
Your company may also have purchased add-ins that provide additional classes for the
Java, SAP, Siebel, PeopleSoft, Oracle applications, Stringray, TE, VisualAge
SmallTalk, Web Services, and the .NET framework. You can view a description of each
class and its properties and methods in the Object Model Reference section of help. To
access help, press F1 or from the QuickTest Professional menu bar, select HELP →
QUICK TEST PROFESSIONAL HELP.
QuickTest Professional help is organized into the following five sections: WHAT’S NEW IN QUICKTEST
PROFESSIONAL?, QUICKTEST USER’S GUIDE, QUICKTEST FOR BUSINESS PROCESS
TESTING USER’S GUIDE, OBJECT MODEL REFERENCE, and VBSCRIPT REFERENCE.
IMAGE
n
Common Interactive WINBUTTON LINK
io
at
Objects
lic
WINCHECKBOX WEBCHECKBOX
up
rD
WINCOMBOBOX WEBEDIT
Fo
WINEDIT WEBLIST
ot
-N
WINLIST WEBRADIOGROUP
n
io
at
WINRADIOBUTTON
uc
Ed
n
io
at
lic
up
rD
Fo
ot
-N
Several interactive objects in Windows and Web applications share the following
at
common methods:
uc
Ed
• CHECK and OUTPUT: Run when checkpoints or output values are inserted into a test
or component. The CHECK and OUTPUT methods check or return the values of the
properties defined in the checkpoint object that is passed into the method as input.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
To view the elements of a QuickTest script, open a test or component in EXPERT VIEW.
ftw
objects. Figure 2-6 shows calls to test objects and to the Reporter utility object.
Example
n
io
Example
at
lic
up
• Use a dot to access methods for an object.
rD
Fo
ot
Example
-N
n
•
io
Use either upper or lower casing because VBScript does not differentiate between
at
Example
ftw
So
P
H
• Where no result value is used, do not use parentheses for method calls.
No parentheses around "31" and CheckPoint("My Property").
Example
• When the result value is needed, use parentheses for method calls.
Need parentheses around CheckPoint("My Property").
n
io
at
lic
Example
up
rD
• Use an underscore to continue a statement on the next line.
This statement on two lines is equivalent to the above statement on one line.
Fo
ot
-N
n
Example
io
at
uc
Example
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
Match the steps from KEYWORD VIEW with their corresponding representation in
ftw
EXPERT VIEW.
So
Instructor Notes
P
Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer-teaching. Each
H
Students may wish to refer to Common Windows and Web Objects on page 2-9 to review the object class name that corresponds
to each icon.
1 matches B
2 matches C
3 matches A
Note that each step in EXPERT VIEW must repeat the entire object hierarchy.
The next lesson discusses the With statement that enables grouping of statements around the same object hierarchy.
n
Figure 2-8 Steps in Keyword View
io
at
lic
Given the code snippet from KEYWORD VIEW, as shown in Figure 2-8, write the
up
equivalent VBScript code for EXPERT VIEW.
rD
The equivalent VBScript code for EXPERT VIEW is: Fo
ot
Dialog("Login").WinEdit("Password:"). _
at
uc
SetSecure "4291f98e3c01c6a5b1d224577e28909ee31c41cd"______________
Ed
Dialog("Login").WinButton("OK").Click_____________________________
e
ar
ftw
Instructor Notes
Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer-teaching.
Students may wish to refer to Common Windows and Web Objects on page 2-9 to review the object class name that corresponds
to each icon.
Summary
In this lesson, you learned how to:
• Explain how VBScript and Object Oriented Programming are relevant to QuickTest
Professional.
• List some common test objects and methods used in QuickTest Professional.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
2-16 Summary
Introduction to Expert View
Review Questions
Now answer these review questions.
You use EXPERT VIEW to build tests and components that retrieve run-time
properties from objects, perform comparisons and computations on objects, execute
steps depending on dynamic information, and retrieve data from external sources.
_______________________________________________________________
_______________________________________________________________
n
2. What is the difference between the KEYWORD VIEW and the EXPERT VIEW?
io
at
In KEYWORD VIEW, an icon-based table displays the information about each step or
lic
component. In EXPERT VIEW, each step is a single line of VBScript code._____
up
rD
_______________________________________________________________
Fo
ot
3. How does QuickTest Professional relate to OOP?
-N
defines the properties and methods available to its objects. Therefore, QuickTest
uc
_______________________________________________________________
e
ar
ftw
_______________________________________________________________
So
_______________________________________________________________
P
H
4. When should you use parentheses for method calls in a script in QuickTest?
Use parentheses for method calls when you need the result value. ___________
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
Purpose
up
This lesson describes how to work in EXPERT VIEW. The lesson provides an exercise that enables students to
rD
type, run, and debug a script using EXPERT VIEW.
Fo
ot
Objectives
-N
n
•
uc
•
ftw
3-1
Using Expert View
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
The QuickTest Professional STEP GENERATOR feature enables you to add steps in a test.
ar
To access STEP GENERATOR, from the QuickTest Professional menu bar, select INSERT
ftw
→ STEP GENERATOR.
So
P
• TEST OBJECTS: Use this category to access properties or methods for objects in the
AUT. The common Windows and Web objects discussed in the previous lesson,
WINEDIT, WINLIST, BROWSER, and WEBLIST, are all examples of test objects.
• UTILITY OBJECTS: Use this category to access the built-in QuickTest objects
provided for general testing and reporting purposes. This course discusses various
utility objects, including REPORTER, DATATABLE, and DATASHEET.
Defining a Step
n
io
at
lic
up
rD
Fo
ot
• OBJECT or LIBRARY: Select the desired test object or utility object. If the step
e
•
P
ARGUMENTS: After the object method or function is selected, the argument table is
H
populated with the input arguments. Supply the desired input in the VALUE column.
• RETURN VALUE: After you select an operation that is expected to return a value, the
RETURN VALUE field gets enabled. Select the RETURN VALUE check box to capture
the value that an operation returns. If required, you can change the value.
Use the following features in EXPERT VIEW are available to assist you:
• Statement completion
The statement completion feature presents options for finishing the current VBScript line.
• Auto-expand VBScript syntax
The auto-expand VBScript syntax feature returns VBScript statements that match characters you typed.
• Context-sensitive help
The QuickTest Professional help is context-sensitive, which means that the help page differs depending on the
n
cursor position.
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Context Example
n
io
class.
at
lic
up
When you type an
rD
object followed by a Fo
dot, QuickTest uses an
ot
object.
at
uc
Ed
e
By default, the STATEMENT COMPLETION option is turned on. To turn this option off, from the QuickTest
Professional menu bar, select TOOLS → VIEW OPTIONS → EDITOR OPTIONS → GENERAL tab.
QuickTest leverages Microsoft’s Intellisense for statement completion. Intellisense involves a program, such as
QuickTest Professional, predicting a word or phrase that the user wants to type without the user actually typing it
completely. This approach can be used in cases where it is easy to predict the new words being entered based on those
already keyed in.
Press ESC to close the auto complete list.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
The auto-expand VBScript syntax feature returns VBScript statements that match the
Ed
characters you type. To trigger the auto-expand VBScript syntax feature, type a few
e
initial characters in EXPERT VIEW and then press the spacebar. The following options are
ar
possible:
ftw
So
• If only one statement fits the criteria, QuickTest enters that statement automatically.
P
H
• If multiple options exist, QuickTest provides a dialog box that enables you to select
the VBScript statement that is the closest match.
• If the VBScript statement has both a closing keyword and an opening keyword,
such as FOR...NEXT, QuickTest enters the closing keyword automatically into the
script.
Figure 3-3 shows VBScript keywords, Set and Select, which begin with the letters
“se”. By default, the auto-expand option is turned on. To turn this option off, from the
QuickTest Professional menu bar, select TOOLS → VIEW OPTIONS → EDITOR
OPTIONS → GENERAL tab.
VBScript statements are covered in lesson 6 "Using VBScript Operators, Statements, and Functions." This lesson
discusses only one VBScript statement, which is the With statement.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
The QuickTest Professional help system is context-sensitive. This means that the help
page displayed differs depending on where the cursor is positioned.
You can use context-sensitive help to retrieve the description of any object, method, or
statement in your script. To open context-sensitive help, place the cursor on the item for
which you need help and from the QuickTest Professional menu bar, select HELP →
QUICKTEST PROFESSIONAL HELP or press F1. The QUICKTEST PROFESSIONAL HELP
window opens a page describing the item you selected.
Figure 3-4 shows the context-sensitive help displayed when the cursor is on the WebList
object.
n
io
at
Figure 3-5 VBScript Code using With Statement
lic
up
The VBScript With statement enables you to perform a series of operations on an object.
rD
Fo
You use the With statement to group related steps together and make a script easier to
ot
read. For example, using With grouping enables you to quickly see all the activities
-N
Figure 3-5 shows two code snippets that perform the same operations. The second code
at
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
To convert a script so that sequential steps related to the same object are grouped
e
together by using a With statement, from QuickTest Professional menu bar, select EDIT
ar
To return the script to the previous format, from the QuickTest Professional menu bar,
select EDIT → ADVANCED → REMOVE “WITH” STATEMENTS.
P
H
You can choose to use With statements automatically when you record new steps for a script by selecting
TOOLS → OPTIONS from the QuickTest Professional menu bar and checking the AUTOMATICALLY
GENERATE “WITH” STATEMENTS AFTER RECORDING check box.
• Locate syntax errors: Enables you to verify that the script adheres to VBScript
rules.
n
io
at
• Execute single steps: Enables you to pinpoint the exact step where an error might
lic
occur.
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Figure 3-7 Syntax Errors
Fo
ot
-N
Whenever you switch from EXPERT VIEW to KEYWORD VIEW, QuickTest checks your
script for syntax errors. You may also perform a syntax check from the TOOLS SYNTAX
n
io
CHECK menu.For each error found in your script, the INFORMATION pane displays the
at
following information:
uc
If the INFORMATION pane is not visible, from the QuickTest Professional menu bar, select VIEW →
Ed
INFORMATION.
e
ar
• DETAILS: Provides the description of the error. For example, if you open a
ftw
conditional block with an IF statement but do not close it with an END IF statement,
So
• ITEM: Provides the name of the test or function library that contains with the syntax
error.
• ACTION: Provides the name of the action that contains the syntax error.
• LINE: Provides the line number that contains the syntax error. To display all the line
numbers in a script, from the QuickTest Professional menu bar, select TOOLS →
VIEW OPTIONS → EDITOR OPTIONS, and check the SHOW LINE NUMBERS check
box in EDITOR OPTIONS dialog box.
• To navigate directly to an error in your script, select the error and click the CHECK
SYNTAX button.
If you run a script containing syntax errors, the run will stop when it passes the first line with a fault.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
The RUN FROM STEP option enables you to execute a QuickTest script starting from any
e
To use this option, place the cursor at the desired starting step and from the Quick Test
So
Note: You may need to manually navigate the AUT to the state expected by the step in
your script.
Adding Breakpoints
n
io
at
lic
up
rD
Fo
ot
-N
Breakpoints enable you to suspend a run session at a predetermined point in the script so
at
that you can inspect the run-time state of your application. To set a breakpoint:
uc
Ed
1. Place the cursor on the step where you want to add the breakpoint.
e
ar
BREAKPOINT. The breakpoint symbol appears on the left margin of the script.
So
P
3. QuickTest pauses the run session when it reaches the breakpoint before executing
H
the step.
You use single step commands to debug a test when it is paused. Single step commands are discussed later
in this lesson.
4. To remove a breakpoint, place the cursor on the step and from the QuickTest
Professional menu bar, select DEBUG → INSERT/REMOVE BREAKPOINT again.
5. When you complete debugging, you can clear all the breakpoints from a script. To
remove all the breakpoints, from the QuickTest Professional menu bar, select
DEBUG → CLEAR ALL BREAKPOINTS.
Breakpoints are ignored when TestDirector or Quality Center runs a QuickTest script.
Note: You can also insert a breakpoint by clicking next to the line number of the step
where you want breakpoint.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
The QuickTest Professional DEBUG menu provides step commands that enable you to
Ed
execute a single step of a script. These commands are available when a run session is
e
paused.
ar
A run session may be paused because of a breakpoint, a run error, or because it was paused manually.
ftw
So
• STEP INTO: Runs only the current line of the active test or component. If the current
line calls another action, the called action is displayed in the QuickTest Professional
window, and the test or component pauses at the first line of the called action.
• STEP OVER: Runs only the current step in the active test or component. The entire
called action executes, and the test pauses at the next step in the test.
• STEP OUT: Applies when the STEP INTO command is used to enter a called action.
The STEP OUT command runs to the end of the called action, then returns to the
calling action, and pauses the run session.
Summary
In this lesson, you learned how to:
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
3-16 Summary
Using Expert View
Review Questions
Now answer these review questions.
The three categories of step in STEP GENERATOR are: TEST OBJECTS, UTILITY
OBJECTS, and FUNCTIONS. __________________________________________
_______________________________________________________________
n
statements that match the characters you type. __________________________
io
at
_______________________________________________________________
lic
up
3. What does the VBScript With statement do?
rD
Fo
The VBScript With statement enables you to perform a series of operations on an
ot
object. __________________________________________________________
-N
_______________________________________________________________
n
io
at
4. What is a breakpoint?
uc
Ed
_______________________________________________________________
So
P
H
Exercise introduction
Students modify the LoginLogout test by inserting steps for a new action that purchases a flight ticket.
Specific objectives
At the end of this exercise, students should be able to:
-Type new steps for a test using EXPERT VIEW.
- Use the EXPERT VIEW Intellisense features.
- Debug a script as needed.
Technical setup
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
student computer:
-Students are provided with a base test, LoginLogout with which to begin the exercise.
-The test UsingExpertView provides a sample solution.
n
io
at
In this exercise you learn how to add new steps in EXPERT VIEW for the Mercury Tours
lic
application. The activities here are divided into the following sections:
up
rD
• Part 1: Translate the given KEYWORD VIEW steps into EXPERT VIEW code.
Fo
• Part 2: Open and run an existing script.
ot
-N
n
io
at
lic
up
Figure 3-11 SearchFlights Action
rD
Figure 3-11 displays the steps of an action in KEYWORD VIEW. Type the VBScript code
Fo
that corresponds to the steps shown in Figure 3-11.
ot
-N
_______________________________________________________________
uc
Ed
_______________________________________________________________
So
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
2. In the QUICKTEST PROFESSIONAL - ADD-IN MANAGER dialog box, check the WEB
check box and click OK.
The test runs on the Mercury Tours application and contains the LOGIN and
LOGOUT actions.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
4.
Apache Web server.
So
P
5. Verify that the START SERVER window displays the following line: Apache/1.3.17
H
7. On the QuickTest Professional toolbar, click RUN to run the test. The RUN dialog
box appears.
8. Click OK.
This test is set up to launch the AUT when a run session starts and to exit the
application when the session ends. When the run completes, a TEST RESULTS
window opens.
9. In the TEST RESULTS window, click VIEW → EXPAND ALL. Confirm that the script
runs completely and successfully.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
d) Click OK.
3. Drag and drop the SEARCHFLIGHTS action so that it is the second action in the test
flow.
n
io
at
lic
up
rD
Fo
ot
-N
n
5. In EXPERT VIEW, type the VBScript code that you wrote in Part1.
Ed
because it is the only browser item set up for this test. ____________________
P
_______________________________________________________________
H
6. After typing the step, save the updated script in your tests folder as
USINGEXPERTVIEW.
Note: Keep the command window with the Mercury Tours application server open.
2. Run the updated test. After it completes execution, the test opens a TEST RESULTS
window.
If your test did not complete successfully, use the QuickTest Professional debug
features to identify the problems in the script.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Purpose Fo
This lesson covers the skills and knowledge needed to retrieve object properties and use that information in scripts.
ot
-N
Objectives
n
io
at
uc
• Use the reporter utility object to report events to the test results.
P
H
4-1
Working with Object Properties
• Test result reporting: You include the value of a property in the output results of the
test for reporting purposes. Reporting test results enables the recording of both the
results and conditions of the test.
• Using a custom checkpoint: You create a checkpoint in EXPERT VIEW rather than in
KEYWORD VIEW to perform any computations validating the value of a property.
n
io
For example, the return date of a flight must be later than the departure date.
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
QuickTest stores the objects of your application as test objects in the OBJECT
So
REPOSITORY. The object repository stores the property values for each object at the time
P
the object was added. During a run session, QuickTest uses these property values to
H
When retrieving property values for an object, you can retrieve either the values of the
run-time object in your application or the static values stored in OBJECT REPOSITORY.
Figure 4-1 shows how the OBJECT REPOSITORY stores the properties of the run-time
FROMPORT object.
Note: Run-time object properties are the properties of the object displayed in the
application, which is the set of all available properties. Test object properties are a
subset of properties of the objects stored in the OBJECT REPOSITORY and are used to
identify the objects.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Identifying a Property
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
You can review the properties associated with any object in a test by reviewing the test
e
ar
object in the OBJECT REPOSITORY. You can also review the properties by using the
ftw
If you are unsure which property to use, access HELP for the object and navigate to the
P
H
identification properties page for that object. This page provides a brief description of
each property.
Figure 4-2 shows the properties of the run-time FROMPORT object in OBJECT SPY. The
figure also shows the WEBLIST IDENTIFICATION PROPERTIES page, which briefly
describes each property of the run-time FROMPORT object.
n
io
at
Example
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The SetTOProperty method changes the property values used to identify an object
during the test run. This method has no effect on the ACTIVE SCREEN of QuickTest
Professional or the values saved in the OBJECT REPOSITORY for the object.
n
<object>.SetTOProperty(<property>)(<value>)
io
at
lic
The following example shows how to use the SetTOProperty method:
up
rD
Example
Fo
ot
-N
Note: You can set values only for properties that are included in the test object
n
• Variables: Store numeric, string, and object values that are dynamic
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Example
The above example shows how values are declared during a test. After you set a constant, you can use it
throughout the remainder of the action or component. Using a constant enables you to set and reset the value in
just one place.
You declare a variable by using a Dim statement. After declaring a variable, assign a
n
io
value, which can be reassigned at any time.
at
lic
The following example shows how to use the Dim statement:
up
rD
Fo
Example
ot
-N
n
The above example sets two variables to values retrieved from the run-time application. Variable declaration is
io
optional in VBScript. If you do not declare a variable, you can create the variable when you assign a value to it.
at
Declaring a variable explicitly enhances code readability and maintenance. Dim statements are often grouped at
uc
the beginning of a script. The CInt function and other conversion functions are covered in lesson 6, “Using
Ed
By common convention, constants and variables are named for easy differentiation. A
ar
ftw
common practice is to prefix constant names with con, or other prefixes such as vb or
mic, which indicate the context of the constant. A common practice for variable names
So
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
When you pause a run session by using breakpoints for a script, the values of the
So
variables of a script are displayed in the VARIABLES tab of the DEBUG VIEWER.
If DEBUG VIEWER is not displayed, from the QuickTest Professional menu bar, select VIEW → DEBUG
P
When you step through the script, the values of the variables change. The VARIABLES
tab updates itself to correspond with the change in the values of the variables.
The variable values are not displayed after the run completes. You can also use the WATCH tab to display the
values or properties of any object, even if they were not assigned to a variable. Use the COMMAND tab if you want to
change the value of a variable during a debug session. This change does not occur for the next run, unless you update
the test itself.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
You use the reporter utility object to report an event to the test results.
P
H
– EventStatus is the status of the report step. The valid values for EventStatus are
the following constants: micPass, micFail, micDone, and micWarning.
n
io
at
Example
lic
In the above example the EventStatus is micDone. The ReportStepName is OrderNumber. Details
up
rD
indicates the value of the string.
Fo
Note: Use the & operator to concatenate strings.
This course discusses the & operator, with string manipulation functions, in lesson 6, “Using VBScript Operators,
ot
-N
Filtering Events
The reporter object provides a Filter property that sets the ReportEvent calls that are
executed based on their EventStatus. Use the Filter property to set the amount of debug
information in the results for your script.
n
io
at
• rfDisableAll: Displays nothing in the test results.
lic
up
Setting the Reporter.Filter property to rftEnableAll or rftDisableAll turns
rD
checkpoint reporting on and off. Checkpoint results are reported as passes or fails, which
Fo
means there are no done or warning results from checkpoints.
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
For each block of code in Figure 4-5, enter the output that would appear in test results.
P
H
Instructor Notes
Summary
In this lesson, you learned how to:
• Use the reporter utility object to report events to the test results.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Summary 4-15
Working with Object Properties
Review Questions
Now answer these review questions.
Retrieving the values of the properties of an object helps in debugging, test result
reporting, and using custom checkpoint. _______________________________
_______________________________________________________________
Constants store number and string values that do not change. Variables store
n
numeric, string, and object values that are dynamic. ______________________
io
at
_______________________________________________________________
lic
up
3. Which method will you use in QuickTest Professional to retrieve the value of the
rD
enabled property of a button in an application?
Fo
ot
You use the GetROProperty command in QuickTest Professional to retrieve the
-N
_______________________________________________________________
at
uc
Ed
e
ar
ftw
So
P
H
Exercise introduction
Students modify the ObjectProperties test to insert new steps that retrieve and output run-time object properties.
Specific objectives
At the end of this exercise, students should be able to:
- Identify where GetROProperty and GetTOProperty are used.
- Use GetROProperty to retrieve run-time properties.
- Declare and use constants and variables.
- Use Reporter.ReportEvent to report an event to the test results.
Technical setup
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
student computer:
-- Students are provided with a base test, ObjectProperties , with which to begin the exercise.
n
-- The ObjectPropertiesSolution test provides a sample solution.
io
at
lic
In this exercise, you enhance an existing script for the Flight Reservation application to
up
retrieve run-time object properties.
rD
The exercise consists of the following parts: Fo
ot
•
n
•
uc
The test runs on the Flight Reservation application and contains the LOGIN,
FLIGHTORDER, and EXIT actions. The FLIGHTORDER action is driven by its local
data table.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
3. On the QuickTest Professional toolbar, click RUN to run the test. RUN dialog box
e
appears.
ar
ftw
4. Click OK.
So
Note: This test is set up to launch the AUT when a run session is started and to exit the
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
The LOGIN and EXIT actions ran once each. The FLIGHTORDER action ran nine
ar
times. __________________________________________________________
ftw
So
_______________________________________________________________
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
Answer the following questions to determine the steps that need to be added to the
Ed
script.
e
ar
1. What is the logical name of the object in the Flight Reservation application that
ftw
contains the total price information? What is the logical name of the object that
So
contains the order number information? What are the class names for these objects?
P
The logical names are “TOTAL:” and “ORDER NO:”, respectively. The class name
for the both objects is WINEDIT. To find the answer, explore OBJECT REPOSITORY
or start the application and use OBJECT SPY. ____________________________
_______________________________________________________________
_______________________________________________________________
Write the VBScript expressions that would identify the total price object and the
order number object. Remember to include the object hierarchy.
_______________________________________________________________
_______________________________________________________________
Write the VBScript statements that retrieve the desired property from the two
n
objects.
io
at
lic
Window(“Flight Reservation”).WinEdit(“Total:”).GetROProperty “text”
up
rD
Window(“Flight Reservation”).WinEdit(“Order No:”).GetROProperty
“text” _________________________________________________________
Fo
ot
3. Do you use a constant or a variable to store the information you retrieved? Explain
-N
your answer.
n
io
Use a variable because the value is determined at run-time and changes with each
at
iteration. ________________________________________________________
uc
Ed
_______________________________________________________________
e
ar
Write the VBScript statements for declaring and setting the values of your constants
ftw
or variables.
So
vTotalPrice = Window(“Flight
Reservation”).WinEdit(“Total:”).GetROProperty “text” ___________
vOrderNumber = Window(“Flight
Reservation”).WinEdit(“OrderNo:”).GetROProperty “text” _________
4. Which object and method is used to report the information to the results?
Write the VBScript statements that report the values of the information you
retrieved.
5. Review the actions in the OBJECTPROPERTIES test. In which action do you add the
new steps?
In the FLIGHTORDER action, after you insert an order, you add the new steps. Each
time an order is inserted, the new steps run with each iteration of the test. ____
_______________________________________________________________
Instructor Notes
Here is sample code to retrieve the total price and order number:
n
io
Dim vTotalPrice, vOrderNumber
at
vTotalPrice = Window("Flight
lic
Reservation").WinEdit("Total:").GetROProperty("text")
up
vOrderNumber = Window("Flight Reservation").WinEdit("Order
rD
No:").GetROProperty("text")
Fo
‘Output the information in the test results.
ot
From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
e
1.
ar
2. From EXPERT VIEW, use the action list to select the FLIGHTORDER action for
editing.
P
H
n
io
at
lic
up
rD
Fo
ot
3. Append the code to the existing script that you wrote in Part 2.
n
io
at
2. Run the updated test. Viewr the TEST RESULTS at the completion of the test.
P
H
If the test did not complete successfully, use the QuickTest Professional debug
features to identify the problems in the script.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
Purpose
up
This lesson explains how to use programmatic descriptions for dynamic objects in QuickTest scripts.
rD
Fo
Note: The technique of “programmatic descriptions” is also called “descriptive
ot
programming.”
-N
n
io
at
Objectives
uc
Ed
5-1
Working with Dynamic Objects
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
Most applications consist of dynamic and static objects. Dynamic objects do not always
e
exist in the same state in the application because they are created during run-time. Static
ar
Figure 5-1 shows navigation links in the left pane of a Web page. These links are static
P
objects and remain unchanged every time the Web page loads. However, the objects in
H
the center of the Web page, displaying itinerary information, are dynamic. These
dynamic objects vary depending on what date the user is traveling on and between
which cities. Therefore, the properties of these objects use dynamic values, which are
assigned at run-time.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
QuickTest Professional identifies the objects in your application and stores them in the
P
OBJECT REPOSITORY.
H
The objects in the OBJECT REPOSITORY can be referenced by the steps of tests and
components.
• Set the values for properties of dynamic objects in the OBJECT REPOSITORY. Use
this method for the objects that exist in the OBJECT REPOSITORY.
• Use programmatic descriptions for dynamic objects that do not exist in the OBJECT
REPOSITORY, but have a dynamic property value that you need to validate.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
If an object is defined in the OBJECT REPOSITORY and has dynamic property values, you
Ed
•
ftw
Using regular expressions to match the dynamic property values that vary at run-
time.
So
P
In a QuickTest script, you refer to a dynamic object by its logical name, just as you refer
to any other object in the OBJECT REPOSITORY.
Basic regular expressions are discussed in the “Using QuickTest Professional” course.
n
io
at
lic
up
rD
Fo
ot
-N
You can instruct QuickTest to perform actions on an object without referring to the
uc
OBJECT REPOSITORY or to the name of the object. To do this, you provide QuickTest
Ed
with a list of properties and values for identifying the objects on which you want to
e
perform an action. This approach of providing QuickTest with a list of properties and
ar
• Validate specific dynamic property values of a dynamic object: Figure 5-4 shows
the programmatic description of a checkbox for flight_92.
Note: You can use programmatic descriptions consistently in QuickTest without using
the OBJECT REPOSITORY.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
To use programmatic descriptions for an object, you identify the class of the object by
P
locating a similar dynamic object in the OBJECT REPOSITORY or by running the AUT
H
Figure 5-5 shows the OBJECT SPY and the application, which has a dynamic object
called BLUE SKIES AIRLINES 361. The OBJECT SPY reveals the class of the object as
WEBRADIOGROUP.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
After you identify the object class, select the object properties that will be needed to
P
You can view object properties in the OBJECT SPY, OBJECT REPOSITORY, or in the
OBJECT MODEL REFERENCE in Quick Test Professional HELP.
Figure 5-6 shows the properties and values of a dynamic object in OBJECT SPY.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Note: Do not insert any extra white space between the “<propertyX>:=<valueX>"
strings.
The following example shows how a value is specified for the WEBCHECKBOX name
property:
n
io
at
lic
up
Example
rD
The following example shows how to use a variable and the concatenation (&) operator
Fo
to specify a dynamic description for the WEBCHECKBOX name property:
ot
-N
n
io
Example
at
uc
The following example shows how to use both a variable and a regular expression:
Ed
e
ar
ftw
Example
So
In this case, the name of the WebCheckBox must contain the given itinerary number.
P
H
The following example shows how to use property and value pairs to identify a dynamic
object uniquely:
Example
Within a single statement, you can use programmatic descriptions to identify multiple
objects in the object hierarchy. However, after you use a programmatic description for a
dynamic object in a hierarchy, you must also use programmatic descriptions for the
remaining objects in the hierarchy.
The following example shows how to use programmatic description for dynamic objects
in a hierarchy:
Example
In the above example, Browser is identified using programmatic descriptions, Therefore PAGE and
WEBCHECKBOX must also be identified using programmatic descriptions.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Note: Use the Dim statement to declare a variable. Use the Create method to create a
new and empty Description object. Use the Set statement to set the value of a variable
and then assign the variable to an object.
n
io
at
2. Set property and value pairs in the Description object by using the following syntax:
lic
<description_object>.(<property1>).Value = <value1>
up
...
rD
<description_object>.(<propertyX>).Value = <valueX>
Fo
3. Refer to the dynamic object with the following syntax:
ot
-N
<object_hierarchy>.<object_class>(<description_object>)
n
io
The following example shows how the Description object is used to create a
at
programmatic description:
uc
Ed
e
ar
Example
ftw
So
P
H
Note: In the above example, you can replace the “flight_378” string with a string
variable whose value is set at run-time.
The following example shows how the ChildObjects method is used to return all the
checkboxes within a browser page:
Example
n
After you retrieve the Collection object, use the Count method to retrieve the number of
io
at
child objects. The index can then be used to access individual child objects.
lic
up
The following example shows how to use the Count method to return the total number
rD
of objects in a collection of child objects:
Fo
ot
-N
Example
n
io
Note: The first object in the collection of child objects is always numbered 0.
at
uc
Ed
e
ar
ftw
So
P
H
• Perform the same operation on a list of objects with similar properties: For
example, to select all the checkboxes and enter a certain date in all the Date fields.
This is done using a programmatic description and a loop statement.
• Perform an operation on a static object that you choose based on run-time
information: For example, the HOTELS or CARRENTALS link is selected based on
previous run information.
• Bypass the OBJECT REPOSITORY: For example, if you have an object that changes
n
io
often based on run-time information, you may want to avoid adding this object to
at
the repository. In this case, you identify the object by constructing its programmatic
lic
description and bypass the OBJECT REPOSITORY.
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Summary
In this lesson, you learned how to:
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
5-16 Summary
Working with Dynamic Objects
Review Questions
Now answer these review questions.
Dynamic objects are objects that do not always exist in the same state in the
application but are created dynamically at run time depending on the user actions
performed in the AUT. _____________________________________________
_______________________________________________________________
_______________________________________________________________
n
2. What is a Description object?
io
at
The Description object enables you to specify multiple properties to uniquely
lic
identify a dynamic object. __________________________________________
up
rD
_______________________________________________________________
Fo
ot
3. What are the steps involved in building a programmatic description?
-N
The steps involved in building a programmatic description are identifying the object
n
io
_______________________________________________________________
Ed
_______________________________________________________________
e
ar
ftw
The additonal uses of programmatic descriptions are performing the same operation
P
object that you choose based on run-time information, and bypassing OBJECT
REPOSITORY._____________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
Exercise introduction
Students modify the failing FaxOrder test so that it works. Students use programmatic descriptions so that the FaxOrder test can
locate the required dynamic objects.
Specific objectives
At the end of this exercise, students should be able to:
- Find the object class and properties for identifying a dynamic object.
- Use a regular expression for a property value in OBJECT REPOSITORY.
- Create a programmatic description.
Remember that once used, programmatic descriptions must be used for the remaining object hierarchy.
Technical setup
In addition to the general requirements listed in Course Overview, this exercise has the following requirements for each student
computer:
n
-- Each student computer is supplied a base test, FaxOrder, to begin the exercise.
io
-- Each student computer is supplied the DynamicObjectsSolution test, which provides a sample solution.
at
lic
In this exercise, you update an existing script for the Flight Reservation application so
up
that the script works for dynamic objects.
rD
Fo
The exercise consists of the following parts:
ot
-N
Instructor Notes
Ed
The instructor should reconvene the class after this part to discuss the answers.
e
ar
•
So
The test runs on the Flight Reservation application and contains the LOGIN,
ORDER_FAX_FLIGHT, and EXIT actions.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Note: The ORDER_FAX_FLIGHT action is the only action defined in this script. The
LOGIN and EXIT actions are calls to actions that enable you to login and exit the
application respectively.
3. On the QuickTest Professional toolbar, click RUN to run the test. The RUN dialog
box appears.
4. Click OK.
a) On which step does the test script fail? What run error message is displayed?
The test script fails on the first step referencing Dialog("Fax Order No. 63").
n
The run message displayed is: “CANNOT FIND THE “FAX NUMBER” OBJECT’S
io
at
PARENT "FAX ORDER NO. 63”...______________________________________
lic
up
_______________________________________________________________
rD
_______________________________________________________________
Fo
ot
b) QuickTest Professional cannot locate a test object in the AUT. Which object is
-N
QuickTest Professional looking for and why is this object not in the AUT?
n
io
QuickTest Professional is looking for a dialog box with a text property value of
at
"FAX ORDER NO. 63" but the dialog box is named dynamically in the AUT. ___
uc
Ed
_______________________________________________________________
e
ar
ftw
So
P
H
Part 2: Determine the New Steps that You Need to Add to the
Script
You need to correct the script in Part 1. The FAX ORDER dialog box is named
dynamically, based on the order number of the flight.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
Answer the following questions to determine the steps that need to be added to the
script.
1. Review the code for the ORDER_FAX_FLIGHT action. Which steps in the action do
you need to correct?
The two steps referencing DIALOG(“FAX ORDER NO. 63”) are: _____________
_______________________________________________________________
_______________________________________________________________
2. Which approach from “Identifying Dynamic Objects” do you use? What is the
benefit of each approach?
_______________________________________________________________
n
_______________________________________________________________
io
at
lic
_______________________________________________________________
up
rD
3. The title of the FAX ORDER dialog box is set dynamically, based on the order
number of the flight. How do you retrieve the correct order number for the flight?
Fo
ot
Use GetROProperty to retrieve the “text” value of the WINEDIT field named
-N
_______________________________________________________________
at
uc
GetROProperty("text") _______________________________________
e
ar
_______________________________________________________________
ftw
So
4. What is the name of the property that specifies the title of a dialog box object? How
did you find your answer?
P
H
The name is “TEXT”. To find the answer, review the properties of the FAX ORDER
dialog box in the OBJECT REPOSITORY, or review the dialog box properties in
QuickTest Professional HELP.________________________________________
_______________________________________________________________
_______________________________________________________________
Write the regular expression that you could enter in the OBJECT REPOSITORY to
make the property that specifies the title of a dialog box object, match dynamic
values.
The & operator is used to concatenate strings. For example, the evaluation of “a” &
“b” is “ab”. Using the & operator, write the programmatic description that you use
to correctly identify the FAX ORDER dialog box.
Instructor Notes
This is the new programmatic description code that replaces the two current lines that reference the FAX ORDER dialog box.
(Note that there are still errors in this code that will be addressed in the next part).
n
No:").GetROProperty("text")
io
at
' Fax the order (using programmatic descriptions.
lic
Window("Flight Reservation").Dialog("text:=Fax Order No. "
up
&OrderNumber).WinObject("attached_text:=Fax Number:").Type
rD
DataTable("Fax_Number",dtLocalSheet)
Window("Flight Reservation").Dialog("text:=Fax Order No. " Fo
&OrderNumber).WinButton("text:=&Send").Click
ot
-N
folder.
Ed
b) From the OBJECT REPOSITORY MANAGER menu bar, open the file
FLIGHTRESERVATION.TSR located in the
C:\TRAINING\QTP92ADVANCED\OBJECTS folder.
c) From the OBJECT REPOSITORY MANAGER menu bar, select FILE → SAVE AS
to save the OBJECT REPOSITORY with the name <YOUR-
INITIALS>_FLIGHTRESERVATION.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
a) Locate the FAX ORDER dialog box in the OBJECT REPOSITORY MANAGER.
P
b) Update the appropriate property value to use the regular expression that you
H
wrote in Part 2.
b) Click the ‘X’ REMOVE REPOSITORY button. A dialog box appears, prompting
you to confirm the removal.
n
5. Close any open instances of the Flight Reservation application.
io
at
lic
6. Run the test.
up
rD
The test should complete successfully.
Fo
Note: Check with your instructor if problems persist.
ot
-N
folder.
uc
Ed
2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
e
3. To ensure that the new test uses the original Object Repository:
So
P
Note: You must use the version of Object Repository that you used in Part 1.
H
n
io
at
lic
up
rD
Fo
ot
-N
5. In EXPERT VIEW, from the action list, select the ORDER_FAX_FLIGHT action to
ar
edit it.
ftw
So
6. Update the code to use the programmatic description that you wrote in Part 2.
P
H
a) The test still does not complete successfully. On which step does the test script
fail? What run error message is displayed?
b) Why is QuickTest unable to locate the object inside the FAX ORDER dialog
box?
QuickTest is unable to locate the object inside the FAX ORDER dialog box because it
is looking in OBJECT REPOSITORY for a WINOBJECT with parent
DIALOG("TEXT:=FAX ORDER NO. "&ORDERNUMBER). But this dialog box is not in
the OBJECT REPOSITORY. ___________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
n
io
at
Use a programmatic description for the WINOBJECT object. Look for object
lic
properties in OBJECT REPOSITORY or in HELP to find an appropriate property to
up
match. __________________________________________________________
rD
__________________________________________________________________
Fo
ot
__________________________________________________________________
-N
n
WinObject("attached_text:=") ___________________________________
at
uc
_______________________________________________________________
Ed
e
d) Are there any other steps that are to be corrected in the same way?
ar
ftw
If your test did not complete successfully, use the QuickTest Professional debug
features to help pinpoint the problem areas in the script.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
Purpose
up
rD
This lesson explains how to use VBScript operators, statements and functions. It covers the functionality of the
Fo
VBScript language.
ot
-N
Objectives
n
io
6-1
Using VBScript Operators, Statements and Functions
• VBScript operators
• VBScript statements
• VBScript functions
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
• Comparison operators
• Arithmetic operators
• Logical operators
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Comparison Operators
Comparison operators are used to compare expressions.
Operator Description
=, <> Equality, inequality
<, <= Less than, less than or equal to
>, >= Greater than, greater than or equal to
Is Object equivalence
n
io
This operator returns true if two variables refer to
at
the same object.
lic
up
Table 6-1. Comparison Operators
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Arithmetic Operators
Arithmetic operators are used to perform mathematical calculations.
Operator Description
+, - Addition, subtraction
*, / Multiplication, division
\ Integer division
This operator rounds off all numbers before
n
performing division.
io
at
Mod Modulus arithmetic
lic
This operator returns the remainder from a
up
division.
rD
- Negation Fo
ot
^ Exponentiation
-N
Logical Operators
Logical operators are used to perform logical operations.
Operator Description
And Conjunction
Or Disjunction
Not Negation
Table 6-3. Logical Operators
n
io
at
The following example shows how to use the And operator:
lic
up
rD
Example
Fo
ot
-N
n
io
In the above example, after inserting an order in the Flight application, you use the And operator to report a “pass”
at
to the result when the INSERT ORDER button disables and the UPDATE ORDER button enables.
uc
Ed
Example
P
H
In the above example, after inserting an order in the Flight application, you use the Or operator to report a “failure” to
the result when the INSERT ORDER button enables or the UPDATE ORDER button disables.
Example
In the above example, after inserting an order in the Flight application, you use the Not operator to report “failure” to
the result when the FLIGHTS button disables.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
Note: When operators are of the same precedence order, evaluate the operators from left
lic
to right. You can use parentheses to clarify or to override operator precedence.
up
For clarity and readability of code, it is generally recommended that you use parentheses rather than relying on
rD
operator precedence.
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
Instructor Notes
e
ar
Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer-teaching.
ftw
1+2*3
So
A: 7.
P
1 + 2 * 3 > (1 + 2) * 3
H
(1 > 2) Or (1 < 2)
A: True. Any one true condition in an Or expression makes the expression true.
n
io
at
Note: Detailed information on VBScript statements can be found in VBSCRIPT
lic
REFERENCE of QUICKTEST PROFESSIONAL HELP.
up
You have already learned how to declare constants and variables in lesson 4, Declaring Constants and Variables.
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Either the Rem statement or an apostrophe (‘) can be used to comment code. You can
comment either an entire line of code or just the text following the Rem statement or the
apostrophe (‘).
The following example shows how to comment code by using the Rem statement and an
apostrophe (‘):
n
Example
io
at
lic
up
rD
Fo
Note: When you comment at the end of a line, use a colon (:) before the Rem statement.
ot
-N
n
io
at
lic
up
rD
Figure 6-2 Commenting Multiple Lines
Fo
To comment multiple lines, from the QuickTest Professional menu bar, select EDIT →
ot
To uncomment multiple lines of code, from the QuickTest Professional menu bar, select
io
n
io
at
lic
up
rD
Figure 6-3 Indent and Outdent Commands
Fo
You can indent and outdent individual statements or blocks of statements using the
ot
INDENT and OUTDENT commands. This feature makes your test actions more readable
-N
To indent a statement(s), selecting the statement(s) and from the QuickTest Professional
uc
To outdent a statement(s), select the statement(s) and from the QuickTest Professional
e
ar
After a variable no longer references an object, the memory resources used by the object
are released. At the end of each run session, QuickTest releases all referenced objects.
For larger objects, you can explicitly disassociate the variable within your script using
the Nothing keyword. This enables the memory resources to be released prior to the end
of the run session.
The following example shows how to use the Set statement and the Nothing keyword:
n
io
at
lic
Example
up
rD
Fo
ot
In the above example, the objDescription variable points to a new Description object. The
-N
• Select Case
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
Use an IF ... THEN statement to evaluate if a condition is true or false, and depending on
at
Use an ELSEIF clause to evaluate multiple cases of a test. An IF ... THEN statement can
e
Use the final ELSE clause in a script to handle all the cases that do not satisfy any of the
So
Later in this lesson, you also use the Select Case statement to accomplish the same objective as that of the IF
H
n
io
at
Use the IF ... THEN statements to insert custom checkpoints in a script.
lic
up
Note: Insert a custom checkpoint to perform scripts validations.
rD
Custom checkpoints help retrieve or calculate an actual value from a script, which are
Fo
then compared with an expected value. If the values match, the Reporter object is used
ot
The CCur function in Figure 6-5 is covered, along with other conversion functions, later in this lesson.
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The Select Case statement evaluates a test expression and compares the result with the
values for each Case.
The following example shows how to use the Select Case statement:
Example
n
io
at
lic
up
rD
Fo
ot
-N
The Select Case statement is more efficient than the IF ... THEN statement, particularly
n
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
Instructor Notes
So
Use this slide as an opportunity to elicit student understanding (or misunderstanding) and to support peer-teaching.
P
A: The results show that the test passed, and displays the text “intMatchItem = 3 ”.
H
n
io
at
Note: Detailed information on VBScript functions can be found in VBSCRIPT
lic
REFERENCE of QUICKTEST PROFESSIONAL HELP.
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Table 6-4 describes the VBScript functions that are used to manipulate text strings.
Function Description
String Accepts a number and a character. Returns a
string created with the character that is repeated
the given number of times.
n
io
Len Returns the number of characters in a given
at
string.
lic
up
InStr Accepts two strings and returns whether the
rD
second is contained within the first or not.
Fo
Left, Right Accept a string and a length, and return a
ot
Table 6-5 describes some of the VBScript functions that are used for date formatting.
Function Description
Date, Time, Now Date returns the current system date. Time returns
the current system time. Now returns the system
date and time.
n
io
DateAdd Adds the specified number of years, months,
at
weeks, days, hours, minutes, or seconds to the
lic
given date.
up
rD
DateDiff Returns the number of years, months, weeks,
Fo
days, hours, minutes, or seconds between the two
given dates. The return value is negative if the
ot
Day, Month, Year, Weekday Accepts a date and returns just the desired portion
io
of the date.
at
uc
Table 6-6 describes some of the VBScript functions that are used to convert values from
one type to another.
Function Description
CInt Converts an expression to an integer value, as shown:
n
CBool Converts an expression to a Boolean value. If the expression evaluates to
io
a nonzero value, CBool returns true; otherwise, CBool returns false.
at
lic
CStr Converts an expression to a string value.
up
rD
CDate Converts an expression to a date value.
Fo
CCur Converts an expression to a currency value, as shown:
ot
-N
n
Note: VBScript also provides the functions IsNumeric and IsDate functions to check
e
ar
n
io
at
lic
up
rD
Fo
ot
Instructor Notes
uc
Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer-teaching.
Ed
A: 9.
ar
ftw
Right(Left(“IG_CRT_Special”, 6), 3)
So
A: “CRT”.
P
H
Mid(“IG_CRT_Special”, 4, 3)
A: “CRT”.
Month (“02/28/2005”)
A: 2.
Table 6-7 describes the VBScript functions that invoke dialog boxes to interact with
users.
Function Description
InputBox Prompts for additional data from the user. This
function displays a new dialog box with the given
prompt, waits for user input, and returns the
contents entered by the user.
n
io
at
MsgBox Displays a given message in a new dialog box,
lic
waits for the user to click a button, and returns the
up
button that is clicked.
rD
Fo
Table 6-7. InputBox and MsgBox Functions
ot
The following example shows the code to prompt a user for the birth year and then
-N
Example
Ed
e
ar
ftw
So
P
H
In the above example, the first text string is the prompt or message to be displayed in the dialog box. The optional
second text string is used as the title of the dialog box. The MsgBox function accepts a settings argument that
specifies the buttons it should present as options; the MsgBox function returns the value of the button clicked.
Summary
In this lesson, you learned how to:
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
6-26 Summary
Using VBScript Operators, Statements and Functions
Review Questions
Now answer these review questions.
1. Which VBScript operator can be used to check that both the DELETE ORDER button
and the UPDATE ORDER buttons are enabled in the Flight Reservation application?
You can use the logical And operator to check the enabled state of both buttons.
The Is operator returns true if two variables refer to the same object. ________
n
io
The Set statement enables to assign a variable to point to an object. _________
at
lic
4. What does the Split function do?
up
rD
The Split function accepts a string and a delimiter character, and returns an array
Fo
of substrings._____________________________________________________
ot
-N
_______________________________________________________________
n
5. What are two VBScript functions that invoke dialog boxes to interact with users?
io
at
uc
InputBox and MsgBox are the VBScript functions that invoke dialog boxes to
Ed
_______________________________________________________________
ftw
So
P
H
Exercise introduction
Students modify the VBScript test so that it inserts a custom checkpoint, validating that the number of itineraries has increased
after a new purchase. Ask the students to perform this exercise in groups of two.
To ensure that the students understand this exercise, demonstrate the functionality of the Mercury Tours application to the
students. For this, perform the following steps:
- Log on to Mercury Tours application.
- Book a flight.
- Click the ITINERARIES link in the application and count the number of itineraries.
- Book another flight.
- Confirm that the number of itineraries has increased by one on the ITINERARIES page.
n
Specific objectives
io
At the end of this exercise, students should be able to:
at
- Use the ChildObjects method to retrieve dynamic objects.
lic
- Write VBScript code that has correct syntax and that works as desired.
up
- Write an IF ... THEN statement to control the flow of your test and use string manipulation functions.
rD
Note: In previous lessons, Part 1 of the exercises provided students with the exact code to be used later. This is not true in this
Fo
lesson. The analyses will provide discussions of key challenges of the problem and ideas for a solution, but the actual code will be
left to students to write independently.
ot
-N
Technical setup
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
n
io
student computer:
at
, with which to begin the exercise. The test works as described in Part 1.
-- The VBScriptSolution1 and VBScriptSolution2 tests provide sample solutions.
Ed
e
In this exercise, you determine the VBScript operators, statements, and functions
ar
required for a specific purpose. You update a test by using VBScript and other features
ftw
in QuickTest Professional.
So
P
• Part 2: Update the script to confirm that the number of itineraries increases by one
after a flight purchase.
• Optional Part 3: Update the script so that the results contain the year and month
when the first itinerary is booked.
• The script reports the year and month of the booking of the first itinerary to results.
Answer the following questions to break down the requirements for this test case.
1. The itinerary page of the Mercury Tours application, as shown in Figure 6-8,
includes dynamic objects to display the complete list of flights that you booked.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Figure 6-8 The Dynamic Itinerary Page of the Flight Reservation Application
a) Which objects on the itinerary page do you count to determine the number of
current itineraries? Which properties you use to identify those objects? (Hint:
Open the Mercury Tours application and use the OBJECT SPY to examine how
the objects are defined.)
1) Can count the number of check boxes on the page to determine the number of
current itineraries; use html tag = INPUT, type = checkbox to identify these objects;
2) Can count the number of “DETAILS” images to determine the number of current
itineraries; use html tag = IMG, file name = DETAILS.GIF to identify these objects;
3) Can count the number of WebElements with inner text matching “PASSENGERS”
to determine the number of current itineraries. _____________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
n
io
__________________________________________________________________
at
lic
up
b) How do you retrieve a count of the above objects on the itinerary page?
rD
Use the ChildObject method to retrieve the collection of all objects on the page
Fo
with the desired characteristics. Use the Count method on the collection to retrieve
ot
__________________________________________________________________
io
at
__________________________________________________________________
uc
Ed
c) How do you save the count of the original number of itineraries to compare it
e
to a later count?
ar
ftw
Use a variable to save the count of the original number of itineraries and to compare
So
__________________________________________________________________
d) How do you indicate success in the test results if the number of itineraries
increments correctly and indicates failure if the number does not increment
successfully?
Use the IF ... THEN statement to compare the original and updated itinerary counts.
If the itinerary count increments correctly, use the Reporter.ReportEvent method
with micPass. If not, use the Reporter.ReportEvent method with micFail.
__________________________________________________________________
__________________________________________________________________
__________________________________________________________________
2. Optional - The ITINERARY page, as shown in Figure 6-9, displays a list of booked
itineraries in the order that they were purchased, with the earliest itinerary listed
first.
For each itinerary, there is a WebTable cell with the text, “ Booked YYYY-MM-DD
HH:MM:SS”. (Note: There is a space character before “Booked”). The WebTable
represents information in tables in Web applications. The name property for the
WebTable always matches the name of the check box object for that same itinerary.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
a) The following code is not commented. Use the space provided to describe the
functionality of each block of code.
i. Code 1:
Set objCheckboxDesc = Description.Create()
objCheckboxDesc ("type").Value = "checkbox"
ii. Code 2:
strName = objCheckboxes(0).GetROProperty("name")
iii. Code 3:
Set objTableDesc= Description.Create()
objTableDesc("html tag").Value = "table"
objTableDesc("rows").Value = 1
n
objTableDesc("name").Value = strName
io
Set objBookedTables = Browser("Welcome: Mercury
at
Tours").Page("Itinerary: Mercury
lic
Tours").ChildObjects(objTableDesc)
up
rD
Retrieves the WebTable objects that have the same name as the first check box of
Fo
the itinerary. ________________________________________________________
ot
-N
__________________________________________________________________
n
io
iv. Code 4:
at
v. Code 5:
P
Else
H
strBookedFirstItinerary =
objBookedTables(0).GetROProperty("text")
Reporter.ReportEvent micDone, "strBookedFirstItinerary",
strBookedFirstItinerary
End If
If found, the correct WebTable retrieves the “BOOKED” text and reports the string to
results._____________________________________________________________
__________________________________________________________________
b) How do you retrieve year information from the text string “ Booked YYYY-
MM-DD HH:MM:SS”? (Note: There is a space character before “Booked”)
Many different ways. One VBScript expression that will work is: ___________
c) How do you retrieve month information from the text string “ Booked YYYY-
MM-DD HH:MM:SS”? (Note: There is a space character before “Booked”)
Many different ways. One VBScript expression that will work is: ___________
d) How do you convert the month value from a number to the name for that
month?
n
Another way to do this is to use the MonthName VBScript function available in
io
at
HELP.___________________________________________________________
lic
up
_______________________________________________________________
rD
_______________________________________________________________
Fo
ot
1. Within the Mercury Tours application, cancel all itineraries except one.
at
uc
Note: You can do this by clicking CANCEL ALL RESERVATIONS and then adding a new
Ed
purchase, or by selecting all the itineraries except one and clicking CANCEL CHECKED
e
ar
RESERVATIONS.
ftw
folder.
P
H
3. Click the START SERVER shortcut on the desktop to start the application server for
Mercury Tours. Minimize the START SERVER window but do not close it.
4. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYVBSCRIPT1.
5. Update the test with the code that increases the number of itineraries by one.
If your test did not complete successfully, use the QuickTest Professional debug features
to help identify the trouble areas in the script.
2. Click the START SERVER shortcut on the desktop to start the application server for
Mercury Tours. Minimize the START SERVER window but do not close it.
3. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYVBSCRIPT2.
4. Update the test with the code that generates the year and month when the first
n
io
itinerary was booked.
at
lic
5. Run and debug the updated test.
up
rD
6. Confirm that your script works even when the Application Under Test (AUT) starts
with no itineraries created. Fo
ot
If your test does not complete successfully, use the QuickTest Professional debug
-N
n
Purpose
io
at
This lesson explains how to retrieve data from application objects and work with the retrieved data. The lesson
lic
discusses the VBScript looping statements and how DATA TABLES are used to iterate actions.
up
rD
Objectives Fo
ot
•
n
• Use the DATA TABLE object to store run-time data and drive actions.
e
ar
7-1
Working with Dynamic Data
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
For static data, you hard-code specific test values in your scripts or in data sheets.
P
For dynamic data, you retrieve data from the run-time application or from an external
H
source.
Figure 7-1 shows how static and dynamic data are used in an application.
The next lesson, “Retrieving External Data”, covers how to retrieve data from external sources.
The following are common Windows and Web objects that contain the data that you
retrieve from a run-time application and use in a script:
• WINCOMBOBOX
• WINLIST
• WEBLIST
• WEBTABLE
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
You retrieve data from the WINCOMBOBOX and WINLIST objects by using the GetItem
and GetItemsCount methods.
The following example shows how to retrieve data by using the GetItem and
GetItemsCount methods for a WINLIST object:
Example
In the above example, the first item on the list is always numbered 0.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
Figure 7-3 shows the DEPARTING FROM object, which is of type WEBLIST.
P
You retrieve data from a WEBLIST object the same as t for a WINLIST object. The
H
The WEBLIST object uses the GETROPROPERTY method to retrieve the items count.
The following example shows how to retrieve data using the GETITEM method for a
WEBLIST object.
Example
In the above example, the first item on the list is always numbered 1.
n
io
at
lic
up
rD
Fo
ot
Figure 7-4.
uc
Ed
You retrieve data from a WEBTABLE object by using the GetCellData, ColumnCount,
and RowCount methods.
e
ar
ftw
The following example shows how to retrieve data using the GetCellData and
So
Example
The above example retrieves the flight time for a random flight displayed in the departure table in Figure 7-4.
WebTables can have differing column counts for each row. Therefore the row is passed in as an argument to the
ColumnCount method. The first row and column in the table are always numbered 1.
VBScript provides the following looping statements that enable you to run a block of
statements for a specified duration:
• FOR...NEXT
• WHILE...WEND
n
•
io
DO...LOOP
at
lic
These statements specify different looping durations.
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The following example shows how to use the FOR...NEXT statement to repeat a group of
statements a specified number of times:
Example
n
io
at
The Step keyword is used to define how the counter increments for the FOR...NEXT
lic
statement.
up
rD
The following example shows how to use the Step keyword to define the counter
variable increments:
Fo
ot
-N
n
Example
io
at
uc
Ed
e
ar
A common practice using the FOR...NEXT statement is to name the loop counter variable i. When loops are
ftw
The following example shows how to use the WHILE...WEND statement to execute a
series of statements as long as a given condition is True:
Example
n
io
at
lic
up
rD
Fo
ot
-N
n
io
In the above example, the script loops through values of a list until the desired value is
at
found or until the script exhausts the list. At the end of the loop, the bFound keyword
uc
indicates whether the item is found or not. If found, the intFountItemIndex keyword
Ed
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
In Figure 7-5, the example on the left shows how to use the DO WHILE statement for
repeating a set of statements while a condition is True. This is called a continuation
e
ar
condition. The example on the right shows the use of the DO UNTIL statement for
ftw
repeating a set of statements until a condition becomes True. This is called a termination
So
condition.
P
H
n
io
at
Figure 7-6 Evaluation at the Start Versus at the End
lic
up
With the DO...LOOP statement; you can evaluate a condition at the start or at the end of a
rD
loop. Evaluating a condition at the end of the loop ensures that the loop is always
executed at least once. Fo
ot
In Figure 7-6, after execution of the code on the left, i = 0. After execution of the code
-N
on the right, i = 1.
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The following example shows how to nest VBScript looping statements within another
looping statement:
Example
n
io
at
lic
up
rD
In the above example, the script steps through the cells of a WebTable and reports its data in the results. The script
uses FOR...NEXT loops to step through each column of each row. The WebTable may have differing column counts
Fo
for each row. Therefore, the WebTable passes the row as an argument to the ColumnCount method.
ot
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
In addition to using the VBScript loop statements, you can also iterate a test, action, or
So
You configure the iteration settings for a test and action in the TEST SETTINGS dialog
box and the ACTION CALL PROPERTIES dialog box, respectively, as shown in Figure 7-7.
For test iteration settings, click the RUN tab of the TEST SETTINGS dialog box. For action iteration settings,
right-click the action in KEYWORD VIEW and select ACTION CALL PROPERTIES from the pop-up menu.
n
Figure 7-8 Dynamically Populating the Data Table
io
at
lic
Instead of hard-coding data in a data sheet before a run session, you can retrieve the data
up
from an application at run-time and store it in the DATA TABLE.
rD
Fo
Figure 7-8 shows a script that loads a data sheet at run-time with the departure city
information retrieved from the Mercury Tours application.
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
Use the Step Generator to insert the following common methods used to work with the
P
DATA TABLE:
H
The following example shows how to use the GetSheet method to retrieve specific
data sheets:
Example
The following example shows how to use the GetRowCount and SetCurrentRow
methods to iterate through data sheet rows:
Example
You can also use the SetNextRow and SetPrevRow methods as an alternative to the
SetCurrentRow method. The first row of a data sheet is always considered as row 1.
n
• Value: To retrieve or assign data into a cell in a DATA TABLE object.
io
at
lic
The following example shows how to use the Value method to get data from the
up
data sheet and set the data into a specified cell of the data sheet:
rD
Fo
ot
Example
-N
n
io
at
uc
Ed
Value is the default method of the DATA TABLE object. Therefore, in the above
e
Column Name”).
ftw
So
P
H
Summary
In this lesson, you learned how to:
• Use the DATA TABLE object to store run-time data and drive actions.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
7-18 Summary
Working with Dynamic Data
Review Questions
Now answer these review questions.
To retrieve data from the WEBLIST object, use the GetItem method. _________
The FOR...NEXT statement uses a counter wheras the WHILE...WEND statement uses
a condition to control the number of iterations to be run. __________________
_______________________________________________________________
n
io
3. What does the GetSheet method in the DATA TABLE object do?
at
lic
The GetSheet method is used to retrieve specific data sheets for further processing.
up
rD
_______________________________________________________________
Fo
4. Which property is used to retrieve or assign data into a cell in a DATA TABLE
ot
-N
object?
n
Use the Value property to retrieve or assign data into a cell in a DATA TABLE
io
at
object.
uc
Ed
_______________________________________________________________
e
ar
ftw
So
P
H
Exercise introduction
Students complete the DynamicData test by filling in two empty actions to achieve the desired objective.
Specific objectives
At the end of this exercise, students should be able to:
- Retrieve run-time test data options from the application.
- Use the nested FOR...NEXT looping statements to control the number of iterations to be run.
- Read from and write to a data sheet in DATA TABLE to store run-time data and drive actions.
Note: The analyses of this exercise will provide discussions of key challenges of the problem and ideas for a solution, but the
actual code will be left to students to write independently.
Technical setup
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
n
io
student computer:
at
-- Students are provided with a base test, DynamicData to begin the exercise.
lic
-- The DynamicDataSolution test provides a sample solution.
up
In this exercise, you update a test script so that it no longer uses hard-coded data but uses
rD
data retrieved dynamically from the application. Fo
ot
Instructor Notes
e
There are five actions in the script. They are: LOGIN, LOGOUT, PURCHASEFIGHT,
and two empty actions called GETDATA and CREATEPERMUTATIONS. ________
_______________________________________________________________
n
io
at
Each action is executed once during a run session. _______________________
lic
up
3. Between which two cities are the passengers traveling?
rD
The passengers are traveling from New York to Paris. ____________________
Fo
ot
•
uc
Retrieves the options for departure and arrival cities from the application at run-
Ed
time.
e
•
ar
Tests that a flight can be purchased from three departure cities to three different
ftw
arrival cities.
So
Answer the following questions to break down the requirements for this test case.
P
H
1. How do you retrieve the departure city information and arrival city information? In
which of the existing actions do you add this code?
Use the GetItem method on the TOPORT and FROMPORT WebLists. Add this
method to the GETDATA action. ______________________________________
_______________________________________________________________
2. How do you build a list of the possible pairs of departure and arrival cities? In
which of the existing actions do you add this code?
Use two nested FOR loops to match every departure city to every arrival city. Add
the loops to the CREATEPERMUTATIONS action.__________________________
_______________________________________________________________
3. How do you save the list of departure-arrival pairs for use in the PURCHASEFLIGHT
action?
Store the data in the data sheet of the PURCHASEFLIGHT action. _____________
4. How do you update the PURCHASEFLIGHT action to use the dynamic data?
Update all the WebList(<port>.Select lines to pull data from the local data
sheet. Also, update the ACTION CALL PROPERTIES window to iterate on every row.
_______________________________________________________________
_______________________________________________________________
n
io
at
Part 3: Update the Script for the First Objective
lic
up
1. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
rD
as MYDYNAMICDATA.
Fo
2. Update the test with code necessary to achieve this objective.
ot
-N
If your test did not complete successfully, use the QTP debug features to help identify
at
1. Update the test with the code necessary to validate purchases for each combination
P
Note: For the purposes of this exercise, reduce the number of the combinations by using
just the first three departure cities and last three arrival cities instead of the full lists.
If your test did not complete successfully, use the QTP debug features to help identify
the trouble areas in the script.
n
io
at
lic
Purpose
up
rD
This lesson covers the steps for retrieving data from external data sources, such as Microsoft Excel, databases, and
text files.
Fo
ot
Objectives
-N
n
•
uc
• Import data from and export data into a Microsoft Excel worksheet.
e
ar
•
ftw
8-1
Retrieving External Data
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
You may want to test an application for different data sets. For example, you may want
H
to check the login functionality of an application with different sets of user names and
passwords. The user names and passwords could reside in external data sources, such as
Microsoft Excel or Microsoft Access.
If you store the test data for an application in external data sources, you retrieve data
from the data sources to test the application. You may also extract data from QuickTest
and store it in external data sources for future references.
Note: It is recommended that you maintain the test data externally from the QuickTest
script so that you can validate the data of the application independently.
• ImportSheet: Imports a sheet from a Microsoft Excel file to a specified sheet in the
run-time data log.
• ExportSheet: Exports the specified sheet of the run-time data log to a Microsoft
Excel file on the computer on which QuickTest Professional is installed.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
file to a sheet in the run-time data log. In Figure 8-2, the imported data is stored in the
uc
After the data is imported from a Microsoft Excel file into DATA TABLE, use the DATA
TABLE to drive the iterations of an action.
So
P
Use the data in the first row of the Microsoft Excel worksheet as column names for the
H
Note: Ensure that the first row of the Microsoft Excel worksheet has the exact data that
you want for the DATA TABLE columns.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
Export the data saved in the run-time data table to Microsoft Excel if you want to access
P
Use the DataTable.ExportSheet method to export a sheet of the run-time data table to
a Microsoft Excel file. The data can be stored in an existing Microsoft Excel file or used
to create a new Microsoft Excel file.
In Figure 8-3, export the data from the GLOBAL DATA TABLE to a new Microsoft Excel
file.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
• The Connection object: Opens a session with a database and executes a query. The
Connection object can be used to access any database with an Open Database
Connectivity (ODBC) driver.
• The RecordSet object: Stores the information retrieved from the database.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Connecting to a Database
To connect to a database from a QuickTest Professional script:
n
io
at
Example
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
In the above example, in the script, you can replace the final two lines with objDB.Open
“DSN=Flight32_TestData.xls” to get the same result as the ConnectionString
property.
The Execute method accepts an SQL statement as an input and returns a RecordSet
object when the run completes.
Example
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
In the above example, FLIGHTS : TABLE (containing 4514 rows) is queried for all rows with SAN
FRANCISCO as the departure city.
• Beginning of File (BOF) and End of File (EOF): These properties determine if you
are at the boundaries of the RecordSet object.
• MoveNext, MovePrevious, and Move: The MoveNext method moves one record
forward and the MovePrevious method moves one record backward in the
RecordSet object. The Move method moves multiple records forward or backward at
a time.
n
io
the SQL query.
at
lic
• Fields(“MyColumn”) or Fields.Item(“MyColumn”).Value: These methods
up
return the value saved in the specified column of the current record in the RecordSet
rD
object. Fo
ot
The following example shows how to use the properties and methods of the RecordSet
-N
object:
n
io
at
uc
Example
Ed
e
ar
ftw
So
P
H
In the above example, the code steps through all the flight rows with SAN FRANCISCO as
the departure city. The code retrieves the flight number and arrival information from
each row.
Note: Closing the Connection object will automatically close any active RecordSet
object associated with the Connection object.
After the RecordSet or Connection objects is closed, you can set their variables to
Nothing.
The following example shows how to use the Close method in the RecordSet object:
n
io
Example
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Use the FileSystemObject object to read data into the QuickTest script.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The TextStream object has the following methods for reading text from a file:
• Read: Reads a specified number of characters from the TextStream object and
returns a string.
n
•
io
ReadLine: Reads from a TextStream object until a newline character is encountered
at
and returns a string.
lic
up
• ReadAll: Reads an entire TextStream object and returns a string. This method is not
rD
recommended for large files. Fo
ot
The following example shows how to use the OpenTextFile method:
-N
n
io
Example
at
uc
Ed
e
ar
ftw
So
P
H
Writing to a File
Use the OpenTextFile or the CreateTextFile method in the FileSystemObject
object to create a new file for writing text to the file. Both the methods return a
TextStream object.
The TextStream object has the following methods for writing text to a file:
n
io
The following example shows how to use the CreateTextFile method:
at
lic
up
rD
Example
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Summary
In this lesson, you learned how to:
• Import data from and export data into a Microsoft Excel worksheet.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Summary 8-15
Retrieving External Data
Review Questions
Now answer these review questions.
1. Give a scenario where you may be required to access data from external sources.
To assign external data to QuickTest to make a script run, instead of hard coding
data, you may need to access data from an external source. ________________
_______________________________________________________________
2. What are the methods used to import data from and export data into a Microsoft
Excel worksheet.
n
The methods used to import and export data to a Microsoft Excel file are:
io
ImportSheet and ExportSheet. ____________________________________
at
lic
_______________________________________________________________
up
rD
3. What does the Close method do? Fo
ot
The Close method closes a database session. ___________________________
-N
4. What are the methods of the TextStream object used for reading from a text file?
n
io
at
The methods of the TextStream object used for reading text from a text file are:
uc
_______________________________________________________________
e
ar
ftw
So
P
H
Exercise introduction
Students modify the ExternalData test so that rather than retrieving test data from the application, the script retrieves data from a
Microsoft Excel worksheet and a Microsoft Access database.
Specific objectives
At the end of this exercise, students should be able to:
- Retrieve data from a Microsoft Excel worksheet.
- Retrieve data from a Microsoft Access database.
Technical setup
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
student computer:
-- Provide the students with a base test, ExternalData to begin the exercise.
-- Provide the students with the Microsoft Excel file, MercTours_TestData.xls. This file exists in the
n
C:\Training\QTP92Advanced\data folder. It contains the worksheet DataSet1.
io
-- Provide the students with the Access database, MercTours_TestData.mdb. The database exists in the
at
C:\Training\QTP92Advanced\data folder.
lic
-- Create a data source named MercTours_TestData on the student workstation. The data source name should point to
up
MercTours_TestData.mdb.
rD
Note
-- The ExternalDataSolution1 test provides a sample solution for Part 1 of this exercise.
Fo
-- The ExternalDataSolution1 test provides a sample solution for Part 2 of this exercise.
ot
-N
In this exercise, you update a script to retrieve test data from a Microsoft Excel file,
MercTours_TestData.xls and a Microsoft Access file,
n
io
MercTours_TestData.mdb.
at
uc
2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYEXTERNALDATA.
3. Which action in the script do you need to update for this exercise?
4. Write the VBScript code to retrieve information from the Microsoft Excel file,
MercTours_TestData.xls.
DataTable.ImportSheet
"C:\Training\QTP92Advanced\data\MercTours_TestData.xls",
"DataSet1", "GetData" ________________________________________
_______________________________________________________________
_______________________________________________________________
5. Use code to update the test so that you canate the test with the code to retrieve data
from the Microsoft Excel worksheet.
n
io
at
If the test fails, use the QuickTest Professional debug feature to troubleshoot the script.
lic
up
Note: Check with your instructor if problems persist.
rD
Fo
Part 2: Import Data from a Microsoft Access File
ot
C:\TRAINING\QTP92ADVANCED\TESTS folder.
n
io
2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
at
uc
3. Which action in the script do you need to update for this exercise?
e
ar
4. Write the VBScript code to open a connection to the Microsoft Access database,
P
MercTours_TestData.
H
objDB.Open ____________________________________________________
5. Write the VBScript code to retrieve the list of departure and arrival cities.
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
n
io
6. Where will you store the results returned by the queries?
at
lic
In the DATA TABLE of the GetData action. _____________________________
up
rD
Write the VBScript code to store the list of departure cities.
Fo
i = 1
ot
-N
DataTable.GetSheet(dtLocalSheet).SetCurrentRow i
at
uc
DataTable("Departure_Cities", dtLocalSheet) =
Ed
objDepartureCities.Fields("City")
e
objDepartureCities.MoveNext
ar
ftw
i + 1
So
Loop
P
H
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
7. Write the VBScript code to clean up the Connection and RecordSet objects.
objDepartureCities.Close
objArrivalCities.Close
objDB.Close
_______________________________________________________________
n
io
at
_______________________________________________________________
lic
up
_______________________________________________________________
rD
Fo
_______________________________________________________________
ot
_______________________________________________________________
-N
n
_______________________________________________________________
io
at
8. Use code to update the test so that you can retrieve data from the Microsoft Access
uc
database.
Ed
e
If the test fails, use the QuickTest Professional debug feature to troubleshoot the script.
So
P
n
io
at
lic
Purpose
up
rD
This lesson covers the creation of new procedures. The lesson also covers the various contexts where new
procedures can be defined.
Fo
ot
-N
n
io
Objectives
at
uc
9-1
Creating New Procedures
An Introduction to Procedures
A procedure is a series of statements grouped together to perform a specific task. For
example, in the Mercury Tours application, if you want to login from ten different
scripts, you can write the login code in a procedure and call that procedure in each script
from which you want to login.
n
io
scenarios.
at
lic
The following are the two types of procedures in VBScript:
up
rD
• Subroutines
Fo
• Functions
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
Accepts arguments True True
lic
Can call other procedures True True
up
rD
Can call itself True True
Fo
Table 9-1. Subroutines and Functions
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The following example shows how to use a subroutine procedure to clean up the
specified Connection and RecordSet objects after you have used these objects in the
script:
n
io
Example
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
A subroutine can be marked as public or private. You will learn about public and private procedures, in more detail,
Ed
The following example shows how you can use a function procedure to accept a query
string and Connection object to return the RecordSet object of the query execution:
n
io
Example
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
Figure 9-1 shows how to add the steps for a new procedure directly into a script.
n
io
at
lic
up
rD
Fo
ot
-N
After creating the code for a procedure, declare the procedure. Declaring a procedure
uc
Note: Mark the end of a procedure with the appropriate ending keywords, as shown in
ar
ftw
Figure 9-2.
So
You can indent the code within a new procedure to improve readability. To indent code:
- In the EDITOR OPTIONS dialog box, click INDENT SELECTED TEXT WHEN PRESSING TAB KEY.
P
Defining an Argument
n
io
at
lic
up
rD
Fo
ot
-N
n
io
After declaring a procedure, identify the values that the procedure will need passed in
Ed
from the calling script. Type these values in the script as argument variables for the
e
ar
procedure. For example, after creating a procedure for log in, pass a user name and
ftw
password to this procedure so that the procedure can log in by using these input values.
So
Use the ByVal keyword to prevent a procedure from changing the value of the variable
P
passed into it, as shown in Figure 9-3. By default, QuickTest Professional uses the
H
reference keyword, ByRef, to pass arguments to the procedure. The ByRef keyword
enables a procedure to assign the argument variable to a new value.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
After building a new procedure, the procedure might be expected to return a value based
Ed
on the operation it performs. For example, the login procedure is expected to return a
e
ar
Return a value from a function by assigning the function name to the desired value, as
So
In addition to a return value of the function, functions and subroutines have other output
values. Procedures can set any ByRef argument to new values. These new values are
passed back to the line that calls the procedure.
Handling Errors
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Enhance a procedure to handle alternate application under test states and to validate
e
ar
arguments.
ftw
Use the IF ... THEN statement to test the existence of the error dialog box and use the
So
H
Error handling and Exit statements are covered in more detail in lesson 10, “Managing QuickTest Professional
Exception Handling”.
• Local action or component: Procedures that are useful only in the current QuickTest
Professional action or scripted component.
• Test object class: Procedures that are associated with a particular QuickTest
Professional test object class. These may be new methods added to the class or an
override of an existing method.
• Library file: Procedures that are used in multiple QuickTest scripts by associating
library files with that script.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
To use a procedure locally in the same script in which it is defined, add the procedure
ftw
After adding the procedure to the script, use the procedure either by typing its name
P
H
directly into the script or by using STEP GENERATOR as shown in Figure 9-6.
Note: A script can access a local procedure only if the procedure is defined in that script.
When creating a procedure for use as a QuickTest Professional test object method, you
can perform the following steps:
n
To register a procedure for use in a business component, you use a library file to create
io
at
the procedure and register it in the library file.
lic
Library files are discussed later in this lesson.
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The following example shows how to use the RegisterUserFunc statement to return
the items count property of a WEBLIST object class:
Example
n
io
at
lic
up
rD
Fo
ot
-N
n
io
After associating a procedure with a test object class, the procedure remains registered
at
with the object class until it is unregistered explicitly or until the next QuickTest
uc
Note: To be registered with an object class, the procedure that you define must have an
ar
ftw
The following example shows how to use the RegisterUserFunc statement to override
the Set method of the WEBEDIT object class with the SetWithDebug procedure:
Example
n
io
at
lic
up
rD
Fo
You use the registered SetWithDebug procedure whenever the Set method is called for a WEBEDIT
object.
ot
-N
Note: To override an existing object method, the procedure you define must have an
n
object as its first argument, and the remaining arguments should match the arguments of
io
at
n
io
at
lic
up
rD
Fo
ot
generate definitions for new user-defined functions and add header information to them.
at
uc
1. Ensure that the function library or test where you want to insert the function
ar
appears.
In the FUNCTION DEFINITION GENERATOR dialog box, fill in the required information.
The FUNCTION DEFINITION GENERATOR creates the basic function definition and
associates it with the test.
Unregistering a Procedure
Use the UnregisterUserFunc statement to dissociate any user-defined procedures that
are associated with a test object class.
Example
n
io
at
lic
up
You should unregister a procedure in the same context in which the procedure was
rD
registered. If a procedure is registered within a QuickTest Professional action, unregister
Fo
it in the same action. Similarly, if a procedure is registered within a QuickTest
ot
Professional library file, unregister the procedure in the same library file.
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Building a Library
Build library files to make procedures accessible to multiple QuickTest scripts.
n
There are several ways of associating a library file to a test.
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
A QuickTest Professional library file is a text file that contains VBScript subroutines
Ed
2. Copy and paste the desired procedures into the newly created file.
P
H
– Public procedures are accessible outside the library file: These are the default
procedures. Procedures not marked as Public or Private are assumed to be
Public.
– Private procedures can be called only within the library file: These are the
helper procedures, used only by other procedures in this library.
Note: The constants and variables added to libraries are available to all the actions in a
test.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Figure 9-9 Library File Creation the Using Function Library Editor
Ed
LIBRARY editor enables you to create and edit function libraries that contain VBScript
ftw
You can create, open, and work on multiple function libraries simultaneously. Each
P
H
FUNCTION LIBRARY editor opens in its own document window. When working with a
FUNCTION LIBRARY editor, another testing document, such as a test, application area, or
component, is always open. This open testing document enables you to add calls to
functions as you create or modify them.
To open a FUNCTION LIBRARY editor, from the QuickTest Professional menu bar, select
FILE → OPEN → FUNCTION LIBRARY. The OPEN FUNCTION LIBRARY dialog box
opens, as shown in Figure 9-9. The OPEN FUNCTION LIBRARY dialog box enables you to
open the desired FUNCTION LIBRARY editor in QuickTest Professional.
Associating a Library
n
io
at
lic
up
rD
Fo
ot
-N
n
io
After creating a library, associate the library with the script where you intend to use the
Ed
1. From the QuickTest Professional menu bar, select SETTINGS → TEST SETTINGS →
RESOURCES to open the RESOURCES tab.
P
H
2. Under LIBRARIES, click the ‘+’ ADDS A NEW FILE TO THE FILE LIST button to
associate the desired library files.
Note: QuickTest Professional searches for functions in the libraries in the order listed. If
a function is defined in multiple libraries, QuickTest Professional uses the first
definition that it finds.
5. Click SET AS DEFAULT to automatically associate the selected libraries with your
new tests or application areas.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
To associate a function library with an open test use the associated function libraries list.
ftw
1. Ensure that the test that you want to associate with the function library is open in
P
QuickTest Professional.
H
Note: Before continuing to the next step, ensure that the function library that you want
to associate with the test is the active document.
Using a Procedure
You can use a procedure in:
• Scripts
• Recovery Scenarios
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
• New library procedures are available under LIBRARY FUNCTIONS in the FUNCTIONS
P
H
category.
• New local procedures are available under LOCAL SCRIPT FUNCTIONS in the
FUNCTIONS category.
• New object methods and the standard object methods are available within the TEST
OBJECTS category.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
1. From the RECOVERY SCENARIO MANAGER, select the desired scenario and click the
e
ar
EDIT button. The RECOVERY SCENARIO WIZARD appears. Click NEXT until you
ftw
2. Check the ADD ANOTHER RECOVERY OPERATION check box and click NEXT.
P
H
3. For OPERATION TYPE, select the FUNCTION CALL option and click NEXT.
5. Call the desired function, or define a new function to be added to the library, and
then click NEXT. The RECOVERY OPERATIONS page appears with the function call
added as an operation.
• A function.
• Defined in a library file: You can define the function before you define the recovery
scenario, or you can define the function when defining the recovery scenario.
• Defined to accept the following input, depending on the trigger for the recovery
scenario.
n
io
Trigger Input
at
lic
Pop-up window The detected pop-up window object
up
Object state The detected object
rD
Test run error • Fo
The object in the faulty step
ot
•
-N
•
io
the method
uc
Ed
method
ar
ftw
If you choose to define the function while defining the recovery scenario, QuickTest
P
H
Summary
In this lesson, you learned how to:
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
9-28 Summary
Creating New Procedures
Review Questions
Now answer these review questions.
_______________________________________________________________
_______________________________________________________________
n
io
at
2. What is the difference between a subroutine and function?
lic
up
A subroutine procedure is a series of VBScript statements that perform actions but
rD
do not return a value. A function procedure is a series of VBScript statements that
Fo
perform actions and return a value. ___________________________________
ot
-N
_______________________________________________________________
n
io
_______________________________________________________________
at
uc
Associating a procedure with test object enables you to use the procedure whenever
e
ar
_______________________________________________________________
P
You can create a library file using standard text editor or FUNCTION LIBRARY editor.
_______________________________________________________________
Exercise introduction
Students modify the NewProcedure test to calculate the number of current itineraries.
Specific objectives
At the end of this exercise, students should be able to:
- Create subroutines and functions to simplify code for easier readability and maintenance.
- Create and associate a functional library file to make functions accessible to multiple QuickTest scripts.
Technical setup
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
student computer:
-- Students are provided with a base test, NewProcedure to begin the exercise.
-- The NewProcedureSolution test and the LibraryFile library file provide a sample solution.
n
In this exercise, you test a new procedure and library file. You then update a script to use
io
at
the new procedure.
lic
up
The exercise consists of the following parts:
rD
• Part 1: Analyze the requirements. Fo
ot
Instructor Notes
-N
The instructor should reconvene the class after this point to discuss the answers.
n
io
• Part 3: Create and associate a new library file by using the FUNCTION LIBRARY
Ed
editor.
e
ar
ftw
So
P
H
The itinerary page of the Mercury Tours application includes dynamic objects to display
the complete list of flights booked by the agent.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The new procedure should be a function because it should return a value. _____
No _____________________________________________________________
3. What assumptions does the new procedure make about the state of the application
under test?
The new procedure will assume that the application under test is running and open
to the itinerary page. _______________________________________________
5. Write the VBScript code to create the desired new procedure. Name the procedure
n
as GetCurrentItineraryCount.
io
at
lic
Function GetCurrentItineraryCount
up
Dim objCheckboxDesc, objCheckboxes
rD
Set objCheckboxDesc = Description.Create()
Fo
objCheckboxDesc("type").Value = "checkbox"
ot
-N
Tours").ChildObjects(objCheckboxDesc).Count
at
uc
_______________________________________________________________
e
ar
ftw
_______________________________________________________________
So
_______________________________________________________________
P
H
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
Mark the new procedure as public to call the new procedure outside the library file.
_______________________________________________________________
2. Type the GetCurrentItineraryCount procedure into the test with the code that
you wrote in Part 1.
n
io
3. Update the test so that the procedure is called in the appropriate places.
at
lic
4. Run and debug the test.
up
rD
Part 3: Create and Associate a New Library File by Using the
Fo
Function Library Editor
ot
-N
a) From the QuickTest Professional menu bar, select FILE → NEW → FUNCTION
io
at
LIBRARY.
uc
Ed
a) With the NEWPROCEDURE test open, from the QuickTest Professional menu
bar, select FILE → OPEN → FUNCTION LIBRARY and select the
MYLIBRARYFILE.QFL file created in the previous step.
If the test does not complete successfully, use the QuickTest Professional debug features
to help identify the trouble areas in the script.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
Purpose
up
rD
This lesson discusses the techniques for managing QuickTest Professional exceptions programmatically. The lesson
also discusses the test cases for negative and positive test data.
Fo
ot
-N
n
io
Objectives
at
uc
10-1
Handling QuickTest Exceptions
Overview of Exceptions
n
io
at
lic
up
rD
Fo
ot
Unexpected events, errors, and application crashes during a test run can disrupt tests and
io
distort test results. For example, during testing, an application error could occur. This
at
uc
error does not permit the automated test to navigate to the feature, screen, or module that
Ed
needs to be tested. Such errors present a problem particularly when running tests
unattended. The test is suspended until you perform the action needed to recover. These
e
ar
• STOP: Stops the run session. The test results display that the script was not
completed.
• RETRY: Attempts to perform the step again. If the step succeeds, the test run
continues.
• SKIP: Skips the step that caused the exception and continues the test run from the
next step.
• DEBUG: Pauses the test run, enabling you to review variable values or step through
the script one line at a time.
n
io
at
lic
up
rD
Fo
Figure 10-2 Positive and Negative Test Data
ot
As a tester, you test with positive and negative data to ensure that the AUT responds
-N
correctly to both types of data. For example, to test login functionality, you test the
n
application with a correct set of user name and password, which is positive data. You
io
at
also check that the application denies login and generates a specific exception message
uc
if you use an incorrect set of user name and password, which is negative data.
Ed
Negative data causes an AUT to generate an error message. While enhancing a positive
e
ar
test case to validate the application for negative data, it is common for QuickTest
ftw
Professional to encounter exceptions. Exception handling ensures that the test runs
So
without exception.
P
You can work with both negative and positive data in two ways:
H
- Create a separate test for both positive and negative test data.
- Create a test that can understand that the expected result of positive data is not an error message, and the expected
result of negative data is an error message.
• It enables a script to handle exceptions and ensures that the test runs to completion.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
RECOVERY SCENARIO WIZARD, which guides you through the process of defining a
at
• TRIGGER: Interrupts the run session of the test. For example, the test may be
So
• RECOVERY: Enables the test to run continuously. For example, you can instruct
QuickTest Professional to click a button in an error pop-up window to close the
window.
Note: You use recovery scenarios for unpredictable events or events that you cannot
synchronize with a specific step in your test.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
The types of recovery scenarios are defined by the type of triggers. These triggers are
ftw
• OBJECT STATE: QuickTest Professional detects a specific test object state and
identifies it according to the property values of the object and all the objects in the
hierarchy.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
It is possible that you may be unable to predict where an exception could occur in a
ftw
script. In such cases, including exception handling statements in the script is not useful.
So
P
For these cases you use recovery scenarios to identify and handle unpredictable
H
exceptions. Define a recovery scenario by using TEST RUN ERROR as the trigger event.
Note: Recovery scenarios are not useful for negative test data. Use recovery scenarios
when you do not have any details about the possible exceptions in a script. With
negative test data, you know precisely where an exception will occur.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
The RECOVERY tab of the TEST SETTINGS dialog box displays a list of all recovery
ftw
scenarios associated with the current test. You can associate additional recovery
So
scenarios with a test, remove recovery scenarios from the test, change the order in which
they are applied to a run session, and view a read-only summary of each recovery
P
H
• Conditional statements.
• Exit statements.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
n
io
at
lic
up
rD
Fo
ot
Figure 10-7 shows how conditional statements separate the code to be executed for
n
io
positive or negative test data. The code between the Then and ELSE statements is
at
executed only for negative test data. The code between the ELSE and End If statements
uc
is executed only for positive test data. All the code outside the If ... End If
Ed
Note: Positive and negative test data are covered later in this lesson.
So
P
H
n
io
at
lic
up
rD
Fo
ot
If a test has multiple steps to be executed for positive test data and only a few steps for
n
io
negative test data, you can use an Exit statement to terminate a process for negative test
at
data.
uc
Ed
Figure 10-8 shows how to use conditional statements to identify negative test data. The
e
code uses an ExitGlobalIteration statement so that the remainder of the code in this
ar
ftw
action, and the remaining actions in the test are not executed for negative cases. The
remaining code and follow-on actions are executed for positive test data.
So
P
n
io
at
lic
up
rD
Fo
ot
Figure 10-9 shows how to search for a specified item in a WINLIST object. The figure
uc
• The block of code on the left uses the Exit statement to terminate the DO ... WHILE
ar
• The block of code on the right is similar to that on the left, except that the context is
P
within a function. The Exit statement helps to immediately return from the function
H
n
io
iteration (if any). the next iteration (if any).
at
lic
ExitAction ExitComponent
up
rD
Terminates the current Terminates the current
action regardless of the Fo component regardless of
existence of additional the existence of additional
ot
ExitGlobalIteration ExitTestIteration
Ed
n
io
The VBScript On Error Resume Next statement enables a script to continue processing
at
even after an exception occurs. When a script encounters an exception, it simply ignores
lic
the current line and proceeds to the next line.
up
rD
Use the On Error Resume Next statement to enable cleanup code to run entirely, even
Fo
if exceptions occur.
ot
-N
In Figure 10-10, the example on the left shows how to use the On Error Resume Next
statement to complete the execution of cleanup code even if exceptions occur. The
n
io
example on the right shows how you can include custom exception handling by having
at
Note: The On Error Resume Next statement skips all the exceptions in a test including
e
Summary
In this lesson, you learned how to:
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
Summary 10-15
Handling QuickTest Exceptions
Review Questions
Now answer these review questions.
1. What two methods can you use to handle exceptions in QuickTest Professional?
_______________________________________________________________
Exception handling enables you to handle exceptions in a test and ensure that the
n
test runs successfully. It also enables you to test positive and negative test data.
io
at
_______________________________________________________________
lic
up
3. What statement can be used to terminate a process if a test has multiple steps to be
rD
executed for positive test data and only a few steps for negative test data?
Fo
ot
You can use an Exit statement to terminate a process if a test has multiple steps to
-N
be executed for positive test data and only a few steps for negative test data. __
n
io
_______________________________________________________________
at
uc
_______________________________________________________________
P
H
Exercise introduction
Students modify the failing ValidateLogin test so that it validates both positive and negative test cases.
The base test requires the Web add-in.
Specific objectives
At the end of this exercise, students should be able to:
- Create tests that perform different checks depending on the test data.
Note: The analyses of the exercise will provide discussions of key challenges of the problem and ideas for a solution, but the
students need to write the actual code independently.
Technical setup
n
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
io
student computer:
at
-- Students are provided with a base test, ValidateLogin, to begin the exercise.
lic
-- The NegativePositive test provides sample solution.
up
rD
In this exercise, you edit a script that validates positive and negative test data.
Fo
The exercise consists of the following parts:
ot
-N
• Imports a list of user names and passwords from an external Microsoft Excel
worksheet.
• Tests whether the application under test logins for the correct set of user names and
passwords, and generates an appropriate error message for the incorrect set of user
names and passwords.
If you try to run the script, you see that an exception occurs.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The exceptions occur because some user names and passwords in the imported
Microsoft Excel sheet are incorrect, for these the application does not login.
n
io
at
lic
up
rD
Fo
Figure 10-12 Data Set with User Names and Passwords
ot
If the user name or the password is invalid, you need to update the script to ensure that
-N
the script:
n
io
•
at
Confirms that the proper error message is displayed and dismisses the exception.
uc
•
Ed
Which action or actions in the VALIDATELOGIN script do you need to update and why?
ftw
So
Update the VALIDATELOGIN action to pick user name and password from DATA
TABLE and insert it into the application under test. _______________________
P
H
_______________________________________________________________
2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYVALIDATELOGIN.
n
io
at
lic
up
rD
Fo
ot
-N
If your test does not complete successfully, use the QuickTest Professional debug
io
at
Exercise introduction
Students modify the failing ExceptionHandling test so that it handles exceptions programmatically.
This test uses the Web add-in.
Specific objectives
At the end of this exercise, students should be able to:
- Create tests that perform different checks depending on the test data.
Note: The analyses of the exercise will provide discussions of key challenges of the problem and ideas for a solution, but the
actual code will be left to students to write independently.
Technical setup
n
In addition to the general requirements listed in the Course Overview, this exercise has the following requirements for each
io
student computer:
at
-- Students are provided with a base test, ExceptionHandling, to begin the exercise.
lic
-- The ExceptionHandlingSolution1 and ExceptionHandlingSolution2 tests provide sample solutions. The NoTomatoCans test
up
uses a condition to intercept negative cases followed by an ExitAction statement. The NatKingCole test uses the On
rD
Error Resume Next statement to skip to an exception handling the IF ... THEN statement when an error occurs.
Fo
In this exercise, you update the script so that it handles run errors programmatically.
ot
-N
• Imports a list of departure and arrival cities from a Microsoft Excel worksheet.
Note: For the purpose of this exercise, the EXCEPTIONHANDLING script uses just the first
three departure cities and last three arrival cities instead of the complete lists of cities.
This reduces the number of the combinations and the time needed to run the script.
If you try to run the script, you see that an exception occurs.
n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H
The exceptions occur because some of the cities in the Microsoft Excel worksheet are
retired airports,where the airlines no longer fly. The application does not offer the option
to fly to or from these retired airports. This is the correct behavior expected of the
application.
n
io
at
lic
up
rD
Fo
Figure 10-15 Data Set with Current and Retired Cities
ot
If either the departure or the arrival city is invalid, you need to update the script to
-N
•
at
Confirms that the retired city is not among the options offered in the application.
uc
•
Ed
and why?
So
Update the PURCHASEFLIGHT action to check that retired cities are not among the
P
the PURCHASEFLIGHTS DATA TABLE indicate when a retired city is used. _____
_______________________________________________________________
_______________________________________________________________
To handle exceptions, you can wrap the whole action in an If ... Then ... Else
statement, or intercept the negative cases and use the ExitActionIteration
statement, or use the On Error Resume Next statement to skip to the next
statement. _______________________________________________________
_______________________________________________________________
_______________________________________________________________
_______________________________________________________________
2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYEXCEPTIONHANDLING.
n
io
at
4. Run and debug the updated test.
lic
up
Confirm in your test results that the PURCHASEFLIGHT action performed different
rD
checks depending on whether or not any cities were retired.
Fo
ot
-N
If your test does not complete successfully, use the QuickTest Professional debug
n
On-line
Through a Resource Coordinator
Someone else registered me
n
io
at
2. How much do you agree with the following statements regarding the registration process
lic
up
and facility? (Please circle only one rating for each category):
rD
Strongly Fo Strongly
Agree Neutral Disagree N/A
Agree Disagree
ot
4. If there was CBT, WBT or online pre-work that was to be completed before class, did you
H
complete it?
Very helpful Somewhat helpful I’m not sure Not very helpful Not helpful at all
5 4 3 2 1
6. How would you rate your technical ability going into the class?
5 - Highly technical
4 - Above average
3 - Average
2 - Below average
1 - Not at all technical
n
io
at
7. How would you rate your familiarity with the product going into the class?
lic
up
rD
5 - I consider myself a product expert
Fo
4 - I have above average knowledge of the
ot
product
-N
functions
io
at
8. How much do you agree with the following statements regarding the course content and
So
materials?
P
Strongly Strongly
H
Strongly Strongly
Agree Neutral Disagree
Agree Disagree
The instructor had a thorough knowledge of the 5 4 3 2 1
course content.
The instructor encouraged participation from stu- 5 4 3 2 1
dents.
The instructor was an effective communicator. 5 4 3 2 1
The instructor conducted the class at an appropriate 5 4 3 2 1
pace.
The instructor made the course relevant by using real- 5 4 3 2 1
world examples.
I would recommend this instructor to others. 5 4 3 2 1
n
11. What suggestions do you have for the instructor?
io
at
lic
up
rD
12. How would you rate your overall experience with this class?
Fo
Excellent Good OK Needs Improvement Poor
ot
-N
5 4 3 2 1
n
io
I understood the
Ed
I understood the
course concepts, I understood the
course concepts, I understood some
e
with others
5 4 3 2 1
P
H
14. What recommendations do you have to improve the overall effectiveness of this course?
15. What other courses would you like to see offered by HP Software Global Training?
16. If you have any other comments, please enter them below. If you would like to be contacted
regarding your comments, please include your name and contact information.
H
P
So
ftw
ar
e
Ed
uc
at
io
n
-N
ot
Fo
rD
up
lic
at
io
n
QTP92Adv-Instruct-01B
H
P
So
ftw
ar
e
Ed
uc
at
io
n
-N
ot
Fo
rD
up
lic
at
io
n