Anda di halaman 1dari 249

Advanced QuickTest Professional 9.

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

Introduction to Expert View ...................................................................................................1


An Overview of Expert View ..............................................................................................2
Using Expert View...............................................................................................................3
Translating Steps Between Views .......................................................................................4
An Overview of VBScript ...................................................................................................5

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

Guidelines for VBScript Syntax ........................................................................................12


-N

More Guidelines for VBScript Syntax...............................................................................13


n

Discussion: Match the Steps from the Views ....................................................................14


io
at

Discussion: Write the VBScript Code ...............................................................................15


uc

Summary............................................................................................................................16
Ed

Review Questions ..............................................................................................................17


e
ar
ftw

Using Expert View ...................................................................................................................1


So

Adding New Steps in Expert View......................................................................................2


P

Categories in the Step Generator .........................................................................................3


H

Defining a Step ....................................................................................................................4


Inserting a Step Manually ....................................................................................................5
Using Statement Completion ...............................................................................................6
Expanding VBScript Syntax ................................................................................................7
Launching Context-Sensitive Help ......................................................................................8
An Overview of the With Statement....................................................................................9
Applying the With Statement to a Test..............................................................................10
Using Debugging Features.................................................................................................11
Finding Syntax Errors ........................................................................................................12
Executing a Script from a Specific Step ............................................................................13
Adding Breakpoints ...........................................................................................................14
Executing Single Steps ......................................................................................................15
Summary............................................................................................................................16
Review Questions ..............................................................................................................17
Exercise: Using Expert View.............................................................................................18

Working with Object Properties ............................................................................................1


Retrieving Object Property Values ......................................................................................2
Run-Time Object Properties Versus Test Object Properties ...............................................3
Retrieving the Property Values............................................................................................4
Identifying a Property ..........................................................................................................5
Calling GetROProperty or GetTOProperty .........................................................................6
Setting Object Properties: Calling SetTOProperty ..............................................................7
An Overview of Constants and Variables............................................................................8
Declaring Constants and Variables......................................................................................9

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

Review Questions ..............................................................................................................16


-N

Exercise: Working with Object Properties ........................................................................17


n
io
at
uc

Working with Dynamic Objects .............................................................................................1


Ed

Dynamic Objects Versus Static Objects ..............................................................................2


Review: Object Repository for Static Objects .....................................................................3
e
ar

Identifying Dynamic Objects...............................................................................................4


ftw

Setting Dynamic Values in the Object Repository ..............................................................5


So

Using Programmatic Descriptions .......................................................................................6


P

Building Programmatic Descriptions...................................................................................7


H

Identifying the Object Class ................................................................................................8


Selecting Object Properties..................................................................................................9
Creating a Programmatic Description................................................................................10
Specifying Property and Value Pairs .................................................................................11
Using the Description Object.............................................................................................13
Retrieving Child Objects ...................................................................................................14
Additional Uses of Programmatic Descriptions ................................................................15
Summary............................................................................................................................16
Review Questions ..............................................................................................................17
Exercise: Working with Dynamic Objects ........................................................................18
Using VBScript Operators, Statements and Functions ........................................................1
Introducing VBScript Operators, Statements and Functions...............................................2
Commonly Used VBScript Operators .................................................................................3
Comparison Operators .........................................................................................................4
Arithmetic Operators ...........................................................................................................5
Logical Operators ................................................................................................................6
Evaluating Operator Precedence..........................................................................................8
Discussion: Value of Expressions........................................................................................9
Commonly Used VBScript Statements..............................................................................10
Using Statements for Commenting....................................................................................11
Commenting Multiple Lines ..............................................................................................12
Using the Indent Outdent Feature ......................................................................................13
Using the Set Statement .....................................................................................................14
Using Statements for Conditional Logic ...........................................................................15

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

Manipulating Dates with Functions ...................................................................................22


-N

Converting Data Types with Functions .............................................................................23


n

Discussion: Value of Each Expression ..............................................................................24


io
at

Functions for Opening Dialog Boxes ................................................................................25


uc

Summary............................................................................................................................26
Ed

Review Questions ..............................................................................................................27


Exercise: Using VBScript Operators, Statements and Functions ......................................28
e
ar
ftw
So

Working with Dynamic Data ..................................................................................................1


P

Dynamic Data Versus Static Data .......................................................................................2


H

Retrieving Data from Objects ..............................................................................................3


The WinComboBox and WinList Objects...........................................................................4
The WebList Object.............................................................................................................5
The WebTable Object ..........................................................................................................6
Overviewing Looping Statements .......................................................................................7
Using the For...Next Statement............................................................................................8
Using the While...Wend Statement......................................................................................9
Using the Do...Loop Statement..........................................................................................10
Using the Continuation and Termination Conditions ........................................................11
Evaluation at the Start Versus at the End ..........................................................................12
An Overview of Nested Loops ..........................................................................................13
Review: Using a Data Table to Manage Iterations ............................................................14
Populating a Data Table Dynamically ...............................................................................15
Commonly Used Data Table Methods...............................................................................16
Summary............................................................................................................................18
Review Questions ..............................................................................................................19
Exercise: Working with Dynamic Data .............................................................................20

Retrieving External Data ........................................................................................................1


Using External Data Sources ...............................................................................................2
Importing and Exporting Data from Microsoft Excel .........................................................3
Using the DataTable.ImportSheet Method ..........................................................................4
Using the DataTable.ExportSheet Method ..........................................................................5
Working with Databases ......................................................................................................6
Introduction to ActiveX Data Objects (ADO) .....................................................................7

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

Writing to a File .................................................................................................................14


-N

Summary............................................................................................................................15
n

Review Questions ..............................................................................................................16


io
at

Exercise: Retrieving External Data....................................................................................17


uc
Ed

Creating New Procedures .......................................................................................................1


e
ar

An Introduction to Procedures .............................................................................................2


ftw

Comparing Subroutines and Functions................................................................................3


So

Understanding the Subroutine Syntax .................................................................................4


P

Understanding the Function Syntax.....................................................................................5


H

Creating a New Procedure ...................................................................................................6


Adding the Base Steps for a New Procedure .......................................................................7
Declaring the Procedure.......................................................................................................8
Defining an Argument .........................................................................................................9
Setting Return Values ........................................................................................................10
Handling Errors..................................................................................................................11
Making a Procedure Available ..........................................................................................12
Using a Procedure Locally.................................................................................................13
Associating a Procedure with a Test Object ......................................................................14
Registering a Procedure with an Object Class...................................................................15
Overriding an Existing Object Method..............................................................................16
Using the Function Definition Generator ..........................................................................17
Unregistering a Procedure .................................................................................................18
Building a Library..............................................................................................................19
Creating a Library File Using a Standard Text Editor.......................................................20
Opening the Function Library Editor.................................................................................21
Associating a Library.........................................................................................................22
Associating a Function Library with a Test.......................................................................23
Using a Procedure ..............................................................................................................24
Using a Procedure in a Script ............................................................................................25
Using a Procedure in a Recovery Scenario........................................................................26
Requirements for Recovery Scenario Procedures..............................................................27
Summary............................................................................................................................28
Review Questions ..............................................................................................................29
Exercise: Creating New Procedures ..................................................................................30

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

Types of Recovery Scenarios ..............................................................................................6


-N

Using Recovery Scenarios for Exception Handling ............................................................7


n

Viewing the Recovery Scenarios for a Test.........................................................................8


io
at

Handling Exceptions Programmatically ..............................................................................9


uc

Using Conditional Statements ...........................................................................................10


Ed

Using Exit Statements........................................................................................................11


VBScript Exit Statements ..................................................................................................12
e
ar

The Exit Statements ...........................................................................................................13


ftw

Using the On Error Resume Next Statement .....................................................................14


So

Summary............................................................................................................................15
P

Review Questions ..............................................................................................................16


H

Exercise: Handling Negative and Positive Test Data ........................................................17


Exercise: Handling Exceptions Programmatically ............................................................21
H
P
So
ftw
ar
e
Ed
uc
at
io
n
-N
ot
Fo
rD
up
lic
at
io
n
Introduction

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

use the advanced features of QuickTest Professional 9.2.


at
uc
Ed
e
ar
ftw
So
P
H

1-1
Introduction

Course Objectives
After completing this course, you will be able to:

• Identify when EXPERT VIEW is useful.

• Explain how VBScript and Object Oriented Programming (OOP) is relevant to


QuickTest Professional.

• Translate steps between KEYWORD VIEW and EXPERT VIEW.

• Enter steps in EXPERT VIEW.

• Retrieve and use the properties of an object.

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

• Retrieve data from application objects.


-N
n

• Describe and use various VBScript looping statements.


io
at


uc

Use the DATA TABLE object to store run-time data and drive actions.
Ed

• Create scripts that access data from external sources.


e
ar


ftw

Create new subroutines and functions.


So

• Create and associate a library of functions.


P
H

• Use the FUNCTION LIBRARY editor.

• Identify when to handle exceptions programmatically.

1-2 Course Objectives


Introduction

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.

This course covers the following lessons:

• Lesson 1: Introduction
 This lesson introduces the structure of the course and sample test applications present in Mercury QuickTest
Professional.

• Lesson 2: Introduction to Expert View

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

Lesson 4: Retrieving Object Properties



-N

This lesson covers the skills and knowledge needed to retrieve object properties and use that information in
scripts.
n
io


at

Lesson 5: Working with Dynamic Objects


uc

This lesson explains how to use programmatic descriptions for dynamic objects in QuickTest scripts.
Ed

• Lesson 6: Using VBScript Operators, Statements, and Functions


e
ar

This lesson explains how to use VBScript operators, statements, and functions. It covers the functionality of
ftw

the VBScript language.


So

• Lesson 7: Working with Dynamic Data


P


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.

• Lesson 8: Retrieving External Data


 This lesson covers the steps for retrieving data from external data sources, such as Microsoft Excel,
databases, and text files.

Course Outline 1-3


Introduction

• Lesson 9: Creating New Procedures


 This lesson covers the creation of new procedures. The lesson also covers the various contexts where new
procedures can be defined.

• Lesson 10: Handling QuickTest Exceptions


 This lesson discusses the techniques for managing QuickTest Professional exceptions programmatically. The
lesson also discusses the test cases for negative and positive test data.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

1-4 Course Outline


Introduction

Instructional Methods
• Slides and lecture: Slides will be used to explain course concepts.

• Discussions/Review questions: Discussions and review questions will be


distributed throughout the course, to help you understand QuickTest Professional
concepts and nuances.

• 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

Instructional Methods 1-5


Introduction

Class Introductions
• Your name

• Your company

• Your job

• How you have used QuickTest Professional

• Your personal objectives

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

1-6 Class Introductions


Introduction

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

of the following ways:


uc

-- 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.

Class Introductions 1-7


Introduction

Sample Test Applications

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 0-1 Mercury Tours and Flight Reservation


e
ar

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

and the Flight Reservation Windows application.


P
H

You may use TRAINING as the user name and MERCURY as the password to login to both
applications.

1-8 Sample Test Applications


Introduction to Expert View

Introduction to Expert View


2

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

After completing this lesson, you will be able to:


io
at


uc

Identify the advantages of EXPERT VIEW.


Ed

• Translate steps between KEYWORD VIEW and EXPERT VIEW.


e
ar


ftw

Explain how VBScript and Object Oriented Programming are relevant to QuickTest
So

Professional.
P

• List common test objects and methods used in QuickTest Professional.


H

2-1
Introduction to Expert View

An Overview of Expert View

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 2-1 Expert View


at
uc

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

2-2 An Overview of Expert View


Introduction to Expert View

Using Expert View


EXPERT VIEW enables you to build tests and components that:

• Retrieve run-time properties from objects.

• Perform comparisons and computations on objects.

• Execute steps depending on dynamic information.

• Retrieve data from external sources.


All techniques covered in this course apply to both tests and scripted components.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

Using Expert View 2-3


Introduction to Expert View

Translating Steps Between Views

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

• An icon-based table displays the information about each step or component.


uc
Ed

• The hierarchy from parent objects to child objects is shown in sequential rows.
e
ar

In EXPERT VIEW:
ftw
So

• Each step is a single line of VBScript code.


P
H

• The dot character separates parent and child objects.

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 logical name of the browser: “WELCOME: MERCURY TOURS”.

• The logical name of the home page: “WELCOME: MERCURY TOURS”.

• The class and logical name of the object on the page: WEBEDIT(“USERNAME”).

• The name of the method performed on this WEBEDIT object: SET.

2-4 Translating Steps Between Views


Introduction to Expert View

An Overview of VBScript
VBScript is a programming language developed by Microsoft. It is a lightweight version
of the Visual Basic programming language.

The characteristics of VBScript are that:

• It is a scripting language.

• Its code is interpreted at run-time rather than at compile-time.

• It is an Object Oriented Programming (OOP) language.


OOP is discussed later in this lesson.

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

An Overview of VBScript 2-5


Introduction to Expert View

An Overview of Object Oriented Programming


OOP is a programming approach based on a hierarchy of objects and classes.

An object consists of:

• Data that describes the object.

• Functions that can be performed on the object.

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

QuickTest Professional is object-oriented. QuickTest objects are categorized by class.


Each class in QuickTest defines the properties and methods available to its objects. Each
n
io

object contains the actual values for the properties.


at
uc
Ed
e
ar
ftw
So
P
H

2-6 An Overview of Object Oriented Programming


Introduction to Expert View

Objects in QuickTest

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 2-3 Object Repository


e
ar

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

The OBJECT REPOSITORY displays the following:


P
H

• The logical name of an object

• The class of an object

• The properties of an object, including the current property values

Figure 2-3 shows the logical name, class, and properties of the object password.

Objects in QuickTest 2-7


Introduction to Expert View

Classes in QuickTest

n
io
at
lic
up
rD
Fo
ot
-N

Figure 2-4 Object Model Reference


n
io

The types of objects that QuickTest can recognize and work on are set by the following
at

default classes defined in QuickTest:


uc
Ed

• 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.

2-8 Classes in QuickTest


Introduction to Expert View

Common Windows and Web Objects


Table 2-1 lists some common Windows and Web objects in QuickTest. The objects are
represented as icons, which in turn, represent the respective classes in KEYWORD VIEW.

Windows Objects Web Objects


Common Display WINDOWS BROWSER
Objects
DIALOG PAGE

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

Table 2-1. Common Windows and Web Objects


e
ar
ftw
So
P
H

Common Windows and Web Objects 2-9


Introduction to Expert View

Common Methods in QuickTest

n
io
at
lic
up
rD
Fo
ot
-N

Figure 2-5 Steps in Expert View


n
io

Several interactive objects in Windows and Web applications share the following
at

common methods:
uc
Ed

• SET: Sets the value provided to the edit box.


e
ar

• SETSECURE: Decrypts a provided encrypted value.


ftw
So

• SELECT: Selects an item from a list box or combo box.


P
H

• TYPE: Enters the supplied keyboard characters into an object.

• CLICK: Executes a mouse-click on an object.

• 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.

• EXIST: Checks that an object is in the AUT.

• WAITPROPERTY: Pauses the test while an application process completes, before


moving on to the next step.

2-10 Common Methods in QuickTest


Introduction to Expert View

Elements of a QuickTest Script

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 2-6 QuickTest Script


e
ar

To view the elements of a QuickTest script, open a test or component in EXPERT VIEW.
ftw

The elements of a QuickTest test or component may be comprised of:


So

• Calls to methods in QuickTest objects: These may be application objects or utility


P
H

objects. Figure 2-6 shows calls to test objects and to the Reporter utility object.

• Other VBScript code: These may be VBScript operators, statements, or functions.


Figure 2-6 shows variable declaration statements (Dim) and assignments (=
operator).

Elements of a QuickTest Script 2-11


Introduction to Expert View

Guidelines for VBScript Syntax


All lines of a QuickTest script must adhere to the VBScript syntax. The following are
some rules and guidelines for VBScript:

• Use quotation marks to enclose text strings.

Example

• Use a dot to access child objects for an object.

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

the two. However, use consistent casing for easy readability.


uc
Ed
e
ar

Example
ftw
So
P
H

2-12 Guidelines for VBScript Syntax


Introduction to Expert View

More Guidelines for VBScript Syntax


The following are some more rules and guidelines for VBScript:

• 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

• Use a colon to combine multiple statements onto the same line.


Ed
e
ar
ftw

Example
So
P
H

More Guidelines for VBScript Syntax 2-13


Introduction to Expert View

Discussion: Match the Steps from the Views

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 2-7 Test Steps


e
ar

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

mouse click reveals the suggested answer.

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.

2-14 Discussion: Match the Steps from the Views


Introduction to Expert View

Discussion: Write the VBScript Code

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("Agent Name:").Set "training"_____________


-N

Dialog("Login").WinEdit("Agent Name:").Type micTab_______________


n
io

Dialog("Login").WinEdit("Password:"). _
at
uc

SetSecure "4291f98e3c01c6a5b1d224577e28909ee31c41cd"______________
Ed

Dialog("Login").WinButton("OK").Click_____________________________
e
ar
ftw

What does this code do?


So
P
H

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.

The EXPERT VIEW code is provided.


This code automates the log in to an application.
The code enters an agent name in the LOGIN dialog box, shifts to the next field, enters a password that is securely shown in
encrypted form within QuickTest Professional, and clicks OK.

Discussion: Write the VBScript Code 2-15


Introduction to Expert View

Summary
In this lesson, you learned how to:

• Identify the advantages of EXPERT VIEW.

• Translate steps between KEYWORD VIEW and EXPERT VIEW.

• 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.

1. Why do you use EXPERT VIEW?

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

OOP is a programming approach based on a hierarchy of objects and classes.


n
io

QuickTest objects are categorized by class. Each class in QuickTest Professional


at

defines the properties and methods available to its objects. Therefore, QuickTest
uc

Professional follows the object-oriented programming approach.____________


Ed

_______________________________________________________________
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. ___________

Review Questions 2-17


Introduction to Expert View

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

2-18 Review Questions


Using Expert View

Using Expert View


3

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

After completing this lesson, you will be able to:


io
at


uc

Use the STEP GENERATOR to create new steps in your tests.


Ed

• Enter steps manually in the EXPERT VIEW.


e
ar


ftw

Use VBScript With statement.


So

• Trace and debug tests and components.


P
H

3-1
Using Expert View

Adding New Steps in Expert View


To add a new step to a test or component in EXPERT VIEW, use any of the following
methods:

• Record steps on the Application Under Test (AUT).

• Use the ACTIVE SCREEN.

• Use the STEP GENERATOR.

• Type the steps directly into a test.


This lesson will briefly review STEP GENERATOR, and then cover how to type steps directly into a test.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

3-2 Adding New Steps in Expert View


Using Expert View

Categories in the Step Generator

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc

Figure 3-1 Step Generator Categories


Ed
e

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

Steps are organized according to the following three categories:


H

• 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.

• FUNCTIONS: Use this category to access general VBScript functions or other


functions that are defined at your company. This course discusses VBScript and
user defined functions in later lessons.

Categories in the Step Generator 3-3


Using Expert View

Defining a Step

n
io
at
lic
up
rD
Fo
ot

Figure 3-2 Completed Steps for Insertion


-N

To define a new step in STEP GENERATOR, complete the following fields:


n
io
at

• CATEGORY: Select the desired category.


uc
Ed

• OBJECT or LIBRARY: Select the desired test object or utility object. If the step
e

category is LIBRARY, select the desired library.


ar
ftw

• OPERATION: Select the desired object method or function.


So


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.

To define additional steps using the STEP GENERATOR:

1. Check the INSERT ANOTHER STEP check box.

2. Create the step.

3. Click INSERT to insert this step in the script.

3-4 Defining a Step


Using Expert View

Inserting a Step Manually


You can add steps directly to tests and components within EXPERT VIEW.

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

Inserting a Step Manually 3-5


Using Expert View

Using Statement Completion


The statement completion feature provides options to finish the current VBScript line.
This feature is useful in the following contexts:

Context Example

When you type a class


followed by a
parenthesis, QuickTest
uses an auto complete
list to display the test
objects in the OBJECT
REPOSITORY for that

n
io
class.

at
lic
up
When you type an

rD
object followed by a Fo
dot, QuickTest uses an
ot

auto complete list to


-N

display the child objects


and methods for that
n
io

object.
at
uc
Ed
e

When you type a


ar

method, QuickTest uses


ftw

an auto complete list to


So

display the arguments


P

for that method.


H

Table 3-1. Statement Completion

 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.

3-6 Using Statement Completion


Using Expert View

Expanding VBScript Syntax

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 3-3 Keyword Completion Options


at
uc

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.

Expanding VBScript Syntax 3-7


Using Expert View

Launching Context-Sensitive Help

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So

Figure 3-4 Context-Sensitive Help


P
H

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.

3-8 Launching Context-Sensitive Help


Using Expert View

An Overview of the With Statement

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

occurring on the same Web page.


n
io

Figure 3-5 shows two code snippets that perform the same operations. The second code
at

snippet uses the With statement to group steps.


uc
Ed
e
ar
ftw
So
P
H

An Overview of the With Statement 3-9


Using Expert View

Applying the With Statement to a Test

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at

Figure 3-6 Edit Menu


uc
Ed

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

→ ADVANCED → APPLY “WITH” TO SCRIPT.


ftw
So

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.

3-10 Applying the With Statement to a Test


Using Expert View

Using Debugging Features


After you create the script for your test or component, you need to debug the script to
ensure that it is free of errors.

QuickTest Professional provides debugging features that help you:

• Locate syntax errors: Enables you to verify that the script adheres to VBScript
rules.

• Execute a script from a specific step: Facilitates working in a long script by


enabling you to skip to the code that you want to test.

• Add breakpoints: Enables you to pause a run session at a desired step.

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

Using Debugging Features 3-11


Using Expert View

Finding Syntax Errors

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

the description of the error is: EXPECTED 'END IF'.


P
H

• 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.

3-12 Finding Syntax Errors


Using Expert View

Executing a Script from a Specific Step

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at

Figure 3-8 Run from Step Option


uc
Ed

The RUN FROM STEP option enables you to execute a QuickTest script starting from any
e

step in the script.


ar
ftw

To use this option, place the cursor at the desired starting step and from the Quick Test
So

Professional menu bar, select AUTOMATION → RUN FROM STEP.


P
H

Note: You may need to manually navigate the AUT to the state expected by the step in
your script.

Executing a Script from a Specific Step 3-13


Using Expert View

Adding Breakpoints

n
io
at
lic
up
rD
Fo
ot
-N

Figure 3-9 Breakpoints


n
io

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

2. From the QuickTest Professional menu bar, select DEBUG → INSERT/REMOVE


ftw

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.

3-14 Adding Breakpoints


Using Expert View

Executing Single Steps

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 3-10 Step Commands


at
uc

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

The available step commands are:


P
H

• 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.

Executing Single Steps 3-15


Using Expert View

Summary
In this lesson, you learned how to:

• Use the STEP GENERATOR to create new steps in your tests.

• Enter steps manually in the EXPERT VIEW.

• Use VBScript With statement.

• Trace and debug tests and components.

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.

1. What are the three categories in the STEP GENERATOR?

The three categories of step in STEP GENERATOR are: TEST OBJECTS, UTILITY
OBJECTS, and FUNCTIONS. __________________________________________

_______________________________________________________________

2. What is the auto-expand VBScript syntax feature in the EXPERT VIEW?

The auto-expand VBScript syntax feature in EXPERT VIEW returns VBScript

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

Breakpoints enable you to suspend a run session at a predetermined point in the


script so that you can inspect the run-time state of your application. _________
e
ar
ftw

_______________________________________________________________
So
P
H

Review Questions 3-17


Using Expert View

Exercise: Using Expert View


Instructor Notes

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

• Part 3: Type new steps in the script.


n
io
at

• Part 4: Run the updated script.


uc
Ed
e
ar
ftw
So
P
H

3-18 Exercise: Using Expert View


Using Expert View

Part 1: Translate the Given Keyword View Steps into Expert


View Code

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

Browser("Welcome: Mercury Tours").Page("Find a Flight:


Mercury").WebList("passCount").Select "2" ______________________
n
io
at

_______________________________________________________________
uc
Ed

Browser("Welcome: Mercury Tours").Page("Find a Flight:


e

Mercury").WebList("fromPort").Select "London" __________________


ar
ftw

_______________________________________________________________
So

Browser("Welcome: Mercury Tours").Page("Find a Flight:


P
H

Mercury").WebList("toPort").Select "Sydney" ____________________

_______________________________________________________________

Browser("Welcome: Mercury Tours").Page("Find a Flight:


Mercury").WebRadioGroup("servClass").Select "Business" _________

_______________________________________________________________

Browser("Welcome: Mercury Tours").Page("Find a Flight:


Mercury").Image("findFlights").Click ___________________________

Exercise: Using Expert View 3-19


Using Expert View

_______________________________________________________________

Browser("Welcome: Mercury Tours").Page("Select a Flight:


Mercury").Image("reserveFlights").Click ________________________

_______________________________________________________________

Browser("Welcome: Mercury Tours").Page("Book a Flight:


Mercury").Image("buyFlights").Click ____________________________

_______________________________________________________________

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

3-20 Exercise: Using Expert View


Using Expert View

Part 2: Open and Run an Existing Script


1. Invoke QuickTest Professional.

2. In the QUICKTEST PROFESSIONAL - ADD-IN MANAGER dialog box, check the WEB
check box and click OK.

3. Open the LOGINLOGOUT test located in the C:\TRAINING\ADVANCED


QTP92\TESTS folder.

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

Figure 3-12 LoginLogout Test


e
ar

Select START → PROGRAMS → MERCURY TOURS → START SERVER to start the


ftw

4.
Apache Web server.
So
P

5. Verify that the START SERVER window displays the following line: Apache/1.3.17
H

<Win32> ApacheJServ/1.1.2 running...

6. Minimize the START SERVER window.

7. On the QuickTest Professional toolbar, click RUN to run the test. The RUN dialog
box appears.

Exercise: Using Expert View 3-21


Using Expert View

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

Figure 3-13 LoginLogout Results

You can compare your test results with Figure 3-13.

Part 3: Type New Steps in the Script


1. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
with the name USINGEXPERTVIEW.

2. In KEYWORD VIEW, create a new action named SEARCHFLIGHTS.

a) Click INSERT → CALL TO NEW ACTION. A new window opens.

b) Type SEARCHFLIGHTS as the name of the new action.

3-22 Exercise: Using Expert View


Using Expert View

c) Select the AT THE END OF THE TEST option.

d) Click OK.

3. Drag and drop the SEARCHFLIGHTS action so that it is the second action in the test
flow.

4. Associate your new action with the shared object repository:


C:/TRAINING/ADVANCED QTP92/OBJECTS/MERCURYTOURS.TSR

n
io
at
lic
up
rD
Fo
ot
-N
n

Figure 3-14 New SearchFlights Action


io
at
uc

5. In EXPERT VIEW, type the VBScript code that you wrote in Part1.
Ed

When you type BROWSER, what happens?


e
ar
ftw

The name, “Welcome: Mercury Tours”, fills automatically in EXPERT VIEW


So

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.

Part 4: Run the Updated Script


1. Close any open browser running the Mercury Tours application.

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.

Exercise: Using Expert View 3-23


Using Expert View

If your test did not complete successfully, use the QuickTest Professional debug
features to identify the problems in the script.

Note: Check with your instructor if problems persist.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

3-24 Exercise: Using Expert View


Working with Object Properties

Working with Object Properties


4

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

After completing this lesson, you will be able to:


Ed

• Retrieve the properties of an object during a test run.


e
ar
ftw

• Use constants and variables in scripts.


So

• Use the reporter utility object to report events to the test results.
P
H

4-1
Working with Object Properties

Retrieving Object Property Values


Retrieving the values of the properties of an object helps you in:

• Debugging: You suspect the value of a property is incorrect or is causing an


unwanted script behavior. In such a case, you can retrieve the value, report on it,
trace it in the debugger, and perform computations or comparisons on it.

• 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

4-2 Retrieving Object Property Values


Working with Object Properties

Run-Time Object Properties Versus Test Object


Properties

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e

Figure 4-1 Run-Time Objects and Test Objects


ar
ftw

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

identify run-time objects in your application.

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.

Run-Time Object Properties Versus Test Object Properties 4-3


Working with Object Properties

Retrieving the Property Values


To retrieve the value of a property from an object in your script:

1. Identify the desired property.

2. Call GetROProperty or GetTOProperty.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

4-4 Retrieving the Property Values


Working with Object Properties

Identifying a Property

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc

Figure 4-2 Object Spy and Properties Help


Ed

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

OBJECT SPY on the run-time object.


So

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.

Identifying a Property 4-5


Working with Object Properties

Calling GetROProperty or GetTOProperty


All QuickTest application objects support these two methods:

• GetROProperty: Retrieves the property values of run-time objects

• GetTOProperty: Retrieves the property values of test objects

The syntax of GetROProperty and GetTOProperty are:


<object>.GetROProperty(<property>)
<object>.GetTOProperty(<property>)

The following example shows how to use GetROProperty and GetTOProperty:

n
io
at
Example

lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

4-6 Calling GetROProperty or GetTOProperty


Working with Object Properties

Setting Object Properties: Calling


SetTOProperty
During a session, you can modify an object’s properties in the temporary version. These
changes do not affect the permanent values in the OBJECT REPOSITORY.

To modify or set the object properties, you call SetTOProperty.

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.

The syntax of SetTOProperty is:

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

description in the OBJECT REPOSITORY.


io
at
uc
Ed
e
ar
ftw
So
P
H

Setting Object Properties: Calling SetTOProperty 4-7


Working with Object Properties

An Overview of Constants and Variables


You can use two types of elements to store values and make your scripts easier to read
and maintain. These elements are:

• Constants: Store number and string values that do not change

• 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

4-8 An Overview of Constants and Variables


Working with Object Properties

Declaring Constants and Variables


You declare a constant by using a Const statement. At the time you declare a constant,
assign a value to the constant.

The following example shows how to use the Const statement:

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

VBScript Operators, Statements, and Functions.”


e

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

is to use a prefix that indicates the type of value to be stored.


P

The mic prefix stands for Mercury Interactive Corporation.


H

Declaring Constants and Variables 4-9


Working with Object Properties

Viewing the Run-Time Value of a Variable

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 4-3 Variables Tab


e
ar
ftw

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

VIEWER to display it.


H

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.

4-10 Viewing the Run-Time Value of a Variable


Working with Object Properties

Adding the Reporter Utility Object

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 4-4 ReportEvent and Test Results


So

You use the reporter utility object to report an event to the test results.
P
H

Adding the Reporter Utility Object 4-11


Working with Object Properties

Using the Reporter Utility Object


Use the ReportEvent method of the reporter object to report an event to the test results.

The syntax of the ReportEvent method is:


Reporter.ReportEvent EventStatus, ReportStepName, Details

– EventStatus is the status of the report step. The valid values for EventStatus are
the following constants: micPass, micFail, micDone, and micWarning.

– ReportStepName and Details are text strings.

The following example shows how to use the ReportEvent method:

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

Statements, and Functions.”


n
io
at
uc
Ed
e
ar
ftw
So
P
H

4-12 Using the Reporter Utility Object


Working with Object Properties

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.

The settings for the Filter property are:

• rfEnableAll: Displays all reported events in the test results.

• rfEnableErrorsAndWarnings: Displays events with a warning or fail status in the


test results.

• rfEnableErrorsOnly: Displays events with a fail status in the test results.

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

Filtering Events 4-13


Working with Object Properties

Discussion: Output in Results

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 4-5 ReportEvent and Filter


So

For each block of code in Figure 4-5, enter the output that would appear in test results.
P
H

Instructor Notes

The slide for this page is to be used for discussion.


Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer teaching.

First Code Block


A: The output is: pass1, fail1, done1, and warning1. There is no output after the filter is set to rDisableAll.

Second Code Block


A: The output is: fail3 and warning3.

Final Code Block


A: The output is: fail4.

4-14 Discussion: Output in Results


Working with Object Properties

Summary
In this lesson, you learned how to:

• Retrieve the properties of an object during a test run.

• Use constants and variables in scripts.

• 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.

1. What are the advantages of retrieving the values of an object’s properties?

Retrieving the values of the properties of an object helps in debugging, test result
reporting, and using custom checkpoint. _______________________________

_______________________________________________________________

2. What is the difference between a constant and a variable?

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

value of the enabled property of a button. ______________________________


n
io

_______________________________________________________________
at
uc
Ed
e
ar
ftw
So
P
H

4-16 Review Questions


Working with Object Properties

Exercise: Working with Object Properties


Instructor Notes

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

• Part 1: Open and run an existing script.


-N


n

Part 2: Determine the additional steps needed to update the script.


io
at


uc

Part 3: Type new steps in the script.


Ed

• Part 4: Run the updated script.


e
ar
ftw

Part 1: Open and Run an Existing Script


So

1. Invoke QuickTest Professional. Select the Web add-in.


P
H

2. From the C:\TRAINING\QTP92ADVANCED\TESTS folder, open the


OBJECTPROPERTIES test.

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.

Exercise: Working with Object Properties 4-17


Working with Object Properties

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at

Figure 4-6 The ObjectProperties Test


uc
Ed

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

AUT at the end of the session.

4-18 Exercise: Working with Object Properties


Working with Object Properties

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 4-7 Test Results


at
uc

How many times did each action run?


Ed
e

The LOGIN and EXIT actions ran once each. The FLIGHTORDER action ran nine
ar

times. __________________________________________________________
ftw
So

_______________________________________________________________
P
H

5. Close the TEST RESULTS window.

Part 2: Determine the Additional Steps Needed to Update the


Script
You are asked to update the script so that it retrieves the total price and order number
information for each flight booked. The information retrieved should be reported into
the test results.

Exercise: Working with Object Properties 4-19


Working with Object Properties

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 4-8 Flight Reservation


at
uc

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

How did you find your answer?


H

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.

Window(“Flight Reservation”).WinEdit(“Total:”) _________________

4-20 Exercise: Working with Object Properties


Working with Object Properties

Window(“Flight Reservation”).WinEdit(“Order No:”) ______________

2. Do you use GETROPROPERTY or GETTOPROPERTY to retrieve the desired


information? What is the name of the property you would retrieve? How did you
find your answer?

Use GetROProperty for run-time information. The property name is “TEXT”. To


find the answer, review properties in OBJECT REPOSITORY, or review properties in
HELP for WINEDIT objects.__________________________________________

_______________________________________________________________

_______________________________________________________________

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

Dim vTotalPrice, vOrderNumber __________________________________


P
H

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?

The Reporter.ReportEvent method._________________________________

Write the VBScript statements that report the values of the information you
retrieved.

Exercise: Working with Object Properties 4-21


Working with Object Properties

Reporter.ReportEvent micDone, “TotalPrice”, vTotalPrice ________

Reporter.ReportEvent micDone, “OrderNumber”, vOrderNumber ______

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:

‘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

Reporter.ReportEvent micDone, "TotalPrice", "The new itinerary's total price


-N

is " & vTotalPrice


Reporter.ReportEvent micDone, "OrderNumber", "The new itinerary's order
n
io

number is " & vOrderNumber


at
uc

Part 3: Type New Steps in the Script


Ed

From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
e

1.
ar

with the name MYOBJECTPROPERTIES.


ftw
So

2. From EXPERT VIEW, use the action list to select the FLIGHTORDER action for
editing.
P
H

4-22 Exercise: Working with Object Properties


Working with Object Properties

n
io
at
lic
up
rD
Fo
ot

Figure 4-9 Action Drop Down List


-N

3. Append the code to the existing script that you wrote in Part 2.
n
io
at

4. After appending the new code, save the updated script.


uc
Ed

Part 4: Run the Updated Script


e
ar

1. Close any open instances of the Flight Reservation application.


ftw
So

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.

Note: Check with your instructor if problems persist.

Exercise: Working with Object Properties 4-23


Working with Object Properties

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

4-24 Exercise: Working with Object Properties


Working with Dynamic Objects

Working with Dynamic Objects


5

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

After completing this lesson, you will be able to:


e
ar
ftw

• Set dynamic values of objects in the OBJECT REPOSITORY.


So

• Build a programmatic description for an object.


P
H

• Create and use a Description object.

• Identify additional uses of programmatic descriptions.

5-1
Working with Dynamic Objects

Dynamic Objects Versus Static Objects

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at

Figure 5-1 Dynamic Objects and Static Objects


uc
Ed

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

objects always exist in the same state in the application.


ftw
So

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.

5-2 Dynamic Objects Versus Static Objects


Working with Dynamic Objects

Review: Object Repository for Static Objects

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 5-2 Object Repository


So

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.

Review: Object Repository for Static Objects 5-3


Working with Dynamic Objects

Identifying Dynamic Objects


Use the following two methods to identify dynamic objects in a QuickTest script:

• 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

5-4 Identifying Dynamic Objects


Working with Dynamic Objects

Setting Dynamic Values in the Object


Repository

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 5-3 Properties in the Object Repository


at
uc

If an object is defined in the OBJECT REPOSITORY and has dynamic property values, you
Ed

can set its values by:


e
ar


ftw

Using regular expressions to match the dynamic property values that vary at run-
time.
So
P

• Using a parameter to match information stored in DATA TABLE.


H

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.

Setting Dynamic Values in the Object Repository 5-5


Working with Dynamic Objects

Using Programmatic Descriptions

n
io
at
lic
up
rD
Fo
ot
-N

Figure 5-4 Using Programmatic Descriptions


n
io
at

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

values is called a programmatic description.


ftw
So

You use programmatic descriptions to:


P
H

• Identify a dynamic object, including objects not defined in OBJECT REPOSITORY.

• Validate specific dynamic property values of a dynamic object: Figure 5-4 shows
the programmatic description of a checkbox for flight_92.

Programmatic descriptions enable QuickTest to bypass the OBJECT REPOSITORY. When


you use a programmatic description, supply one or more pairs of an object property and
the desired value of the object. QuickTest uses these object properties to identify the
desired object.

Note: You can use programmatic descriptions consistently in QuickTest without using
the OBJECT REPOSITORY.

5-6 Using Programmatic Descriptions


Working with Dynamic Objects

Building Programmatic Descriptions


The following are broad steps to build a programmatic description of an object:

1. Identify the object class.

2. Select object properties.

3. Create a programmatic description.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

Building Programmatic Descriptions 5-7


Working with Dynamic Objects

Identifying the Object Class

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 5-5 Using Object Spy to Identify the Object Class


So

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

and using the OBJECT SPY on the desired object.

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.

5-8 Identifying the Object Class


Working with Dynamic Objects

Selecting Object Properties

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 5-6 Object Properties in Object Spy


So

After you identify the object class, select the object properties that will be needed to
P

identify the object uniquely.


H

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.

Selecting Object Properties 5-9


Working with Dynamic Objects

Creating a Programmatic Description


You can create a programmatic description in the following ways:

• Specifying property and value pairs in place of a logical name.

• Using the Description object.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

5-10 Creating a Programmatic Description


Working with Dynamic Objects

Specifying Property and Value Pairs


The syntax of an object that uses a programmatic description is:
<class>("<property1>:=<value1>",... , "<propertyX>:=<valueX>")

Note: Do not insert any extra white space between the “<propertyX>:=<valueX>"
strings.

QuickTest evaluates valueX as a regular expression. ValueX is the value of propertyX.


If the value contains a special regular expression character, use the backslash (\)
character to instruct QuickTest to treat the special character as a literal character.

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.

Specifying Property and Value Pairs 5-11


Working with Dynamic Objects

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

5-12 Specifying Property and Value Pairs


Working with Dynamic Objects

Using the Description Object


The Description object enables you to specify multiple properties to uniquely identify a
dynamic object.

To use the Description object:

1. Create a Description object by using the following syntax:


Dim objDescription
Set objDescription = Description.Create()

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.

Using the Description Object 5-13


Working with Dynamic Objects

Retrieving Child Objects


The ChildObjects method is available for most QuickTest objects. This method
accepts the Description object as input and returns a Collection object. The Collection
object includes both static and dynamic objects that satisfy the description of the object.

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

5-14 Retrieving Child Objects


Working with Dynamic Objects

Additional Uses of Programmatic Descriptions


In addition to using programmatic descriptions to identify dynamic objects, you can also
use programmatic descriptions to:

• 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

Additional Uses of Programmatic Descriptions 5-15


Working with Dynamic Objects

Summary
In this lesson, you learned how to:

• Set dynamic values of objects in the OBJECT REPOSITORY.

• Build a programmatic description for an object.

• Create and use a Description object.

• Identify additional uses of programmatic descriptions.

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.

1. What are dynamic objects?

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

class, selecting the object properties, and creating a programmatic description._


at
uc

_______________________________________________________________
Ed

_______________________________________________________________
e
ar
ftw

4. Why may you need to use a programmatic description?


So

The additonal uses of programmatic descriptions are performing the same operation
P

on a list of objects with similar properties, performing an operation on a static


H

object that you choose based on run-time information, and bypassing OBJECT
REPOSITORY._____________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

Review Questions 5-17


Working with Dynamic Objects

Exercise: Working with Dynamic Objects


Instructor Notes

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

• Part 1: Open and run an existing script.


n
io

• Part 2: Determine the new steps needed to update the script.


at
uc

Instructor Notes
Ed

The instructor should reconvene the class after this part to discuss the answers.
e
ar

• Part 3: Correct the script by updating the OBJECT REPOSITORY.


ftw


So

Part 4: Correct the script by using programmatic descriptions.


P
H

5-18 Exercise: Working with Dynamic Objects


Working with Dynamic Objects

Part 1: Open and Run an Existing Script


1. Open QuickTest Professional. Load the web add-in.

2. Open the FAXORDER test located in the C:\TRAINING\QTP92ADVANCED\TESTS


folder.

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

Figure 5-7 The FaxOrder Test

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.

Exercise: Working with Dynamic Objects 5-19


Working with Dynamic Objects

3. On the QuickTest Professional toolbar, click RUN to run the test. The RUN dialog
box appears.

4. Click OK.

This test launches the AUT when a run session starts.

The test run does not complete successfully.

Answer the following questions regarding the run session.

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

5-20 Exercise: Working with Dynamic Objects


Working with Dynamic Objects

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

Figure 5-8 Fax Order Dialog Box


P
H

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: _____________

Window("Flight Reservation").Dialog("Fax Order No. 63").


ActiveX("MaskEdBox").Type DataTable("Fax_Number", dtLocalSheet).

_______________________________________________________________

Exercise: Working with Dynamic Objects 5-21


Working with Dynamic Objects

Window("Flight Reservation").Dialog("Fax Order No. 63").


WinButton("Send").Click ________________________________________

_______________________________________________________________

2. Which approach from “Identifying Dynamic Objects” do you use? What is the
benefit of each approach?

Updating a property to use a regular expression is easier to do because the object is


already defined in OBJECT REPOSITORY (OR). The benefit of using a programmatic
description is that we can explicitly validate that the FAX ORDER dialog box is
named with the correct order number. _________________________________

_______________________________________________________________

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

“ORDER NO:” ____________________________________________________


n
io

_______________________________________________________________
at
uc

OrderNumber = Window("Flight Reservation").WinEdit("Order No:").


Ed

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.

Fax Order No\. .* or Fax Order No\. [0-9]* _____________________________

5-22 Exercise: Working with Dynamic Objects


Working with Dynamic Objects

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.

Dialog("text:=Fax Order No. "&OrderNumber) _____________________

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

' Retrieve the order number.


Dim OrderNumber
OrderNumber = Window("Flight Reservation").WinEdit("Order

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

Part 3: Correct the Test by Updating Object Repository


n
io
at

1. Open the FAXORDER test located in the C:\TRAINING\QTP92ADVANCED\TESTS


uc

folder.
Ed

2. Create a new OBJECT REPOSITORY:


e
ar
ftw

a) From the QuickTest Professional menu bar, select RESOURCES → OBJECT


So

REPOSITORY MANAGER to open the OBJECT REPOSITORY MANAGER dialog


box.
P
H

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.

Exercise: Working with Dynamic Objects 5-23


Working with Dynamic Objects

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 5-9 The Object Repository Manager


e
ar

3. To update the dynamic object description:


ftw
So

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.

c) Save the new OBJECT REPOSITORY in the OBJECT REPOSITORY MANAGER


dialog box.

d) Close the OBJECT REPOSITORY MANAGER dialog box.

4. To associate the new OBJECT REPOSITORY with your test:

a) From the QuickTest Professional menu bar, select RESOURCES → ASSOCIATE


REPOSITORIES to open the ASSOCIATE REPOSITORIES dialog box.

5-24 Exercise: Working with Dynamic Objects


Working with Dynamic Objects

b) Click the ‘X’ REMOVE REPOSITORY button. A dialog box appears, prompting
you to confirm the removal.

c) Click YES to confirm the removal of the repository.

d) Click the ‘+’ ADD REPOSITORY button.

e) Select the new saved OBJECT REPOSITORY.

f) In the ASSOCIATE REPOSITORIES dialog box, in the AVAILABLE ACTIONS list,


double-click ORDER_FAX_FLIGHT to move it to the ASSOCIATED ACTIONS
list.

g) Click OK to close the ASSOCIATE REPOSITORIES dialog box.

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

Part 4: Correct the Test by Using Programmatic Descriptions


n
io

1. Open the FAXORDER test located in the C:\TRAINING\QTP92ADVANCED\TESTS


at

folder.
uc
Ed

2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
e

with the name MYFAXORDER.


ar
ftw

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

a) From the QuickTest Professional menu bar, select RESOURCES → ASSOCIATE


REPOSITORIES to open the ASSOCIATE REPOSITORIES dialog box.

b) Ensure that the FLIGHTRESERVATION.TSR file is loaded in the REPOSITORIES


list. If not, remove the existing file by clicking the ‘X’ REMOVE REPOSITORY
button and then select the FLIGHTRESERVATION.TSR file located in the
C:\TRAINING\QTP92ADVANCED\OBJECTS folder.

c) In the ASSOCIATE REPOSITORIES dialog box, in the AVAILABLE ACTIONS list,


double-click ORDER_FAX_FLIGHT to move it to the ASSOCIATED ACTIONS
list.

Exercise: Working with Dynamic Objects 5-25


Working with Dynamic Objects

n
io
at
lic
up
rD
Fo
ot
-N

Figure 5-10 The Associate Repositories Dialog Box


n
io

d) Close the ASSOCIATE REPOSITORY dialog box.


at
uc

4. Within the test, click EXPERT VIEW.


Ed
e

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

7. After updating the code, save the updated script.

8. Close any open instances of the Flight Reservation application.

9. Run the updated test.

Answer the following questions regarding the run session:

a) The test still does not complete successfully. On which step does the test script
fail? What run error message is displayed?

The test fails on the same step as in Part 1. _____________________________

The “WinObject” object is not found....________________________________

5-26 Exercise: Working with Dynamic Objects


Working with Dynamic Objects

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. ___________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

c) How can you correct the step?

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

You need to change WinObject("Fax Number") to


io

WinObject("attached_text:=") ___________________________________
at
uc

_______________________________________________________________
Ed
e

d) Are there any other steps that are to be corrected in the same way?
ar
ftw

Yes, in the immediate next line. _____________________________________


So

Change WinButton("Send")to WinButton("text:=&Send") ______________


P
H

10. Correct the steps and run the test again.

If your test did not complete successfully, use the QuickTest Professional debug
features to help pinpoint the problem areas in the script.

Note: Check with your instructor if problems persist.

Exercise: Working with Dynamic Objects 5-27


Working with Dynamic Objects

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

5-28 Exercise: Working with Dynamic Objects


Using VBScript Operators, Statements and Functions

Using VBScript Operators,


6
Statements and Functions

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

After completing this lesson, you will be able to:


at
uc

• Create scripts that include VBScript operators, statements and functions.


Ed
e

• Describe commonly used VBScript operators.


ar
ftw

• Describe commonly used VBScript statements.


So
P

• Describe commonly used VBScript functions.


H

• Use VBScript operators, statements and functions in a script.

6-1
Using VBScript Operators, Statements and Functions

Introducing VBScript Operators, Statements and


Functions
In addition to calling QuickTest objects and methods in your scripts, you can also use
the following VBScript features to enhance the scripts:

• 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

6-2 Introducing VBScript Operators, Statements and Functions


Using VBScript Operators, Statements and Functions

Commonly Used VBScript Operators


Operators are symbols that represent specific actions in a script. Use an operator to
evaluate expressions. Commonly used VBScript operators are:

• Comparison operators

• Arithmetic operators

• Logical operators

Note: Detailed information on VBScript operators can be found in VBSCRIPT


REFERENCE of QUICKTEST PROFESSIONAL HELP.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

Commonly Used VBScript Operators 6-3


Using VBScript Operators, Statements and Functions

Comparison Operators
Comparison operators are used to compare expressions.

Table 6-1 lists some commonly used comparison operators.

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

6-4 Comparison Operators


Using VBScript Operators, Statements and Functions

Arithmetic Operators
Arithmetic operators are used to perform mathematical calculations.

Table 6-2 lists some commonly used arithmetic operators.

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

& String concatenation


n
io
at

Table 6-2. Arithmetic Operators


uc
Ed
e
ar
ftw
So
P
H

Arithmetic Operators 6-5


Using VBScript Operators, Statements and Functions

Logical Operators
Logical operators are used to perform logical operations.

Table 6-3 lists some commonly used logical operators.

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

The following example shows how to use the Or operator:


e
ar
ftw
So

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.

6-6 Logical Operators


Using VBScript Operators, Statements and Functions

The following example shows how to use the Not operator:

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

Logical Operators 6-7


Using VBScript Operators, Statements and Functions

Evaluating Operator Precedence


When several operations occur in an expression, you first evaluate arithmetic operators,
then the comparison operators and finally the logical operators.

Within each operator category, the following precedence orders apply:

• Arithmetic operators: Negation (-) → Exponentiation (^) → Multiplication and


division (*, /) → Integer division (\) → Addition and subtraction (+, -) → String
concatenation (&).

• All comparison operators have equal precedence.

• Logical operators: Not → And → Or.

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

6-8 Evaluating Operator Precedence


Using VBScript Operators, Statements and Functions

Discussion: Value of Expressions

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 6-1 Discussion: Sample VBScript Operators


at
uc

What is the value of each of the VBScript expression in Figure 6-1?


Ed

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

A: False. 7 is not greater than 9.

(1 > 2) And (2 < 3)


A: False. All conditions in an And expression must be true for the expression to be true. (1>2) is false.

(1 > 2) Or (1 < 2)
A: True. Any one true condition in an Or expression makes the expression true.

“a, “ & “b, “ & “c”


A: “a, b, c”.

Discussion: Value of Expressions 6-9


Using VBScript Operators, Statements and Functions

Commonly Used VBScript Statements


A statement is a line of instruction in a program. A statement also refers to the keywords
that designate the type of instruction to be performed.

Commonly used VBScript statements include statements to:

• Declare constants and variables.

• Add comments to scripts.

• Assign variables to point to objects.

• Define conditional logic in scripts.

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

6-10 Commonly Used VBScript Statements


Using VBScript Operators, Statements and Functions

Using Statements for Commenting


Commenting enables you to add descriptive information to your scripts. Comments also
help you explain the purpose of a single line of code or a group of lines.

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

You do not need to do this for the apostrophe.


n
io
at
uc
Ed
e
ar
ftw
So
P
H

Using Statements for Commenting 6-11


Using VBScript Operators, Statements and Functions

Commenting Multiple Lines

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

ADVANCED → COMMENT BLOCK.


-N
n

To uncomment multiple lines of code, from the QuickTest Professional menu bar, select
io

EDIT → ADVANCED → UNCOMMENT BLOCK.


at
uc
Ed
e
ar
ftw
So
P
H

6-12 Commenting Multiple Lines


Using VBScript Operators, Statements and Functions

Using the Indent Outdent Feature

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

and easier to maintain.


n
io
at

To indent a statement(s), selecting the statement(s) and from the QuickTest Professional
uc

menu bar, select EDIT → ADVANCED → INDENT.


Ed

To outdent a statement(s), select the statement(s) and from the QuickTest Professional
e
ar

menu bar, select EDIT → ADVANCED → OUTDENT.


ftw
So
P
H

Using the Indent Outdent Feature 6-13


Using VBScript Operators, Statements and Functions

Using the Set Statement


The Set statement enables you to assign a variable to point to an object. The Nothing
keyword disassociates a variable from the object.

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

objDetailsImages variable points to a collection of objects. objDetailsImages is later set to


n

Nothing so that the collection of objects can be released.


io
at
uc
Ed
e
ar
ftw
So
P
H

6-14 Using the Set Statement


Using VBScript Operators, Statements and Functions

Using Statements for Conditional Logic


Conditional statements are used to perform an action depending on a certain condition.
You can use the following two conditional statements in VBScript:
• If...Then

• Select Case

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

Using Statements for Conditional Logic 6-15


Using VBScript Operators, Statements and Functions

The If ... Then Conditional Statement

n
io
at
lic
up
rD
Fo
ot
-N

Figure 6-4 Using If ... Then Statements


n
io

Use an IF ... THEN statement to evaluate if a condition is true or false, and depending on
at

the result, to specify one or more statements to run.


uc
Ed

Use an ELSEIF clause to evaluate multiple cases of a test. An IF ... THEN statement can
e

have none or several ELSEIF clauses.


ar
ftw

Use the final ELSE clause in a script to handle all the cases that do not satisfy any of the
So

previous conditions set in the script.


P

Later in this lesson, you also use the Select Case statement to accomplish the same objective as that of the IF
H

... THEN statement.

6-16 The If ... Then Conditional Statement


Using VBScript Operators, Statements and Functions

Using the If ... Then Statement for Custom


Checkpoints

Figure 6-5 If ... Then Statements for Custom Checkpoint

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

to report success. Otherwise, the Reporter object reports failure.


-N

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

Using the If ... Then Statement for Custom Checkpoints 6-17


Using VBScript Operators, Statements and Functions

Using the Select Case Statement


The Select Case statement is similar to the IF ... THEN statement. Use the Select Case
statement only when there are multiple options that depend on the same test expression.

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

if the test expression requires evaluation of a condition.


io
at
uc
Ed
e
ar
ftw
So
P
H

6-18 Using the Select Case Statement


Using VBScript Operators, Statements and Functions

Discussion: Output in Results

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 6-6 Discussion: Sample VBScript Statements


e
ar

What is the result of the VBScript statements shown in Figure 6-6?


ftw

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

Discussion: Output in Results 6-19


Using VBScript Operators, Statements and Functions

Commonly Used VBScript Functions


A function is a series of statements grouped together to perform a specific task and
return a result.

VBScript provides various built-in functions, which include:

• Functions for string manipulation

• Functions for date manipulation

• Functions for type conversion

• Functions for opening dialog boxes

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

6-20 Commonly Used VBScript Functions


Using VBScript Operators, Statements and Functions

Manipulating Strings with Functions


VBScript provides functions to manipulate string expressions and values. For example,
you use string manipulation functions to get a substring from the beginning of the
original string.

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

substring of the given length from the beginning


-N

or the end of the original string.


n

Return the original string if the given number is


io

larger than the actual length of the string.


at
uc

Mid Accepts a string, a starting point, and a length.


Ed

Returns a substring of the given length from the


e

starting point of the original string.


ar
ftw

Split Accepts a string and a delimiter character, and


So

returns an array of substrings as shown:


P
H

Table 6-4. Functions for String Manipulation


The QuickTest Professional string functions are the same as those of Microsoft Excel.

Manipulating Strings with Functions 6-21


Using VBScript Operators, Statements and Functions

Manipulating Dates with Functions


VBScript provides functions for manipulating and working with the date data type. For
example, you use date manipulation functions to find the number of days between two
dates.

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

first date is after the second date.


-N
n

Day, Month, Year, Weekday Accepts a date and returns just the desired portion
io

of the date.
at
uc

Table 6-5. Functions for Date Manipulation


Ed
e
ar
ftw
So
P
H

6-22 Manipulating Dates with Functions


Using VBScript Operators, Statements and Functions

Converting Data Types with Functions


VBScript provides functions to convert values of expressions from one type to another.
For example, you use type conversion functions to convert an expression to a date value.

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

Table 6-6. Functions for Type Conversion


io
at
uc

An error occurs if the conversion for a given expression is not possible.


Ed

Note: VBScript also provides the functions IsNumeric and IsDate functions to check
e
ar

the type of an expression.


ftw
So
P
H

Converting Data Types with Functions 6-23


Using VBScript Operators, Statements and Functions

Discussion: Value of Each Expression

n
io
at
lic
up
rD
Fo
ot

Figure 6-7 Discussion: Sample VBScript Functions


-N

What is the value of each of the VBScript expressions in Figure 6-7?


n
io
at

Instructor Notes
uc

Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer-teaching.
Ed

Len(“abcd” & String(5, “e”))


e

A: 9.
ar
ftw

Right(Left(“IG_CRT_Special”, 6), 3)
So

A: “CRT”.
P
H

Mid(“IG_CRT_Special”, 4, 3)
A: “CRT”.

arr = Split("IG_CRT_Special", "_")


arr(1)
A: “CRT”.

DateDiff(“d”, “02/28/2005”, “03/05/2005”)


A: 5.

Month (“02/28/2005”)
A: 2.

Len(CStr(CBool(0)) & CStr(1>2))


A: 10 = Len (“FalseFalse”).

6-24 Discussion: Value of Each Expression


Using VBScript Operators, Statements and Functions

Functions for Opening Dialog Boxes


VBScript provides functions that you can use to display dialog boxes. These dialog
boxes accept user input and incorporate the user input in a script.

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

calculates the birthday:


n
io
at
uc

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.

Note: Review VBSCRIPT REFERENCE of QUICKTEST PROFESSIONAL HELP for the


complete list of options and return values for the InputBox and MsgBox functions.

Functions for Opening Dialog Boxes 6-25


Using VBScript Operators, Statements and Functions

Summary
In this lesson, you learned how to:

• Create scripts that include VBScript operators, statements and functions.

• Describe commonly used VBScript operators.

• Describe commonly used VBScript statements.

• Describe commonly used VBScript functions.

• Use VBScript operators, statements and functions in a script.

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.

2. What is the function of the Is operator?

The Is operator returns true if two variables refer to the same object. ________

3. What is the function of the Set statement?

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

interact with users. ________________________________________________


e
ar

_______________________________________________________________
ftw
So
P
H

Review Questions 6-27


Using VBScript Operators, Statements and Functions

Exercise: Using VBScript Operators, Statements


and Functions
Instructor Notes

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

-- Students are provided with a base test, VBScript.


uc

, 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

The exercise consists of the following parts:


H

• Part 1: Analyze the requirements.

• 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.

6-28 Exercise: Using VBScript Operators, Statements and Functions


Using VBScript Operators, Statements and Functions

Part 1: Analyze the Requirements


You need to update a flight purchase script. The updated script should have achieved
following objectives:

• After a flight purchase, the number of itineraries increases by one.

• 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.)

Exercise: Using VBScript Operators, Statements and Functions 6-29


Using VBScript Operators, Statements and Functions

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

the number of the objects. _____________________________________________


-N
n

__________________________________________________________________
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

it to a later count. ____________________________________________________


P
H

__________________________________________________________________

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.

__________________________________________________________________

__________________________________________________________________

6-30 Exercise: Using VBScript Operators, Statements and Functions


Using VBScript Operators, Statements and Functions

__________________________________________________________________

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

Figure 6-9 The Dynamic Itinerary Page and Object Spy

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"

Exercise: Using VBScript Operators, Statements and Functions 6-31


Using VBScript Operators, Statements and Functions

Set objCheckboxes = Browser("Welcome: Mercury


Tours").Page("Itinerary: Mercury
Tours").ChildObjects(objCheckboxDesc)

Retrieves the collection of check boxes on the itinerary page. _________________

ii. Code 2:
strName = objCheckboxes(0).GetROProperty("name")

Retrieves the name of the first itinerary on the page._________________________

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

If objBookedTables.Count <> 1 Then


uc

Reporter.ReportEvent micWarning , "objBookedTables.Count",


Ed

objBookedTables.Count&" were found when one object should


have been found."
e
ar
ftw

Reports a warning if multiple or no WebTables have the desired name.__________


So

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

6-32 Exercise: Using VBScript Operators, Statements and Functions


Using VBScript Operators, Statements and Functions

Many different ways. One VBScript expression that will work is: ___________

Year( Right( strBooked, Len(strBooked)-8 ) ) _____________________

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: ___________

Month( Right( strBooked, Len(strBooked)-8 ) ) _________________

d) How do you convert the month value from a number to the name for that
month?

Use a Select Case statement to match 1 to “January”,..., 12 to “December”.

n
Another way to do this is to use the MonthName VBScript function available in

io
at
HELP.___________________________________________________________

lic
up
_______________________________________________________________

rD
_______________________________________________________________
Fo
ot

Part 2: Update the Script to Confirm that the Number of


-N

Itineraries Increases by One After a Flight Purchase


n
io

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

2. Open the VBSCRIPT test located in the C:\TRAINING\ADVANCED QTP92\TESTS


So

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.

6. Run and debug the updated test.

If your test did not complete successfully, use the QuickTest Professional debug features
to help identify the trouble areas in the script.

Exercise: Using VBScript Operators, Statements and Functions 6-33


Using VBScript Operators, Statements and Functions

Note: Check with your instructor if problems persist.

Optional Part 3: Update the Script so that the Results Contain


the Year and Month When the First Itinerary is Booked
1. Open the VBSCRIPT test located in the C:\TRAINING\QTP92ADVANCED\TESTS
folder.

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

features to help identify the trouble areas in the script.


n
io
at

Note: Check with your instructor if problems persist.


uc
Ed
e
ar
ftw
So
P
H

6-34 Exercise: Using VBScript Operators, Statements and Functions


Working with Dynamic Data

Working with Dynamic Data


7

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

After completing this lesson, you will be able to:


-N


n

Retrieve data from application objects.


io
at

• Describe the VBScript looping statements.


uc
Ed

• Use the DATA TABLE object to store run-time data and drive actions.
e
ar

• Build a script for a data-driven test case.


ftw
So
P
H

7-1
Working with Dynamic Data

Dynamic Data Versus Static Data

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 7-1 Dynamic Data and Static Data


e
ar

QuickTest scripts can use static or dynamic data to test an application.


ftw
So

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.

7-2 Dynamic Data Versus Static Data


Working with Dynamic Data

Retrieving Data from Objects


You can retrieve data directly from the objects in the application under test.

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

Retrieving Data from Objects 7-3


Working with Dynamic Data

The WinComboBox and WinList Objects

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 7-2 The WinComboBox and WinList Objects


e
ar

The WINCOMBOBOX objects represent lists in Windows applications. The WINLIST


ftw

objects represent information lists in Windows applications.


So

Figure 7-2 shows examples of the WINCOMBOBOX and WINLIST objects.


P
H

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.

7-4 The WinComboBox and WinList Objects


Working with Dynamic Data

The WebList Object

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 7-3 The WebList Object


e
ar

The WEBLIST object represents lists in Web applications.


ftw
So

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

WEBLIST object uses the GetItem method to retrieve data.

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.

The WebList Object 7-5


Working with Dynamic Data

The WebTable Object

n
io
at
lic
up
rD
Fo
ot

Figure 7-4 The WebTable Object


-N
n

WEBTABLE objects represent information tables in Web applications, as shown in


io
at

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

RowCount methods for a WEBTABLE object:


P
H

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.

7-6 The WebTable Object


Working with Dynamic Data

Overviewing Looping Statements


Often you must perform the same action on a full set of data values rather than on a
single value.

VBScript enables you to perform the same action on a block of statements.

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

Overviewing Looping Statements 7-7


Working with Dynamic Data

Using the For...Next Statement


The FOR...NEXT statement uses a counter to control the number of iterations to be run.

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

nested, the next loop counter is named j, then k and so on.


So
P
H

7-8 Using the For...Next Statement


Working with Dynamic Data

Using the While...Wend Statement


The WHILE...WEND statement uses a condition to control the number of iterations to be
run. The loop continues as long as the condition expressed is True.

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

indicates the location in the list of the desired item.


e
ar
ftw
So
P
H

Using the While...Wend Statement 7-9


Working with Dynamic Data

Using the Do...Loop Statement


Similar to the WHILE...WEND statement, the DO...LOOP statement uses conditions to
control the number of iterations.

The DO...LOOP statement provides additional flexibility in two ways:

• Provides a continuation condition or a termination condition.

• Evaluates the condition at the start or at the end of the loop.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

7-10 Using the Do...Loop Statement


Working with Dynamic Data

Using the Continuation and Termination


Conditions

n
io
at
lic
up
rD
Fo
ot

Figure 7-5 Continuation and Termination Conditions


-N
n

You can use the DO...LOOP statement to provide a continuation condition or a


io
at

termination condition. The condition depends on personal preference.


uc
Ed

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

Using the Continuation and Termination Conditions 7-11


Working with Dynamic Data

Evaluation at the Start Versus at the End

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

7-12 Evaluation at the Start Versus at the End


Working with Dynamic Data

An Overview of Nested Loops


Each VBScript looping statement can be nested within another looping statement. By
nesting looping statements, you can examine all the cells of a DATA TABLE or create
combinations from data lists.

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

Note: You can nest VBScript loops to any number of levels.


-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

An Overview of Nested Loops 7-13


Working with Dynamic Data

Review: Using a Data Table to Manage Iterations

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 7-7 Test Settings and Action Call Properties Windows


e
ar
ftw

In addition to using the VBScript loop statements, you can also iterate a test, action, or
So

component by using data sheets of DATA TABLE.


P
H

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.

7-14 Review: Using a Data Table to Manage Iterations


Working with Dynamic Data

Populating a Data Table Dynamically

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

Populating a Data Table Dynamically 7-15


Working with Dynamic Data

Commonly Used Data Table Methods

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 7-9 Data Table Methods


So

Use the Step Generator to insert the following common methods used to work with the
P

DATA TABLE:
H

• GetSheet and GetSheetCount: To retrieve specific data sheets for further


processing.

The following example shows how to use the GetSheet method to retrieve specific
data sheets:

Example

7-16 Commonly Used Data Table Methods


Working with Dynamic Data

• GetRowCount, GetCurrentRow, and SetCurrentRow: To iterate through rows in a


data sheet.

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

example, DataTable(“My Column Name”) is equivalent to DataTable.Value(“My


ar

Column Name”).
ftw
So
P
H

Commonly Used Data Table Methods 7-17


Working with Dynamic Data

Summary
In this lesson, you learned how to:

• Retrieve data from application objects.

• Describe the VBScript looping statements.

• Use the DATA TABLE object to store run-time data and drive actions.

• Build a script for a data-driven test case.

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.

1. Which method is used to retrieve data from the WEBLIST object?

To retrieve data from the WEBLIST object, use the GetItem method. _________

2. What is the difference between the FOR...NEXT and WHILE...WEND statements?

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

Review Questions 7-19


Working with Dynamic Data

Exercise: Working with Dynamic Data


Instructor Notes

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

The exercise consists of the following parts:


-N

• Part 1: Review the existing script.


n
io
at

• Part 2: Analyze the requirements.


uc
Ed

Instructor Notes
e

Reconvene the class after this point to discuss the answers.


ar
ftw

• Part 3: Update the script for the first objective.


So

• Part 4: Update the script for the second objective.


P
H

7-20 Exercise: Working with Dynamic Data


Working with Dynamic Data

Part 1: Review the Existing Script


Open and run the script DYNAMICDATA script located in the
C:\TRAINING\QTP92ADVANCED\TESTS folder.

Answer the following questions:

1. How many actions are present in this script?

There are five actions in the script. They are: LOGIN, LOGOUT, PURCHASEFIGHT,
and two empty actions called GETDATA and CREATEPERMUTATIONS. ________

_______________________________________________________________

2. How many times is each action executed during a run session?

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

Part 2: Analyze the Requirements


-N
n

You need to update the script so that it:


io
at


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.__________________________

Exercise: Working with Dynamic Data 7-21


Working with Dynamic Data

_______________________________________________________________

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

3. Run and debug the updated test.


n
io

If your test did not complete successfully, use the QTP debug features to help identify
at

the trouble areas in the script.


uc
Ed

Note: Check with your instructor if problems persist.


e
ar
ftw

Part 4: Update the Script for the Second Objective


So

1. Update the test with the code necessary to validate purchases for each combination
P

of departure and arrival cities.


H

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.

2. Run and debug the updated test.

If your test did not complete successfully, use the QTP debug features to help identify
the trouble areas in the script.

Note: Check with your instructor if problems persist.

7-22 Exercise: Working with Dynamic Data


Retrieving External Data

Retrieving External Data


8

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

After completing this lesson, you will be able to:


io
at


uc

Build scripts that access data from external sources.


Ed

• Import data from and export data into a Microsoft Excel worksheet.
e
ar


ftw

Use the Connection and RecordSet objects to query a database.


So

• Import and export data to text files.


P
H

8-1
Retrieving External Data

Using External Data Sources

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 8-1 External Data Sources


So
P

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.

8-2 Using External Data Sources


Retrieving External Data

Importing and Exporting Data from Microsoft


Excel
Test data for an application may be stored in Microsoft Excel. Use the following
methods to import or export data to Microsoft Excel worksheet:

• 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

Importing and Exporting Data from Microsoft Excel 8-3


Retrieving External Data

Using the DataTable.ImportSheet Method

n
io
at
lic
up
rD
Fo
ot
-N

Figure 8-2 Microsoft Excel Data Source


n
io

Use the DataTable.ImportSheet method to import a worksheet of a Microsoft Excel


at

file to a sheet in the run-time data log. In Figure 8-2, the imported data is stored in the
uc

DATASET1 worksheet of the file MERCTOURS_TESTDATA.XLS into the QuickTest


Ed

Professional DATA TABLE for the GETDATA action.


e
ar
ftw

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

QuickTest Professional DATA TABLE.

Note: Ensure that the first row of the Microsoft Excel worksheet has the exact data that
you want for the DATA TABLE columns.

8-4 Using the DataTable.ImportSheet Method


Retrieving External Data

Using the DataTable.ExportSheet Method

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar

Figure 8-3 Microsoft Excel Data Log


ftw
So

Export the data saved in the run-time data table to Microsoft Excel if you want to access
P

the data in another QuickTest Professional test or component.


H

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.

Using the DataTable.ExportSheet Method 8-5


Retrieving External Data

Working with Databases


The test data for an application may be stored in a database. If the data is stored in a
database, you need to retrieve the data from the database.

To retrieve data from a database:

1. Connect to the database.

2. Execute a Structured Query Language (SQL) query.

3. Examine the query results.

4. Close the database session.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

8-6 Working with Databases


Retrieving External Data

Introduction to ActiveX Data Objects (ADO)


The Microsoft platform provides a set of ADO objects that enable applications to
connect to databases and retrieve data.

The commonly used ADO objects are:

• 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

Introduction to ActiveX Data Objects (ADO) 8-7


Retrieving External Data

Connecting to a Database
To connect to a database from a QuickTest Professional script:

1. Create a Connection object.

2. Call the Open method of the Connection object.

You use the ConnectionString property of a Connection object to provide


information about a database. Using this ConnectionString property, the Open method
connects to a database.

The following example shows how to set the ConnectionString property:

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.

8-8 Connecting to a Database


Retrieving External Data

Executing a SQL Query


After the database connection is established, run an SQL query against the database. Use
the Execute method of the Connection object to retrieve data from a database.

The Execute method accepts an SQL statement as an input and returns a RecordSet
object when the run completes.

The following example shows how to use the Execute method:

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.

Executing a SQL Query 8-9


Retrieving External Data

Examining the Query Results


After executing an SQL query, use the RecordSet object to examine the query results.
Use the following properties and methods to examine the query results:

• 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.

• Fields.Count: This method indicates the number of columns of data returned by

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.

8-10 Examining the Query Results


Retrieving External Data

Closing the Database Session


After examining the output of an SQL query, close the database session by using the
Close method. Close methods are provided in the RecordSet and Connection objects.

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

Closing the Database Session 8-11


Retrieving External Data

Working with Text Files


You can store the test data for your application in a text file.

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

8-12 Working with Text Files


Retrieving External Data

Reading from a File


Use the OpenTextFile method in the FileSystemObject object to open a text file and
return a TextStream object. The OpenTextFile method accepts a constant as an
argument. This argument specifies the purpose for the file as reading, writing, or
appending.

A TextStream object facilitates sequential access to a text file.

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

In the above example, the OpenTextFile method in the FileSystemObject object


returns the TextStream object, strText.

Reading from a File 8-13


Retrieving External Data

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:

• Write: Writes a string to an open file.

• WriteLine: Writes a string to an open file, and adds a newline.

• WriteBlankLines: Writes a given number of empty lines to an open 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

8-14 Writing to a File


Retrieving External Data

Summary
In this lesson, you learned how to:

• Build scripts that access data from external sources.

• Import data from and export data into a Microsoft Excel worksheet.

• Use the Connection and RecordSet objects to query a database.

• Import and export data to text files.

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

Read, ReadLine, and ReadAll. ______________________________________


Ed

_______________________________________________________________
e
ar
ftw
So
P
H

8-16 Review Questions


Retrieving External Data

Exercise: Retrieving External Data


Instructor Notes

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

The exercise consists of the following parts:


Ed
e

• Part 1: Import data from a Microsoft Excel file.


ar
ftw

• Part 2: Import data from a Microsoft Access file.


So
P

Part 1: Import Data from a Microsoft Excel File


H

1. Open the EXTERNALDATA test, located in the


C:\TRAINING\QTP92ADVANCED\TESTS folder.

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?

Update the GETDATA action in the script. ______________________________

Exercise: Retrieving External Data 8-17


Retrieving External Data

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.

6. Run and debug the updated test.

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

1. Open the EXTERNALDATA test, located in the


-N

C:\TRAINING\QTP92ADVANCED\TESTS folder.
n
io

2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
at
uc

with the name MYEXTERNALDATAACCESS.


Ed

3. Which action in the script do you need to update for this exercise?
e
ar

Update the GETDATA action. ________________________________________


ftw
So

4. Write the VBScript code to open a connection to the Microsoft Access database,
P

MercTours_TestData.
H

Set objDB = CreateObject("ADODB.Connection") ___________________

objDB.ConnectionString = "DSN=MercTours_TestData" ______________

objDB.Open ____________________________________________________

5. Write the VBScript code to retrieve the list of departure and arrival cities.

Note: The MERCTOURS_TESTDATA database has two tables, DEPARTURE_CITIES


and ARRIVAL_CITIES. Both tables have a column named CITY. The SQL query
used to retrieve the departure cities data is:
Select City From_Departure Cities

8-18 Exercise: Retrieving External Data


Retrieving External Data

The SQL query to retrieve the arrival cities data is:

Select City From Arrival_Cities

Set objDepartureCities = objDB.Execute("Select City From


Departure_Cities")

Set objArrivalCities = objDB.Execute("Select City From


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

Do While Not objDepartureCities.EOF


n
io

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

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

Exercise: Retrieving External Data 8-19


Retrieving External Data

_______________________________________________________________

7. Write the VBScript code to clean up the Connection and RecordSet objects.
objDepartureCities.Close

objArrivalCities.Close

objDB.Close

Set objDepartureCities = Nothing

Set objArrivalCities = Nothing

Set objDB = Nothing

_______________________________________________________________

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

9. Run and debug the updated test.


ar
ftw

If the test fails, use the QuickTest Professional debug feature to troubleshoot the script.
So
P

Note: Check with your instructor if problems persist.


H

8-20 Exercise: Retrieving External Data


Creating New Procedures

Creating New Procedures


9

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

After completing this lesson, you will be able to:


Ed
e

• Identify the advantages of creating a procedure in a test.


ar
ftw

• Create new subroutines and functions.


So
P

• Register a procedure with an object class.


H

• Build and associate a function library.

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.

Creating procedures in VBScript can:

• Simplify code for readability and maintenance.

• Override an existing object method.

• Enable reuse of abstract code in scripts, business components, or recovery

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

9-2 An Introduction to Procedures


Creating New Procedures

Comparing Subroutines and Functions


A subroutine procedure is a series of VBScript statements that perform actions but do
not return a value. A function procedure is a series of VBScript statements that
perform actions and return a value.

A subroutine is a primitive version of a function. Table 9-1 shows the characteristics of


subroutines and functions.

Subroutines and Functions Subroutines Functions


Contains a series of statements True True
Returns a value False True

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

Comparing Subroutines and Functions 9-3


Creating New Procedures

Understanding the Subroutine Syntax


You create a subroutine by using the Sub ... End Sub statement.

The syntax of the Sub ... End Sub statement is:


Sub <subroutine_name> (argument1, argument2, ..., argumentX)
‘ Statement A
End Sub

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

later in this lesson.


e
ar
ftw
So
P
H

9-4 Understanding the Subroutine Syntax


Creating New Procedures

Understanding the Function Syntax


You create a function by using the Function ... End Function statement.

The syntax of the Function ... End Function statement is:


Function <function_name> (argument1, argument2, ..., argumentX)
‘ Statement A
<function_name> = <expression>
End Function

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

Understanding the Function Syntax 9-5


Creating New Procedures

Creating a New Procedure


After identifying the goal of a procedure, create the procedure by using the following
steps:

1. Add the base steps for the procedure.

2. Create the procedure declaration.

3. Define the arguments for the procedure.

4. Set return values for the procedure.

5. Handle errors in the procedure.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

9-6 Creating a New Procedure


Creating New Procedures

Adding the Base Steps for a New Procedure

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw

Figure 9-1 A New Procedure


So

Building a procedure involves adding steps to a procedure in a script. Add steps in a


P

script by using one of the following methods:


H

• Record steps in the application under test.

• Use the ACTIVE SCREEN.

• Use the STEP GENERATOR.

• Type the steps directly in the script.

Figure 9-1 shows how to add the steps for a new procedure directly into a script.

Adding the Base Steps for a New Procedure 9-7


Creating New Procedures

Declaring the Procedure

n
io
at
lic
up
rD
Fo
ot
-N

Figure 9-2 Procedure Declaration


n
io
at

After creating the code for a procedure, declare the procedure. Declaring a procedure
uc

depends on if the procedure is a subroutine or a function.


Ed
e

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

- Select the desired lines and press the TAB key.


H

9-8 Declaring the Procedure


Creating New Procedures

Defining an Argument

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 9-3 Procedure Arguments


at
uc

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.

Defining an Argument 9-9


Creating New Procedures

Setting Return Values

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 9-4 Setting Return Values


at
uc

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

variable that indicates whether or not the login succeeds.


ftw

Return a value from a function by assigning the function name to the desired value, as
So

shown in Figure 9-4.


P
H

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.

9-10 Setting Return Values


Creating New Procedures

Handling Errors

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc

Figure 9-5 Error Handling


Ed

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

Exit statement to abort a procedure, if required, as shown in Figure 9-5.


P


H

Error handling and Exit statements are covered in more detail in lesson 10, “Managing QuickTest Professional
Exception Handling”.

Handling Errors 9-11


Creating New Procedures

Making a Procedure Available


Use a procedure as a:

• 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

9-12 Making a Procedure Available


Creating New Procedures

Using a Procedure Locally

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 9-6 QuickTest Script and Step Generator


e
ar

To use a procedure locally in the same script in which it is defined, add the procedure
ftw

definition code to the current script.


So

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.

Using a Procedure Locally 9-13


Creating New Procedures

Associating a Procedure with a Test Object


When you create a procedure and associate it with a test object, this association enables
you to use the procedure whenever you use an instance of the test object.

When creating a procedure for use as a QuickTest Professional test object method, you
can perform the following steps:

1. Register the procedure with an object class.

2. Override an existing object method.

3. Unregister the procedure.

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

9-14 Associating a Procedure with a Test Object


Creating New Procedures

Registering a Procedure with an Object Class


Use the RegisterUserFunc statement to associate a procedure with a test object class.

The syntax of the RegisterUserFunc statement is:


RegisterUserFunc <class>, <method>, <procedure>

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

Professional run session begins.


Ed
e

Note: To be registered with an object class, the procedure that you define must have an
ar
ftw

object as its first argument.


So
P
H

Registering a Procedure with an Object Class 9-15


Creating New Procedures

Overriding an Existing Object Method


Use the RegisterUserFunc statement to override an existing method of a test object
class.

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

the original method.


uc
Ed
e
ar
ftw
So
P
H

9-16 Overriding an Existing Object Method


Creating New Procedures

Using the Function Definition Generator

n
io
at
lic
up
rD
Fo
ot

Figure 9-7 Function Definition Generator


-N

QuickTest provides a FUNCTION DEFINITION GENERATOR, which enables you to


n
io

generate definitions for new user-defined functions and add header information to them.
at
uc

To open the FUNCTION DEFINITION GENERATOR:


Ed
e

1. Ensure that the function library or test where you want to insert the function
ar

definition is the active document.


ftw
So

2. From the QuickTest Professional menu bar, select INSERT → FUNCTION


P

DEFINITION GENERATOR. The FUNCTION DEFINITION GENERATOR dialog box


H

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.

Using the Function Definition Generator 9-17


Creating New Procedures

Unregistering a Procedure
Use the UnregisterUserFunc statement to dissociate any user-defined procedures that
are associated with a test object class.

The syntax of the UnregisterUserFunc statement is:


UnregisterUserFunc <class>, <method>

The following example shows how to use the UnregisterUserFunc statement to


unregister a user-defined procedure:

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

9-18 Unregistering a Procedure


Creating New Procedures

Building a Library
Build library files to make procedures accessible to multiple QuickTest scripts.

To build a library file:

1. Create a library file by using one of the following:

– Standard text editor

– FUNCTION LIBRARY editor

2. Associate the library to a test or an application area.

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

Building a Library 9-19


Creating New Procedures

Creating a Library File Using a Standard Text


Editor

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 9-8 Library File Creation Using a Standard Text Editor


at
uc

A QuickTest Professional library file is a text file that contains VBScript subroutines
Ed

and functions. To create a library file:


e
ar
ftw

1. Create a new file in NOTEPAD or any other text editor.


So

2. Copy and paste the desired procedures into the newly created file.
P
H

3. Confirm that the procedures have the desired access scope:

– 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.

4. Save the file with a .vbs or .txt extension.

Note: The constants and variables added to libraries are available to all the actions in a
test.

9-20 Creating a Library File Using a Standard Text Editor


Creating New Procedures

Opening the Function Library Editor

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

QuickTest Professional has a built-in FUNCTION LIBRARY editor. The FUNCTION


e
ar

LIBRARY editor enables you to create and edit function libraries that contain VBScript
ftw

functions and subroutines.


So

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.

Note: A function library file is saved with a .qfl extension.

Opening the Function Library Editor 9-21


Creating New Procedures

Associating a Library

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 9-10 Library Association


at
uc

After creating a library, associate the library with the script where you intend to use the
Ed

procedure defined in the library file.


e
ar

To associate a library to a QuickTest Professional test or application area:


ftw
So

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.

3. Use the arrow buttons to edit the order of the libraries.

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.

4. Click CHECK SYNTAX to review all libraries for syntax errors.

5. Click SET AS DEFAULT to automatically associate the selected libraries with your
new tests or application areas.

9-22 Associating a Library


Creating New Procedures

Associating a Function Library with a Test

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 9-11 Associate Function Library with a Test


e
ar

To associate a function library with an open test use the associated function libraries list.
ftw

To associate a function library with a test:


So

1. Ensure that the test that you want to associate with the function library is open in
P

QuickTest Professional.
H

2. Create or open a function library in QuickTest.

Note: Before continuing to the next step, ensure that the function library that you want
to associate with the test is the active document.

3. Right-click in the function library and select ASSOCIATE LIBRARY ‘<FUNCTION


LIBRARY>’ WITH ‘TEST’ or from the QuickTest Professional menu bar, select
FILE → ASSOCIATE LIBRARY ‘<FUNCTION LIBRARY>’ WITH ‘TEST’. QuickTest
associates the function library with the open test.

Associating a Function Library with a Test 9-23


Creating New Procedures

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

9-24 Using a Procedure


Creating New Procedures

Using a Procedure in a Script

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 9-12 The Step Generator to Insert Code in a Script


e
ar
ftw

The following options are available within the STEP GENERATOR:


So

• 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.

Using a Procedure in a Script 9-25


Creating New Procedures

Using a Procedure in a Recovery Scenario

n
io
at
lic
up
rD
Fo
ot
-N
n
io

Figure 9-13 Call a Procedure in the Recovery Scenario Wizard


at
uc

To use a function in a recovery scenario:


Ed

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

reach the RECOVERY OPERATIONS page.


So

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.

4. Select the desired library file from the FUNCTION LIBRARY.

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.

6. Add, remove, or reorder the operations as needed.

7. Continue through the RECOVERY SCENARIO WIZARD until it finishes.

9-26 Using a Procedure in a Recovery Scenario


Creating New Procedures

Requirements for Recovery Scenario


Procedures
To be available for use in a recovery scenario, a procedure must be:

• 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

The method in the faulty step


n


io

The arguments that were passed into


at

the method
uc
Ed

• The result that was returned by the


e

method
ar
ftw

Application crash The name and ID of the process that failed


So

If you choose to define the function while defining the recovery scenario, QuickTest
P
H

Professional provides the default input values for you.

Requirements for Recovery Scenario Procedures 9-27


Creating New Procedures

Summary
In this lesson, you learned how to:

• Identify the advantages of creating a procedure in a test.

• Create new subroutines and functions.

• Register a procedure with an object class.

• Build and associate a function library.

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.

1. What are the advantages of creating a procedure in a test?

It simplifies code for readability and maintenance, overrides an existing object


method, and abstracts code for reuse in scripts, business components, or recovery
scenarios. _______________________________________________________

_______________________________________________________________

_______________________________________________________________

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

3. What is the advantage of associating a procedure with a test object?


Ed

Associating a procedure with test object enables you to use the procedure whenever
e
ar

you use an instance of the test object. _________________________________


ftw
So

_______________________________________________________________
P

4. How do you create a library file?


H

You can create a library file using standard text editor or FUNCTION LIBRARY editor.

_______________________________________________________________

Review Questions 9-29


Creating New Procedures

Exercise: Creating New Procedures


Instructor Notes

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 2: Define and test the new procedure in QuickTest Professional.


at
uc

• Part 3: Create and associate a new library file by using the FUNCTION LIBRARY
Ed

editor.
e
ar
ftw
So
P
H

9-30 Exercise: Creating New Procedures


Creating New Procedures

Part 1: Analyze the Requirements


You need to create a new procedure for testing the Mercury Tours application. Your
procedure must examine the contents of the itinerary Web page and return the number of
itineraries that the agent books.

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

Figure 9-14 Dynamic Itinerary Page

1. Should the new procedure be a subroutine or a function? Explain your answer.

The new procedure should be a function because it should return a value. _____

Exercise: Creating New Procedures 9-31


Creating New Procedures

2. Are any input parameters required for the new procedure?

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. _______________________________________________

4. Open the NEWPROCEDURE test located in the


C:\TRAINING\QTP92ADVANCED\TESTS folder. This script includes code that
retrieves the number of current itineraries.

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

GetCurrentItineraryCount = Browser("Welcome: Mercury


Tours").Page("Itenerary: Mercury
n
io

Tours").ChildObjects(objCheckboxDesc).Count
at
uc

End Function __________________________________________________


Ed

_______________________________________________________________
e
ar
ftw

_______________________________________________________________
So

_______________________________________________________________
P
H

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

9-32 Exercise: Creating New Procedures


Creating New Procedures

6. Do you mark the new procedure as Public or Private?

Mark the new procedure as public to call the new procedure outside the library file.

_______________________________________________________________

Part 2: Define and Test the New Procedure in QuickTest


Professional
1. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYNEWPROCEDURE.

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

1. To create a new function library file:


n

a) From the QuickTest Professional menu bar, select FILE → NEW → FUNCTION
io
at

LIBRARY.
uc
Ed

b) Cut the GETCURRENTITINERARYCOUNT procedure from the


NEWPROCEDURE test and paste the procedure into the new function library file.
e
ar
ftw

c) Save the function library file as MYLIBRARYFILE.QFL in the folder


C:\TRAINING\QTP92ADVANCED\FUNCTION LIBRARY folder.
So
P

2. To associate the library file with QuickTest script:


H

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.

b) From the QuickTest Professional menu bar, select FILE → ASSOCIATE


LIBRARY ‘MYLIBRARYFILE.QFL’ WITH ‘MYNEWPROCEDURE’.

c) QuickTest associates the function library with the open test.

Exercise: Creating New Procedures 9-33


Creating New Procedures

3. Run and debug the updated test.

If the test does not complete successfully, use the QuickTest Professional debug features
to help identify the trouble areas in the script.

Note: Check with your instructor if problems persist.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

9-34 Exercise: Creating New Procedures


Handling QuickTest Exceptions

Handling QuickTest Exceptions


10

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

After completing this lesson, you will be able to:


Ed
e

• Describe exceptions in a test.


ar
ftw

• Handle positive and negative test data.


So
P

• Use recovery scenarios for exceptions in a script.


H

• Handle exceptions programmatically.

10-1
Handling QuickTest Exceptions

Overview of Exceptions

n
io
at
lic
up
rD
Fo
ot

Figure 10-1 Run Error Window


-N
n

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

unexpected errors and events are called run errors or exceptions.


ftw
So

When the QuickTest Professional encounters an exception within a run session, it


displays a RUN ERROR window. The RUN ERROR window provides the following
P
H

options to handle the exceptions:

• 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.

10-2 Overview of Exceptions


Handling QuickTest Exceptions

Handling Positive and Negative Test Data

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.

Handling Positive and Negative Test Data 10-3


Handling QuickTest Exceptions

Benefits of Exception Handling


Handle exceptions in a test using the RECOVERY SCENARIO WIZARD or
programmatically.

Exception handling provides the following advantages:

• It enables a script to handle exceptions and ensures that the test runs to completion.

• It enables you to test positive and negative test data.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

10-4 Benefits of Exception Handling


Handling QuickTest Exceptions

An Overview of the Recovery Scenario Wizard

n
io
at
lic
up
rD
Fo
ot

Figure 10-3 Recovery Scenario Wizard


-N

Create recovery scenarios to handle exceptions. QuickTest Professional provides the


n
io

RECOVERY SCENARIO WIZARD, which guides you through the process of defining a
at

recovery scenario. The process of defining a recovery scenario includes defining an


uc
Ed

unexpected event and recovering the run session of a test.


e

A recovery scenario consists of the following components:


ar
ftw

• TRIGGER: Interrupts the run session of the test. For example, the test may be
So

interrupted by a window that may pop up on the screen.


P
H

• 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.

• POST-RECOVERY: Instructs QuickTest Professional how to proceed after the


recovery operations are performed and where in the test QuickTest Professional
must proceed. For example, after handling an exception, you may want to restart a
test from the beginning, or skip a step entirely and continue with the next step in the
test.

Note: You use recovery scenarios for unpredictable events or events that you cannot
synchronize with a specific step in your test.

An Overview of the Recovery Scenario Wizard 10-5


Handling QuickTest Exceptions

Types of Recovery Scenarios

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 10-4 Types of Recovery Scenarios


e
ar

The types of recovery scenarios are defined by the type of triggers. These triggers are
ftw

provided in the QuickTest Professional RECOVERY SCENARIO WIZARD.


So

The following are the trigger events in RECOVERY SCENARIO WIZARD:


P
H

• POP-UP WINDOW: QuickTest Professional detects a pop-up window and identifies it


according to the window title and textual content.

• 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.

• TEST RUN ERROR: QuickTest Professional detects an exception and identifies it by a


failed return value from a method.

• APPLICATION CRASH: QuickTest Professional detects an application crash and


identifies it according to a predefined list of applications.

10-6 Types of Recovery Scenarios


Handling QuickTest Exceptions

Using Recovery Scenarios for Exception


Handling

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 10-5 Exception Handling by Using Recovery Scenario Wizard


e
ar

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.

Using Recovery Scenarios for Exception Handling 10-7


Handling QuickTest Exceptions

Viewing the Recovery Scenarios for a Test

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed

Figure 10-6 View Recovery Scenarios for a Test


e
ar

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

scenario in the TEST SETTINGS dialog box.

10-8 Viewing the Recovery Scenarios for a Test


Handling QuickTest Exceptions

Handling Exceptions Programmatically


In addition to handling exceptions by using recovery scenarios, you can handle
exceptions programmatically for better control over the script.

You can handle exceptions programmatically using:

• Conditional statements.

• Exit statements.

• The On Error Resume Next statement.

n
io
at
lic
up
rD
Fo
ot
-N
n
io
at
uc
Ed
e
ar
ftw
So
P
H

Handling Exceptions Programmatically 10-9


Handling QuickTest Exceptions

Using Conditional Statements

n
io
at
lic
up
rD
Fo
ot

Figure 10-7 Conditional Statement


-N

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

statements is executed for both positive and negative test data.


e
ar
ftw

Note: Positive and negative test data are covered later in this lesson.
So
P
H

10-10 Using Conditional Statements


Handling QuickTest Exceptions

Using Exit Statements

n
io
at
lic
up
rD
Fo
ot

Figure 10-8 Exit Statement


-N

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

The two types of Exit statements are:


H

• VBScript Exit statements

• QuickTest Professional Exit statements

Using Exit Statements 10-11


Handling QuickTest Exceptions

VBScript Exit Statements

n
io
at
lic
up
rD
Fo
ot

Figure 10-9 VBScript Exit Statement


-N

Use the VBScript Exit statement to terminate loops or procedures in a test.


n
io
at

Figure 10-9 shows how to search for a specified item in a WINLIST object. The figure
uc

shows the VBScript Exit statement in the following contexts:


Ed
e

• The block of code on the left uses the Exit statement to terminate the DO ... WHILE
ar

loop as soon as the desired item is found.


ftw
So

• 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

after the desired item is found.

10-12 VBScript Exit Statements


Handling QuickTest Exceptions

The Exit Statements


In addition to the VBScript Exit statements, QuickTest Professional provides the
following Exit statements.

Exit Statements for Exit Statements for


QuickTest Professional Actions and QuickTest Professional Components
Tests and Business Process Tests
ExitActionIteration ExitComponentIteration

Terminates the current Terminates the current


iteration of the action. iteration of the
Proceeds to the next component. Proceeds to

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

iterations. Proceeds to the iterations. Proceeds to the


-N

next action, if any, in the next component, if any, in


n
io

test. the business process test.


at
uc

ExitGlobalIteration ExitTestIteration
Ed

Terminates the current Terminates the current


e

iteration of the actions in iteration of the


ar
ftw

a test. Proceeds to the next components in a business


So

iteration, if any, of the process test. Proceeds to


test. the next iteration, if any,
P
H

of the business process


test.
ExitRun ExitTest

Terminates the entire run Terminates the entire run


of the test. of the business process
test.
Table 10-1. QuickTest Professional Exit Statements

The Exit Statements 10-13


Handling QuickTest Exceptions

Using the On Error Resume Next Statement

Figure 10-10 Using the On Error Resume Next Statement

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

the next statement check for an anticipated exception.


uc
Ed

Note: The On Error Resume Next statement skips all the exceptions in a test including
e

the ones that you do not anticipate.


ar
ftw
So
P
H

10-14 Using the On Error Resume Next Statement


Handling QuickTest Exceptions

Summary
In this lesson, you learned how to:

• Describe exceptions in a test.

• Handle positive and negative test data.

• Use recovery scenarios for exceptions in a script.

• Handle exceptions programmatically.

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?

In QuickTest Professional, you can handle exceptions by using Recovery Scenario


Wizard. You can also handle exceptions programmatically. ________________

_______________________________________________________________

2. What are the advantages of exception handling?

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

4. What is the purpose of the VBScript On Error Resume Next statement?


Ed

The VBScript On Error Resume Next statement enables a script to continue


e
ar

processing even after an exception occurs. _____________________________


ftw
So

_______________________________________________________________
P
H

10-16 Review Questions


Handling QuickTest Exceptions

Exercise: Handling Negative and Positive Test


Data
Instructor Notes

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

• Part 1: Analyze the requirements.


n
io

• Part 2: Code and debug a script.


at
uc
Ed
e
ar
ftw
So
P
H

Exercise: Handling Negative and Positive Test Data 10-17


Handling QuickTest Exceptions

Part 1: Analyze the Requirements


An existing test VALIDATELOGIN performs the following test on the Flight32
application:

• 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

Figure 10-11 Run Errors in Test Results

The exceptions occur because some user names and passwords in the imported
Microsoft Excel sheet are incorrect, for these the application does not login.

10-18 Exercise: Handling Negative and Positive Test Data


Handling QuickTest Exceptions

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

Skips to the next user name and password combination.


e
ar

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

_______________________________________________________________

Part 2: Code and Debug a Script


1. Open the VALIDATELOGIN script located in the C:\TRAINING\ADVANCED
QTP92\TESTS folder.

2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYVALIDATELOGIN.

3. Update the script with code to achieve the given objectives.

4. Run and debug the updated test.

Exercise: Handling Negative and Positive Test Data 10-19


Handling QuickTest Exceptions

n
io
at
lic
up
rD
Fo
ot
-N

Figure 10-13 Checks for Test Cases


n

If your test does not complete successfully, use the QuickTest Professional debug
io
at

features to help identify the trouble areas in the script.


uc
Ed

Check with your instructor if problems persist.


e
ar
ftw
So
P
H

10-20 Exercise: Handling Negative and Positive Test Data


Handling QuickTest Exceptions

Exercise: Handling Exceptions


Programmatically
Instructor Notes

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

The exercise consists of the following parts:


n
io

• Part 1: Analyze the requirements.


at
uc

• Part 2: Code and debug a script.


Ed
e
ar
ftw
So
P
H

Exercise: Handling Exceptions Programmatically 10-21


Handling QuickTest Exceptions

Part 1: Analyze the Requirements


An existing script EXCEPTIONHANDLING performs the following test on the Mercury
Tours application:

• Imports a list of departure and arrival cities from a Microsoft Excel worksheet.

• Tests that a flight can be purchased for each combination of cities.

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

Figure 10-14 Run Errors in Test Results

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.

10-22 Exercise: Handling Exceptions Programmatically


Handling QuickTest Exceptions

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

ensure that the script:


n
io


at

Confirms that the retired city is not among the options offered in the application.
uc


Ed

Skips to the next departure-arrival combination.


e
ar

1. Which action or actions in the GOODDEANFROMEZRA script do you need to update


ftw

and why?
So

Update the PURCHASEFLIGHT action to check that retired cities are not among the
P

options in the application. Also update the CREATEPERMUTATIONS action to have


H

the PURCHASEFLIGHTS DATA TABLE indicate when a retired city is used. _____

_______________________________________________________________

_______________________________________________________________

2. You need to handle the exceptions programmatically. Which exception handling


approach do you use?

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. _______________________________________________________

Exercise: Handling Exceptions Programmatically 10-23


Handling QuickTest Exceptions

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

Part 2: Code and Debug a Script


1. Open the EXCEPTIONHANDLING script located in the C:\TRAINING\ADVANCED
QTP92\TESTS folder.

2. From the QuickTest Professional menu bar, select FILE → SAVE AS to save the test
as MYEXCEPTIONHANDLING.

3. Update the script with code to achieve the given objectives.

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

features to help identify the trouble areas in the script.


io
at
uc

Check with your instructor if problems persist.


Ed
e
ar
ftw
So
P
H

10-24 Exercise: Handling Exceptions Programmatically


Class Evaluation Form
(http://www.merc-training.com/survey/publictraining)

Class: _____________________________ Class Start Date: _________________

Location: ___________________________ Instructor: ______________________

1. How did you register for this class? (check one)

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

My registration was handled efficiently. 5 4 3 2 1 -


-N

The classroom/facilities were clean and 5 4 3 2 1 on-site


well maintained.
n
io

The classroom equipment worked properly 5 4 3 2 1 on-site


at

and effectively supported the class.


uc
Ed

3. How could the registration process or facilities be improved?


e
ar
ftw
So
P

4. If there was CBT, WBT or online pre-work that was to be completed before class, did you
H

complete it?

There was no pre-work for this class


Yes - I completed it before class
No - I didn't understand that it was required
No - I didn't get the assignment in time
No - I didn't have time to do it
No - Skipped it, already familiar with the content
No - Couldn't figure out the WBT site
No - I started, but the content didn't seem useful
5. If you completed pre-work for this class, how helpful was it in preparing you for this class?

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

3 - I'm comfortable with common product


n

functions
io
at

2 - I've used the product a little


uc
Ed

1 - I've never used the product


e
ar
ftw

8. How much do you agree with the following statements regarding the course content and
So

materials?
P

Strongly Strongly
H

Agree Neutral Disagree


Agree Disagree
The objectives laid out in the course description were 5 4 3 2 1
met.
The course materials were clearly written and easy to 5 4 3 2 1
follow.
There was an appropriate amount of content - not too 5 4 3 2 1
packed or too lean.
The lab exercises were well constructed and relevant. 5 4 3 2 1
The graphics in the course materials were clear and 5 4 3 2 1
effective.
I would recommend this course to others. 5 4 3 2 1

9. How could the course materials be improved?


10. How much do you agree with the following statements regarding the class instructor?

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

13. What is your level of confidence after completing the class?


at
uc

I understood the
Ed

I understood the
course concepts, I understood the
course concepts, I understood some
e

can apply some course concepts, I had a very hard


ar

and can apply most of the course con-


without assistance, but will need help time with this course
ftw

of them without cepts


but will need help applying them
assistance
So

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

Anda mungkin juga menyukai