23319158-Advanced-QTP-9-2

249
Advanced QuickTest Professional 9.2 August 2007 HP Software Education - Not For Duplication

Transcript of 23319158-Advanced-QTP-9-2

Page 1: 23319158-Advanced-QTP-9-2

Advanced QuickTest Professional 9.2

August 2007

Use of this material to deliver training without prior written permission from HP is prohibited.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 2: 23319158-Advanced-QTP-9-2

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

Printed in the USAAdvanced QuickTest Professional 9.2

QTP92Adv-Instruct-01BInstructor GuideAugust 2007

If you have any comments or suggestions regarding this document, please send them viahttp://www.merc-training.com/feedback

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 3: 23319158-Advanced-QTP-9-2

Introduction..............................................................................................................................1Course Objectives ................................................................................................................2Course Outline .....................................................................................................................3Instructional Methods ..........................................................................................................5Class Introductions ..............................................................................................................6Sample Test Applications ....................................................................................................8

Introduction to Expert View...................................................................................................1An Overview of Expert View ..............................................................................................2Using Expert View...............................................................................................................3Translating Steps Between Views .......................................................................................4An Overview of VBScript ...................................................................................................5An Overview of Object Oriented Programming..................................................................6Objects in QuickTest ...........................................................................................................7Classes in QuickTest ...........................................................................................................8Common Windows and Web Objects..................................................................................9Common Methods in QuickTest........................................................................................10Elements of a QuickTest Script .........................................................................................11Guidelines for VBScript Syntax ........................................................................................12More Guidelines for VBScript Syntax...............................................................................13Discussion: Match the Steps from the Views ....................................................................14Discussion: Write the VBScript Code ...............................................................................15Summary............................................................................................................................16Review Questions ..............................................................................................................17

Using Expert View ...................................................................................................................1Adding New Steps in Expert View......................................................................................2Categories in the Step Generator .........................................................................................3Defining a Step ....................................................................................................................4Inserting a Step Manually ....................................................................................................5Using Statement Completion ...............................................................................................6Expanding VBScript Syntax ................................................................................................7Launching Context-Sensitive Help ......................................................................................8An Overview of the With Statement....................................................................................9Applying the With Statement to a Test..............................................................................10Using Debugging Features.................................................................................................11Finding Syntax Errors ........................................................................................................12Executing a Script from a Specific Step ............................................................................13Adding Breakpoints ...........................................................................................................14Executing Single Steps ......................................................................................................15

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 4: 23319158-Advanced-QTP-9-2

Summary............................................................................................................................16Review Questions ..............................................................................................................17Exercise: Using Expert View.............................................................................................18

Working with Object Properties ............................................................................................1Retrieving Object Property Values ......................................................................................2Run-Time Object Properties Versus Test Object Properties ...............................................3Retrieving the Property Values............................................................................................4Identifying a Property ..........................................................................................................5Calling GetROProperty or GetTOProperty .........................................................................6Setting Object Properties: Calling SetTOProperty ..............................................................7An Overview of Constants and Variables............................................................................8Declaring Constants and Variables......................................................................................9Viewing the Run-Time Value of a Variable ......................................................................10Adding the Reporter Utility Object ...................................................................................11Using the Reporter Utility Object ......................................................................................12Filtering Events..................................................................................................................13Discussion: Output in Results............................................................................................14Summary............................................................................................................................15Review Questions ..............................................................................................................16Exercise: Working with Object Properties ........................................................................17

Working with Dynamic Objects .............................................................................................1Dynamic Objects Versus Static Objects ..............................................................................2Review: Object Repository for Static Objects .....................................................................3Identifying Dynamic Objects...............................................................................................4Setting Dynamic Values in the Object Repository ..............................................................5Using Programmatic Descriptions .......................................................................................6Building Programmatic Descriptions...................................................................................7Identifying the Object Class ................................................................................................8Selecting Object Properties..................................................................................................9Creating a Programmatic Description................................................................................10Specifying Property and Value Pairs .................................................................................11Using the Description Object.............................................................................................13Retrieving Child Objects ...................................................................................................14Additional Uses of Programmatic Descriptions ................................................................15Summary............................................................................................................................16Review Questions ..............................................................................................................17Exercise: Working with Dynamic Objects ........................................................................18

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 5: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions........................................................1Introducing VBScript Operators, Statements and Functions...............................................2Commonly Used VBScript Operators .................................................................................3Comparison Operators .........................................................................................................4Arithmetic Operators ...........................................................................................................5Logical Operators ................................................................................................................6Evaluating Operator Precedence..........................................................................................8Discussion: Value of Expressions........................................................................................9Commonly Used VBScript Statements..............................................................................10Using Statements for Commenting....................................................................................11Commenting Multiple Lines ..............................................................................................12Using the Indent Outdent Feature ......................................................................................13Using the Set Statement .....................................................................................................14Using Statements for Conditional Logic ...........................................................................15The If ... Then Conditional Statement ...............................................................................16Using the If ... Then Statement for Custom Checkpoints ..................................................17Using the Select Case Statement .......................................................................................18Discussion: Output in Results............................................................................................19Commonly Used VBScript Functions ...............................................................................20Manipulating Strings with Functions.................................................................................21Manipulating Dates with Functions ...................................................................................22Converting Data Types with Functions .............................................................................23Discussion: Value of Each Expression ..............................................................................24Functions for Opening Dialog Boxes ................................................................................25Summary............................................................................................................................26Review Questions ..............................................................................................................27Exercise: Using VBScript Operators, Statements and Functions ......................................28

Working with Dynamic Data ..................................................................................................1Dynamic Data Versus Static Data .......................................................................................2Retrieving Data from Objects ..............................................................................................3The WinComboBox and WinList Objects...........................................................................4The WebList Object.............................................................................................................5The WebTable Object ..........................................................................................................6Overviewing Looping Statements .......................................................................................7Using the For...Next Statement............................................................................................8Using the While...Wend Statement......................................................................................9Using the Do...Loop Statement..........................................................................................10Using the Continuation and Termination Conditions ........................................................11Evaluation at the Start Versus at the End ..........................................................................12An Overview of Nested Loops ..........................................................................................13Review: Using a Data Table to Manage Iterations ............................................................14

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 6: 23319158-Advanced-QTP-9-2

Populating a Data Table Dynamically ...............................................................................15Commonly Used Data Table Methods...............................................................................16Summary............................................................................................................................18Review Questions ..............................................................................................................19Exercise: Working with Dynamic Data .............................................................................20

Retrieving External Data ........................................................................................................1Using External Data Sources ...............................................................................................2Importing and Exporting Data from Microsoft Excel .........................................................3Using the DataTable.ImportSheet Method ..........................................................................4Using the DataTable.ExportSheet Method ..........................................................................5Working with Databases ......................................................................................................6Introduction to ActiveX Data Objects (ADO) .....................................................................7Connecting to a Database ....................................................................................................8Executing a SQL Query .......................................................................................................9Examining the Query Results ............................................................................................10Closing the Database Session ............................................................................................11Working with Text Files ....................................................................................................12Reading from a File ...........................................................................................................13Writing to a File .................................................................................................................14Summary............................................................................................................................15Review Questions ..............................................................................................................16Exercise: Retrieving External Data....................................................................................17

Creating New Procedures .......................................................................................................1An Introduction to Procedures .............................................................................................2Comparing Subroutines and Functions................................................................................3Understanding the Subroutine Syntax .................................................................................4Understanding the Function Syntax.....................................................................................5Creating a New Procedure ...................................................................................................6Adding the Base Steps for a New Procedure .......................................................................7Declaring the Procedure.......................................................................................................8Defining an Argument .........................................................................................................9Setting Return Values ........................................................................................................10Handling Errors..................................................................................................................11Making a Procedure Available ..........................................................................................12Using a Procedure Locally.................................................................................................13Associating a Procedure with a Test Object ......................................................................14Registering a Procedure with an Object Class...................................................................15Overriding an Existing Object Method..............................................................................16Using the Function Definition Generator ..........................................................................17

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 7: 23319158-Advanced-QTP-9-2

Unregistering a Procedure .................................................................................................18Building a Library..............................................................................................................19Creating a Library File Using a Standard Text Editor.......................................................20Opening the Function Library Editor.................................................................................21Associating a Library.........................................................................................................22Associating a Function Library with a Test.......................................................................23Using a Procedure ..............................................................................................................24Using a Procedure in a Script ............................................................................................25Using a Procedure in a Recovery Scenario........................................................................26Requirements for Recovery Scenario Procedures..............................................................27Summary............................................................................................................................28Review Questions ..............................................................................................................29Exercise: Creating New Procedures ..................................................................................30

Handling QuickTest Exceptions .............................................................................................1Overview of Exceptions.......................................................................................................2Handling Positive and Negative Test Data ..........................................................................3Benefits of Exception Handling...........................................................................................4An Overview of the Recovery Scenario Wizard..................................................................5Types of Recovery Scenarios ..............................................................................................6Using Recovery Scenarios for Exception Handling ............................................................7Viewing the Recovery Scenarios for a Test.........................................................................8Handling Exceptions Programmatically ..............................................................................9Using Conditional Statements ...........................................................................................10Using Exit Statements........................................................................................................11VBScript Exit Statements ..................................................................................................12The Exit Statements ...........................................................................................................13Using the On Error Resume Next Statement .....................................................................14Summary............................................................................................................................15Review Questions ..............................................................................................................16Exercise: Handling Negative and Positive Test Data ........................................................17Exercise: Handling Exceptions Programmatically ............................................................21

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 8: 23319158-Advanced-QTP-9-2

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 9: 23319158-Advanced-QTP-9-2

Introduction

1-1

1Introduction

Purpose

This course covers the EXPERT VIEW inQuickTest Professional 9.2. This course explains how to create steps that work with dynamic objects and data, use VBScript conditional and looping statements to control the flow of tests and components, and use DATA TABLE methods and database Connection objects to retrieve external data.

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 use the advanced features of QuickTest Professional 9.2.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 10: 23319158-Advanced-QTP-9-2

Course Objectives1-2

Introduction

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

• Use constants and variables in tests.

• Identify when programmatic descriptions are useful.

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

• Retrieve data from application objects.

• Describe and use various VBScript looping statements.

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

• Create scripts that access data from external sources.

• Create new subroutines and functions.

• Create and associate a library of functions.

• Use the FUNCTION LIBRARY editor.

• Identify when to handle exceptions programmatically.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 11: 23319158-Advanced-QTP-9-2

Introduction

Course Outline 1-3

Course Outline

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�This lesson introduces scripting in EXPERT VIEW. In this lesson, you work with VBScript and QuickTest objects and methods.

• Lesson 3: Using Expert View�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.

• Lesson 4: Retrieving Object Properties�This lesson covers the skills and knowledge needed to retrieve object properties and use that information in scripts.

• Lesson 5: Working with Dynamic Objects�This lesson explains how to use programmatic descriptions for dynamic objects in QuickTest scripts.

• Lesson 6: Using VBScript Operators, Statements, and Functions�This lesson explains how to use VBScript operators, statements, and functions. It covers the functionality of the VBScript language.

• Lesson 7: Working with Dynamic Data�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.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 12: 23319158-Advanced-QTP-9-2

Course Outline1-4

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 13: 23319158-Advanced-QTP-9-2

Introduction

Instructional Methods 1-5

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 14: 23319158-Advanced-QTP-9-2

Class Introductions1-6

Introduction

Class Introductions• Your name

• Your company

• Your job

• How you have used QuickTest Professional

• Your personal objectives

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 15: 23319158-Advanced-QTP-9-2

Introduction

Class Introductions 1-7

Instructor Notes

SlidesSome 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 setupThe 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.-- The following is true for all Flight Reservation tests:. . . . Each test will launch the Flight 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 FlightReservation.tsr located in C:\Training\QTP92Advanced\objects.-- Shortcuts on the desktop are provided for the following:. . . . QuickTest Professional application . . . . Mercury Tours application . . . . Flight Reservation application . . . . Apache start server . . . . Apache stop server See merc-training for detailed setup instructions, Flight Reservation installation files, and test files.

Classroom deliveryEach exercise includes an analysis section followed by a class discussion. Instructors may choose to conduct the analyses in any of the following ways:-- 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.-- 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 slower or faster), reconvene the class for discussion when most are done.-- Have participants perform the entire exercise independently including skipping the analysis questions if they choose.-- Conduct the analysis questions altogether as a class.In other words, use your judgment of the needs of the participants as your guide.

Sample solutions are provided for each exercise. At the end of each exercise, you may choose a successful participant to present 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 16: 23319158-Advanced-QTP-9-2

Sample Test Applications1-8

Introduction

Sample Test Applications

Figure 0-1 Mercury Tours and Flight Reservation

QuickTest Professional has been set up on your workstation with two sample test applications that can be accessed from the desktop: the Mercury Tours web application and the Flight Reservation Windows application.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

AK
Highlight
Page 17: 23319158-Advanced-QTP-9-2

Introduction to Expert View

2-1

2Introduction to Expert View

Purpose�This lesson introduces you to scripting in EXPERT VIEW. In this lesson, you work with VBScript and QuickTest objects and methods.

Objectives

After completing this lesson, you will be able 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 common test objects and methods used in QuickTest Professional. HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 18: 23319158-Advanced-QTP-9-2

An Overview of Expert View2-2

Introduction to Expert View

An Overview of Expert View

Figure 2-1 Expert View

In QuickTest Professional, tests and components are coded in VBScript. EXPERT VIEW displays the VBScript code that corresponds to the steps that you create for your test or component. �You have already worked with KEYWORD VIEW in the basic course. This course covers the EXPERT VIEW.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 19: 23319158-Advanced-QTP-9-2

Introduction to Expert View

Using Expert View 2-3

Using Expert ViewEXPERT 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 20: 23319158-Advanced-QTP-9-2

Translating Steps Between Views2-4

Introduction to Expert View

Translating Steps Between Views

Figure 2-2 Keyword View and Expert View

KEYWORD VIEW and EXPERT VIEW represent a step in a test script differently.

In KEYWORD VIEW:

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

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

In EXPERT VIEW:

• Each step is a single line of VBScript code.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 21: 23319158-Advanced-QTP-9-2

Introduction to Expert View

An Overview of VBScript 2-5

An Overview of VBScriptVBScript 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.

• It defines tests and components in QuickTest Professional.

• It helps automate tasks in Windows environments.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 22: 23319158-Advanced-QTP-9-2

An Overview of Object Oriented Programming2-6

Introduction to Expert View

An Overview of Object Oriented ProgrammingOOP 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 applying brakes.

The types of objects are defined by classes. For example, the bicycle object is an instance of the class of bicycles. In this case, all bicycle objects share the same properties and methods. However, at any moment, the values of properties of all bicycle objects and the method that is executed could be different for each bicycle.

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 object contains the actual values for the properties.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 23: 23319158-Advanced-QTP-9-2

Introduction to Expert View

Objects in QuickTest 2-7

Objects in QuickTest

Figure 2-3 Object Repository

The OBJECT REPOSITORY displays all the objects in the application under test (AUT) that are used in the test while recording or added to the OBJECT REPOSITORY directly.

The OBJECT REPOSITORY displays the following:

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 24: 23319158-Advanced-QTP-9-2

Classes in QuickTest2-8

Introduction to Expert View

Classes in QuickTest

Figure 2-4 Object Model Reference

The types of objects that QuickTest can recognize and work on are set by the following default classes defined in QuickTest:

• STANDARD WINDOWS

• ACTIVE X

• VISUAL BASIC

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 25: 23319158-Advanced-QTP-9-2

Introduction to Expert View

Common Windows and Web Objects 2-9

Common Windows and Web ObjectsTable 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 Objects

WINDOWS

DIALOG

BROWSER

PAGE

IMAGE

Common Interactive Objects

WINBUTTON

WINCHECKBOX

WINCOMBOBOX

WINEDIT

WINLIST

WINRADIOBUTTON

LINK

WEBCHECKBOX

WEBEDIT

WEBLIST

WEBRADIOGROUP

Table 2-1. Common Windows and Web Objects

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 26: 23319158-Advanced-QTP-9-2

Common Methods in QuickTest2-10

Introduction to Expert View

Common Methods in QuickTest

Figure 2-5 Steps in Expert View

Several interactive objects in Windows and Web applications share the following common methods:

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

• SETSECURE: Decrypts a provided encrypted value.

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

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 27: 23319158-Advanced-QTP-9-2

Introduction to Expert View

Elements of a QuickTest Script 2-11

Elements of a QuickTest Script

Figure 2-6 QuickTest Script

To view the elements of a QuickTest script, open a test or component in EXPERT VIEW. The elements of a QuickTest test or component may be comprised of:

• Calls to methods in QuickTest objects: These may be application objects or utility 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).

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 28: 23319158-Advanced-QTP-9-2

Guidelines for VBScript Syntax2-12

Introduction to Expert View

Guidelines for VBScript SyntaxAll 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.

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

• Use a dot to access methods for an object.

• Use either upper or lower casing because VBScript does not differentiate between the two. However, use consistent casing for easy readability.

Example

Example

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

AK
Highlight
Page 29: 23319158-Advanced-QTP-9-2

Introduction to Expert View

More Guidelines for VBScript Syntax 2-13

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

• When the result value is needed, use parentheses for method calls.�Need parentheses around CheckPoint("My Property").

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

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

Example

Example

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 30: 23319158-Advanced-QTP-9-2

Discussion: Match the Steps from the Views2-14

Introduction to Expert View

Discussion: Match the Steps from the Views

Figure 2-7 Test Steps

Match the steps from KEYWORD VIEW with their corresponding representation in EXPERT VIEW.

Instructor Notes

Use this slide as an opportunity to elicit student understanding (including misunderstanding) and support peer-teaching. Each 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 B2 matches C3 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 31: 23319158-Advanced-QTP-9-2

Introduction to Expert View

Discussion: Write the VBScript Code 2-15

Discussion: Write the VBScript Code

Figure 2-8 Steps in Keyword View

Given the code snippet from KEYWORD VIEW, as shown in Figure 2-8, write the equivalent VBScript code for EXPERT VIEW.

The equivalent VBScript code for EXPERT VIEW is:

Dialog("Login").WinEdit("Agent Name:").Set "training"_____________

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

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

SetSecure "4291f98e3c01c6a5b1d224577e28909ee31c41cd"______________

Dialog("Login").WinButton("OK").Click_____________________________

What does this code do?

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 32: 23319158-Advanced-QTP-9-2

Summary2-16

Introduction to Expert View

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 33: 23319158-Advanced-QTP-9-2

Introduction to Expert View

Review Questions 2-17

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

_______________________________________________________________

_______________________________________________________________

2. What is the difference between the KEYWORD VIEW and the EXPERT VIEW?

In KEYWORD VIEW, an icon-based table displays the information about each step or component. In EXPERT VIEW, each step is a single line of VBScript code._____

_______________________________________________________________

3. How does QuickTest Professional relate to OOP?

OOP is a programming approach based on a hierarchy of objects and classes. QuickTest objects are categorized by class. Each class in QuickTest Professional defines the properties and methods available to its objects. Therefore, QuickTest Professional follows the object-oriented programming approach.____________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 34: 23319158-Advanced-QTP-9-2

Review Questions2-18

Introduction to Expert View

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 35: 23319158-Advanced-QTP-9-2

Using Expert View

3-1

3Using Expert View

Purpose�This lesson describes how to work in EXPERT VIEW. The lesson provides an exercise that enables students to type, run, and debug a script using EXPERT VIEW.

Objectives

After completing this lesson, you will be able 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.HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 36: 23319158-Advanced-QTP-9-2

Adding New Steps in Expert View3-2

Using Expert View

Adding New Steps in Expert ViewTo 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 37: 23319158-Advanced-QTP-9-2

Using Expert View

Categories in the Step Generator 3-3

Categories in the Step Generator

Figure 3-1 Step Generator Categories

The QuickTest Professional STEP GENERATOR feature enables you to add steps in a test. To access STEP GENERATOR, from the QuickTest Professional menu bar, select INSERT → STEP GENERATOR.

Steps are organized according to the following three categories:

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 38: 23319158-Advanced-QTP-9-2

Defining a Step3-4

Using Expert View

Defining a Step

Figure 3-2 Completed Steps for Insertion

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

• CATEGORY: Select the desired category.

• OBJECT or LIBRARY: Select the desired test object or utility object. If the step category is LIBRARY, select the desired library.

• OPERATION: Select the desired object method or function.

• ARGUMENTS: After the object method or function is selected, the argument table is 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 39: 23319158-Advanced-QTP-9-2

Using Expert View

Inserting a Step Manually 3-5

Inserting a Step ManuallyYou 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 cursor position.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 40: 23319158-Advanced-QTP-9-2

Using Statement Completion3-6

Using Expert View

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

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

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

When you type an object followed by a dot, QuickTest uses an auto complete list to display the child objects and methods for that object.

When you type a method, QuickTest uses an auto complete list to display the arguments for that method.

Table 3-1. Statement CompletionHP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 41: 23319158-Advanced-QTP-9-2

Using Expert View

Expanding VBScript Syntax 3-7

Expanding VBScript Syntax

Figure 3-3 Keyword Completion Options

The auto-expand VBScript syntax feature returns VBScript statements that match the characters you type. To trigger the auto-expand VBScript syntax feature, type a few initial characters in EXPERT VIEW and then press the spacebar. The following options are possible:

• If only one statement fits the criteria, QuickTest enters that statement automatically.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 42: 23319158-Advanced-QTP-9-2

Launching Context-Sensitive Help3-8

Using Expert View

Launching Context-Sensitive Help

Figure 3-4 Context-Sensitive Help

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 43: 23319158-Advanced-QTP-9-2

Using Expert View

An Overview of the With Statement 3-9

An Overview of the With Statement

Figure 3-5 VBScript Code using With Statement

The VBScript With statement enables you to perform a series of operations on an object.

You use the With statement to group related steps together and make a script easier to read. For example, using With grouping enables you to quickly see all the activities occurring on the same Web page.

Figure 3-5 shows two code snippets that perform the same operations. The second code snippet uses the With statement to group steps.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 44: 23319158-Advanced-QTP-9-2

Applying the With Statement to a Test3-10

Using Expert View

Applying the With Statement to a Test

Figure 3-6 Edit Menu

To convert a script so that sequential steps related to the same object are grouped together by using a With statement, from QuickTest Professional menu bar, select EDIT → ADVANCED → APPLY “WITH” TO SCRIPT.

To return the script to the previous format, from the QuickTest Professional menu bar, select EDIT → ADVANCED → REMOVE “WITH” STATEMENTS. �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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 45: 23319158-Advanced-QTP-9-2

Using Expert View

Using Debugging Features 3-11

Using Debugging FeaturesAfter 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.

• Execute single steps: Enables you to pinpoint the exact step where an error might occur.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 46: 23319158-Advanced-QTP-9-2

Finding Syntax Errors3-12

Using Expert View

Finding Syntax Errors

Figure 3-7 Syntax Errors

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 CHECK menu.For each error found in your script, the INFORMATION pane displays the following information:�If the INFORMATION pane is not visible, from the QuickTest Professional menu bar, select VIEW → INFORMATION.

• DETAILS: Provides the description of the error. For example, if you open a conditional block with an IF statement but do not close it with an END IF statement, the description of the error is: EXPECTED 'END IF'.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 47: 23319158-Advanced-QTP-9-2

Using Expert View

Executing a Script from a Specific Step 3-13

Executing a Script from a Specific Step

Figure 3-8 Run from Step Option

The RUN FROM STEP option enables you to execute a QuickTest script starting from any step in the script.

To use this option, place the cursor at the desired starting step and from the Quick Test Professional menu bar, select AUTOMATION → RUN FROM STEP.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 48: 23319158-Advanced-QTP-9-2

Adding Breakpoints3-14

Using Expert View

Adding Breakpoints

Figure 3-9 Breakpoints

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. To set a breakpoint:

1. Place the cursor on the step where you want to add the breakpoint.

2. From the QuickTest Professional menu bar, select DEBUG → INSERT/REMOVE BREAKPOINT. The breakpoint symbol appears on the left margin of the script.

3. QuickTest pauses the run session when it reaches the breakpoint before executing 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 49: 23319158-Advanced-QTP-9-2

Using Expert View

Executing Single Steps 3-15

Executing Single Steps

Figure 3-10 Step Commands

The QuickTest Professional DEBUG menu provides step commands that enable you to execute a single step of a script. These commands are available when a run session is paused.�A run session may be paused because of a breakpoint, a run error, or because it was paused manually.

The available step commands are:

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 50: 23319158-Advanced-QTP-9-2

Summary3-16

Using Expert View

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 51: 23319158-Advanced-QTP-9-2

Using Expert View

Review Questions 3-17

Review QuestionsNow 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 statements that match the characters you type. __________________________

_______________________________________________________________

3. What does the VBScript With statement do?

The VBScript With statement enables you to perform a series of operations on an object. __________________________________________________________

_______________________________________________________________

4. What is a breakpoint?

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

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 52: 23319158-Advanced-QTP-9-2

Exercise: Using Expert View3-18

Using Expert View

Exercise: Using Expert View

In this exercise you learn how to add new steps in EXPERT VIEW for the Mercury Tours application. The activities here are divided into the following sections:

• Part 1: Translate the given KEYWORD VIEW steps into EXPERT VIEW code.

• Part 2: Open and run an existing script.

• Part 3: Type new steps in the script.

• Part 4: Run the updated script.

Instructor Notes

Exercise introductionStudents 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 setupIn 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 53: 23319158-Advanced-QTP-9-2

Using Expert View

Exercise: Using Expert View 3-19

Part 1: Translate the Given Keyword View Steps into Expert View Code

Figure 3-11 SearchFlights Action

Figure 3-11 displays the steps of an action in KEYWORD VIEW. Type the VBScript code that corresponds to the steps shown in Figure 3-11.

Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("passCount").Select "2" ______________________

_______________________________________________________________

Browser("Welcome: Mercury Tours").Page("Find a Flight: Mercury").WebList("fromPort").Select "London" __________________

_______________________________________________________________

Browser("Welcome: Mercury Tours").Page("Find a Flight: 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 ___________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 54: 23319158-Advanced-QTP-9-2

Exercise: Using Expert View3-20

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 ____________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 55: 23319158-Advanced-QTP-9-2

Using Expert View

Exercise: Using Expert View 3-21

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.

Figure 3-12 LoginLogout Test

4. Select START → PROGRAMS → MERCURY TOURS → START SERVER to start the Apache Web server.

5. Verify that the START SERVER window displays the following line: Apache/1.3.17 <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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 56: 23319158-Advanced-QTP-9-2

Exercise: Using Expert View3-22

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.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 57: 23319158-Advanced-QTP-9-2

Using Expert View

Exercise: Using Expert View 3-23

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

Figure 3-14 New SearchFlights Action

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

When you type BROWSER, what happens?

The name, “Welcome: Mercury Tours”, fills automatically in EXPERT VIEW because it is the only browser item set up for this test. ____________________

_______________________________________________________________

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 58: 23319158-Advanced-QTP-9-2

Exercise: Using Expert View3-24

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 59: 23319158-Advanced-QTP-9-2

Working with Object Properties

4-1

4Working with Object Properties

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

Objectives

After completing this lesson, you will be able 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.HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 60: 23319158-Advanced-QTP-9-2

Retrieving Object Property Values4-2

Working with Object Properties

Retrieving Object Property ValuesRetrieving 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. For example, the return date of a flight must be later than the departure date.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 61: 23319158-Advanced-QTP-9-2

Working with Object Properties

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

Run-Time Object Properties Versus Test Object Properties

Figure 4-1 Run-Time Objects and Test Objects

QuickTest stores the objects of your application as test objects in the OBJECT REPOSITORY. The object repository stores the property values for each object at the time the object was added. During a run session, QuickTest uses these property values to 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 62: 23319158-Advanced-QTP-9-2

Retrieving the Property Values4-4

Working with Object Properties

Retrieving the Property ValuesTo retrieve the value of a property from an object in your script:

1. Identify the desired property.

2. Call GetROProperty or GetTOProperty.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 63: 23319158-Advanced-QTP-9-2

Working with Object Properties

Identifying a Property 4-5

Identifying a Property

Figure 4-2 Object Spy and Properties Help

You can review the properties associated with any object in a test by reviewing the test object in the OBJECT REPOSITORY. You can also review the properties by using the OBJECT SPY on the run-time object.

If you are unsure which property to use, access HELP for the object and navigate to the 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 64: 23319158-Advanced-QTP-9-2

Calling GetROProperty or GetTOProperty4-6

Working with Object Properties

Calling GetROProperty or GetTOPropertyAll 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:

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 65: 23319158-Advanced-QTP-9-2

Working with Object Properties

Setting Object Properties: Calling SetTOProperty 4-7

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:<object>.SetTOProperty(<property>)(<value>)

The following example shows how to use the SetTOProperty method:

Note: You can set values only for properties that are included in the test object description in the OBJECT REPOSITORY.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 66: 23319158-Advanced-QTP-9-2

An Overview of Constants and Variables4-8

Working with Object Properties

An Overview of Constants and VariablesYou 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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 67: 23319158-Advanced-QTP-9-2

Working with Object Properties

Declaring Constants and Variables 4-9

Declaring Constants and VariablesYou 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:

�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 value, which can be reassigned at any time.

The following example shows how to use the Dim statement:

�The above example sets two variables to values retrieved from the run-time application. Variable declaration is optional in VBScript. If you do not declare a variable, you can create the variable when you assign a value to it. Declaring a variable explicitly enhances code readability and maintenance. Dim statements are often grouped at the beginning of a script. The CInt function and other conversion functions are covered in lesson 6, “Using VBScript Operators, Statements, and Functions.”

By common convention, constants and variables are named for easy differentiation. A 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 is to use a prefix that indicates the type of value to be stored.

�The mic prefix stands for Mercury Interactive Corporation.

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 68: 23319158-Advanced-QTP-9-2

Viewing the Run-Time Value of a Variable4-10

Working with Object Properties

Viewing the Run-Time Value of a Variable

Figure 4-3 Variables Tab

When you pause a run session by using breakpoints for a script, the values of the 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 VIEWER to display it.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 69: 23319158-Advanced-QTP-9-2

Working with Object Properties

Adding the Reporter Utility Object 4-11

Adding the Reporter Utility Object

Figure 4-4 ReportEvent and Test Results

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 70: 23319158-Advanced-QTP-9-2

Using the Reporter Utility Object4-12

Working with Object Properties

Using the Reporter Utility ObjectUse 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:

�In the above example the EventStatus is micDone. The ReportStepName is OrderNumber. Details indicates the value of the string.

Note: Use the & operator to concatenate strings. �This course discusses the & operator, with string manipulation functions, in lesson 6, “Using VBScript Operators, Statements, and Functions.”

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 71: 23319158-Advanced-QTP-9-2

Working with Object Properties

Filtering Events 4-13

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

• rfDisableAll: Displays nothing in the test results.

Setting the Reporter.Filter property to rftEnableAll or rftDisableAll turns checkpoint reporting on and off. Checkpoint results are reported as passes or fails, which means there are no done or warning results from checkpoints.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 72: 23319158-Advanced-QTP-9-2

Discussion: Output in Results4-14

Working with Object Properties

Discussion: Output in Results

Figure 4-5 ReportEvent and Filter

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

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 BlockA: The output is: pass1, fail1, done1, and warning1. There is no output after the filter is set to rDisableAll.

Second Code BlockA: The output is: fail3 and warning3.

Final Code BlockA: The output is: fail4.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 73: 23319158-Advanced-QTP-9-2

Working with Object Properties

Summary 4-15

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 74: 23319158-Advanced-QTP-9-2

Review Questions4-16

Working with Object Properties

Review QuestionsNow 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 numeric, string, and object values that are dynamic. ______________________

_______________________________________________________________

3. Which method will you use in QuickTest Professional to retrieve the value of the enabled property of a button in an application?

You use the GetROProperty command in QuickTest Professional to retrieve the value of the enabled property of a button. ______________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 75: 23319158-Advanced-QTP-9-2

Working with Object Properties

Exercise: Working with Object Properties 4-17

Exercise: Working with Object Properties

In this exercise, you enhance an existing script for the Flight Reservation application to retrieve run-time object properties.

The exercise consists of the following parts:

• Part 1: Open and run an existing script.

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

• Part 3: Type new steps in the script.

• Part 4: Run the updated script.

Part 1: Open and Run an Existing Script

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

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.

Instructor Notes

Exercise introductionStudents modify the ObjectProperties test to insert new steps that retrieve and output run-time object properties.

Specific objectivesAt 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 setupIn 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. -- The ObjectPropertiesSolution test provides a sample solution.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 76: 23319158-Advanced-QTP-9-2

Exercise: Working with Object Properties4-18

Working with Object Properties

Figure 4-6 The ObjectProperties Test

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

4. Click OK.

Note: This test is set up to launch the AUT when a run session is started and to exit the AUT at the end of the session.HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 77: 23319158-Advanced-QTP-9-2

Working with Object Properties

Exercise: Working with Object Properties 4-19

Figure 4-7 Test Results

How many times did each action run?

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

_______________________________________________________________

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 78: 23319158-Advanced-QTP-9-2

Exercise: Working with Object Properties4-20

Working with Object Properties

Figure 4-8 Flight Reservation

Answer the following questions to determine the steps that need to be added to the script.

1. What is the logical name of the object in the Flight Reservation application that contains the total price information? What is the logical name of the object that contains the order number information? What are the class names for these objects? How did you find your answer?

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 79: 23319158-Advanced-QTP-9-2

Working with Object Properties

Exercise: Working with Object Properties 4-21

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

Window(“Flight Reservation”).WinEdit(“Total:”).GetROProperty “text”

Window(“Flight Reservation”).WinEdit(“Order No:”).GetROProperty “text” _________________________________________________________

3. Do you use a constant or a variable to store the information you retrieved? Explain your answer.

Use a variable because the value is determined at run-time and changes with each iteration. ________________________________________________________

_______________________________________________________________

Write the VBScript statements for declaring and setting the values of your constants or variables.

Dim vTotalPrice, vOrderNumber __________________________________

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 80: 23319158-Advanced-QTP-9-2

Exercise: Working with Object Properties4-22

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

_______________________________________________________________

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

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

Instructor Notes

Here is sample code to retrieve the total price and order number:

‘Retrieve the total price and order number.Dim vTotalPrice, vOrderNumbervTotalPrice = Window("Flight Reservation").WinEdit("Total:").GetROProperty("text")vOrderNumber = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")

‘Output the information in the test results.Reporter.ReportEvent micDone, "TotalPrice", "The new itinerary's total price is " & vTotalPriceReporter.ReportEvent micDone, "OrderNumber", "The new itinerary's order number is " & vOrderNumber

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 81: 23319158-Advanced-QTP-9-2

Working with Object Properties

Exercise: Working with Object Properties 4-23

Figure 4-9 Action Drop Down List

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

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

Part 4: Run the Updated Script

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

2. Run the updated test. Viewr the TEST RESULTS at the completion of the test.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 82: 23319158-Advanced-QTP-9-2

Exercise: Working with Object Properties4-24

Working with Object Properties

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 83: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

5-1

5Working with Dynamic Objects

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

Note: The technique of “programmatic descriptions” is also called “descriptive programming.”

Objectives

After completing this lesson, you will be able 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 84: 23319158-Advanced-QTP-9-2

Dynamic Objects Versus Static Objects5-2

Working with Dynamic Objects

Dynamic Objects Versus Static Objects

Figure 5-1 Dynamic Objects and Static Objects

Most applications consist of dynamic and static objects. Dynamic objects do not always exist in the same state in the application because they are created during run-time. Static objects always exist in the same state in the application.

Figure 5-1 shows navigation links in the left pane of a Web page. These links are static objects and remain unchanged every time the Web page loads. However, the objects in 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 85: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Review: Object Repository for Static Objects 5-3

Review: Object Repository for Static Objects

Figure 5-2 Object Repository

QuickTest Professional identifies the objects in your application and stores them in the OBJECT REPOSITORY.

The objects in the OBJECT REPOSITORY can be referenced by the steps of tests and components.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 86: 23319158-Advanced-QTP-9-2

Identifying Dynamic Objects5-4

Working with Dynamic Objects

Identifying Dynamic ObjectsUse 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 87: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Setting Dynamic Values in the Object Repository 5-5

Setting Dynamic Values in the Object Repository

Figure 5-3 Properties in the Object Repository

If an object is defined in the OBJECT REPOSITORY and has dynamic property values, you can set its values by:

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

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

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 88: 23319158-Advanced-QTP-9-2

Using Programmatic Descriptions5-6

Working with Dynamic Objects

Using Programmatic Descriptions

Figure 5-4 Using Programmatic Descriptions

You can instruct QuickTest to perform actions on an object without referring to the OBJECT REPOSITORY or to the name of the object. To do this, you provide QuickTest with a list of properties and values for identifying the objects on which you want to perform an action. This approach of providing QuickTest with a list of properties and values is called a programmatic description.

You use programmatic descriptions to:

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 89: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Building Programmatic Descriptions 5-7

Building Programmatic DescriptionsThe 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 90: 23319158-Advanced-QTP-9-2

Identifying the Object Class5-8

Working with Dynamic Objects

Identifying the Object Class

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

To use programmatic descriptions for an object, you identify the class of the object by locating a similar dynamic object in the OBJECT REPOSITORY or by running the AUT 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 91: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Selecting Object Properties 5-9

Selecting Object Properties

Figure 5-6 Object Properties in Object Spy

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

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 92: 23319158-Advanced-QTP-9-2

Creating a Programmatic Description5-10

Working with Dynamic Objects

Creating a Programmatic DescriptionYou can create a programmatic description in the following ways:

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

• Using the Description object.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 93: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Specifying Property and Value Pairs 5-11

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:

The following example shows how to use a variable and the concatenation (&) operator to specify a dynamic description for the WEBCHECKBOX name property:

The following example shows how to use both a variable and a regular expression:

�In this case, the name of the WebCheckBox must contain the given itinerary number.

The following example shows how to use property and value pairs to identify a dynamic object uniquely:

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.

Example

Example

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 94: 23319158-Advanced-QTP-9-2

Specifying Property and Value Pairs5-12

Working with Dynamic Objects

The following example shows how to use programmatic description for dynamic objects in a hierarchy:

�In the above example, Browser is identified using programmatic descriptions, Therefore PAGE and WEBCHECKBOX must also be identified using programmatic descriptions.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 95: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Using the Description Object 5-13

Using the Description ObjectThe 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 objDescriptionSet 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.

2. Set property and value pairs in the Description object by using the following syntax: <description_object>.(<property1>).Value = <value1>...<description_object>.(<propertyX>).Value = <valueX>

3. Refer to the dynamic object with the following syntax:

<object_hierarchy>.<object_class>(<description_object>)

The following example shows how the Description object is used to create a programmatic description:

Note: In the above example, you can replace the “flight_378” string with a string variable whose value is set at run-time.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 96: 23319158-Advanced-QTP-9-2

Retrieving Child Objects5-14

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:

After you retrieve the Collection object, use the Count method to retrieve the number of child objects. The index can then be used to access individual child objects.

The following example shows how to use the Count method to return the total number of objects in a collection of child objects:

Note: The first object in the collection of child objects is always numbered 0.

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 97: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Additional Uses of Programmatic Descriptions 5-15

Additional Uses of Programmatic DescriptionsIn 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 often based on run-time information, you may want to avoid adding this object to the repository. In this case, you identify the object by constructing its programmatic description and bypass the OBJECT REPOSITORY.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 98: 23319158-Advanced-QTP-9-2

Summary5-16

Working with Dynamic Objects

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 99: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Review Questions 5-17

Review QuestionsNow 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. _____________________________________________

_______________________________________________________________

_______________________________________________________________

2. What is a Description object?

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

_______________________________________________________________

3. What are the steps involved in building a programmatic description?

The steps involved in building a programmatic description are identifying the object class, selecting the object properties, and creating a programmatic description._

_______________________________________________________________

_______________________________________________________________

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

The additonal uses of programmatic descriptions are performing the same operation on a list of objects with similar properties, performing an operation on a static object that you choose based on run-time information, and bypassing OBJECT REPOSITORY._____________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 100: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Objects5-18

Working with Dynamic Objects

Exercise: Working with Dynamic Objects

In this exercise, you update an existing script for the Flight Reservation application so that the script works for dynamic objects.

The exercise consists of the following parts:

• Part 1: Open and run an existing script.

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

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

• Part 4: Correct the script by using programmatic descriptions.

Instructor Notes

Exercise introductionStudents 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 objectivesAt 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 setupIn addition to the general requirements listed in Course Overview, this exercise has the following requirements for each student computer:-- Each student computer is supplied a base test, FaxOrder, to begin the exercise. -- Each student computer is supplied the DynamicObjectsSolution test, which provides a sample solution.

Instructor Notes

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 101: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Exercise: Working with Dynamic Objects 5-19

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.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 102: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Objects5-20

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

The run message displayed is: “CANNOT FIND THE “FAX NUMBER” OBJECT’S PARENT "FAX ORDER NO. 63”...______________________________________

_______________________________________________________________

_______________________________________________________________

b) QuickTest Professional cannot locate a test object in the AUT. Which object is QuickTest Professional looking for and why is this object not in the AUT?

QuickTest Professional is looking for a dialog box with a text property value of "FAX ORDER NO. 63" but the dialog box is named dynamically in the AUT. ___

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 103: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Exercise: Working with Dynamic Objects 5-21

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.

Figure 5-8 Fax Order Dialog Box

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

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 104: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Objects5-22

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

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

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?

Use GetROProperty to retrieve the “text” value of the WINEDIT field named “ORDER NO:” ____________________________________________________

_______________________________________________________________

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

_______________________________________________________________

4. What is the name of the property that specifies the title of a dialog box object? How did you find your answer?

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]* _____________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 105: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Exercise: Working with Dynamic Objects 5-23

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

Part 3: Correct the Test by Updating Object Repository

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

2. Create a new OBJECT REPOSITORY:

a) From the QuickTest Professional menu bar, select RESOURCES → OBJECT REPOSITORY MANAGER to open the OBJECT REPOSITORY MANAGER dialog box.

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.

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 OrderNumberOrderNumber = Window("Flight Reservation").WinEdit("Order No:").GetROProperty("text")

' Fax the order (using programmatic descriptions.Window("Flight Reservation").Dialog("text:=Fax Order No. " &OrderNumber).WinObject("attached_text:=Fax Number:").Type DataTable("Fax_Number",dtLocalSheet)

Window("Flight Reservation").Dialog("text:=Fax Order No. " &OrderNumber).WinButton("text:=&Send").Click

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 106: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Objects5-24

Working with Dynamic Objects

Figure 5-9 The Object Repository Manager

3. To update the dynamic object description:

a) Locate the FAX ORDER dialog box in the OBJECT REPOSITORY MANAGER.

b) Update the appropriate property value to use the regular expression that you 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 107: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Exercise: Working with Dynamic Objects 5-25

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.

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

6. Run the test.

The test should complete successfully.

Note: Check with your instructor if problems persist.

Part 4: Correct the Test by Using Programmatic Descriptions

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

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

3. To ensure that the new test uses the original Object Repository:

Note: You must use the version of Object Repository that you used in Part 1.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 108: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Objects5-26

Working with Dynamic Objects

Figure 5-10 The Associate Repositories Dialog Box

d) Close the ASSOCIATE REPOSITORY dialog box.

4. Within the test, click EXPERT VIEW.

5. In EXPERT VIEW, from the action list, select the ORDER_FAX_FLIGHT action to edit it.

6. Update the code to use the programmatic description that you wrote in Part 2.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 109: 23319158-Advanced-QTP-9-2

Working with Dynamic Objects

Exercise: Working with Dynamic Objects 5-27

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?

Use a programmatic description for the WINOBJECT object. Look for object properties in OBJECT REPOSITORY or in HELP to find an appropriate property to match. __________________________________________________________

__________________________________________________________________

__________________________________________________________________

You need to change WinObject("Fax Number") to WinObject("attached_text:=") ___________________________________

_______________________________________________________________

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

Yes, in the immediate next line. _____________________________________

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

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 110: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Objects5-28

Working with Dynamic Objects

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 111: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

6-1

6Using VBScript Operators,Statements and Functions

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

Objectives

After completing this lesson, you will be able 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 112: 23319158-Advanced-QTP-9-2

Introducing VBScript Operators, Statements and Functions6-2

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 113: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Commonly Used VBScript Operators 6-3

Commonly Used VBScript OperatorsOperators 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 114: 23319158-Advanced-QTP-9-2

Comparison Operators6-4

Using VBScript Operators, Statements and Functions

Comparison OperatorsComparison 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 equivalenceThis operator returns true if two variables refer to the same object.

Table 6-1. Comparison Operators

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 115: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Arithmetic Operators 6-5

Arithmetic OperatorsArithmetic operators are used to perform mathematical calculations.

Table 6-2 lists some commonly used arithmetic operators.

Operator Description

+, - Addition, subtraction

*, / Multiplication, division

\ Integer divisionThis operator rounds off all numbers before performing division.

Mod Modulus arithmetic This operator returns the remainder from a division.

- Negation

^ Exponentiation

& String concatenation

Table 6-2. Arithmetic Operators

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 116: 23319158-Advanced-QTP-9-2

Logical Operators6-6

Using VBScript Operators, Statements and Functions

Logical OperatorsLogical operators are used to perform logical operations.

Table 6-3 lists some commonly used logical operators.

The following example shows how to use the And operator:

�In the above example, after inserting an order in the Flight application, you use the And operator to report a “pass” to the result when the INSERT ORDER button disables and the UPDATE ORDER button enables.

The following example shows how to use the Or operator:

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

Operator Description

And Conjunction

Or Disjunction

Not Negation

Table 6-3. Logical Operators

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 117: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Logical Operators 6-7

The following example shows how to use the Not operator:

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

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 118: 23319158-Advanced-QTP-9-2

Evaluating Operator Precedence6-8

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.

Note: When operators are of the same precedence order, evaluate the operators from left to right. You can use parentheses to clarify or to override operator precedence.�For clarity and readability of code, it is generally recommended that you use parentheses rather than relying on operator precedence.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 119: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Discussion: Value of Expressions 6-9

Discussion: Value of Expressions

Figure 6-1 Discussion: Sample VBScript Operators

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

Instructor Notes

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

1 + 2 * 3A: 7.

1 + 2 * 3 > (1 + 2) * 3A: 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”.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 120: 23319158-Advanced-QTP-9-2

Commonly Used VBScript Statements6-10

Using VBScript Operators, Statements and Functions

Commonly Used VBScript StatementsA 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.

Note: Detailed information on VBScript statements can be found in VBSCRIPT REFERENCE of QUICKTEST PROFESSIONAL HELP.�You have already learned how to declare constants and variables in lesson 4, Declaring Constants and Variables.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 121: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Using Statements for Commenting 6-11

Using Statements for CommentingCommenting 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 (‘):

Note: When you comment at the end of a line, use a colon (:) before the Rem statement. You do not need to do this for the apostrophe.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 122: 23319158-Advanced-QTP-9-2

Commenting Multiple Lines6-12

Using VBScript Operators, Statements and Functions

Commenting Multiple Lines

Figure 6-2 Commenting Multiple Lines

To comment multiple lines, from the QuickTest Professional menu bar, select EDIT → ADVANCED → COMMENT BLOCK.

To uncomment multiple lines of code, from the QuickTest Professional menu bar, select EDIT → ADVANCED → UNCOMMENT BLOCK.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 123: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Using the Indent Outdent Feature 6-13

Using the Indent Outdent Feature

Figure 6-3 Indent and Outdent Commands

You can indent and outdent individual statements or blocks of statements using the INDENT and OUTDENT commands. This feature makes your test actions more readable and easier to maintain.

To indent a statement(s), selecting the statement(s) and from the QuickTest Professional menu bar, select EDIT → ADVANCED → INDENT.

To outdent a statement(s), select the statement(s) and from the QuickTest Professional menu bar, select EDIT → ADVANCED → OUTDENT.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 124: 23319158-Advanced-QTP-9-2

Using the Set Statement6-14

Using VBScript Operators, Statements and Functions

Using the Set StatementThe 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:

�In the above example, the objDescription variable points to a new Description object. The objDetailsImages variable points to a collection of objects. objDetailsImages is later set to Nothing so that the collection of objects can be released.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 125: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Using Statements for Conditional Logic 6-15

Using Statements for Conditional LogicConditional 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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 126: 23319158-Advanced-QTP-9-2

The If ... Then Conditional Statement6-16

Using VBScript Operators, Statements and Functions

The If ... Then Conditional Statement

Figure 6-4 Using If ... Then Statements

Use an IF ... THEN statement to evaluate if a condition is true or false, and depending on the result, to specify one or more statements to run.

Use an ELSEIF clause to evaluate multiple cases of a test. An IF ... THEN statement can have none or several ELSEIF clauses.

Use the final ELSE clause in a script to handle all the cases that do not satisfy any of the previous conditions set in the script. �Later in this lesson, you also use the Select Case statement to accomplish the same objective as that of the IF ... THEN statement. HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 127: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

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

Using the If ... Then Statement for Custom Checkpoints

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

Use the IF ... THEN statements to insert custom checkpoints in a script.

Note: Insert a custom checkpoint to perform scripts validations.

Custom checkpoints help retrieve or calculate an actual value from a script, which are then compared with an expected value. If the values match, the Reporter object is used to report success. Otherwise, the Reporter object reports failure.�The CCur function in Figure 6-5 is covered, along with other conversion functions, later in this lesson.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 128: 23319158-Advanced-QTP-9-2

Using the Select Case Statement6-18

Using VBScript Operators, Statements and Functions

Using the Select Case StatementThe 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:

The Select Case statement is more efficient than the IF ... THEN statement, particularly if the test expression requires evaluation of a condition.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 129: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Discussion: Output in Results 6-19

Discussion: Output in Results

Figure 6-6 Discussion: Sample VBScript Statements

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

Instructor Notes

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

A: The results show that the test passed, and displays the text “intMatchItem = 3”. HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 130: 23319158-Advanced-QTP-9-2

Commonly Used VBScript Functions6-20

Using VBScript Operators, Statements and Functions

Commonly Used VBScript FunctionsA 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

Note: Detailed information on VBScript functions can be found in VBSCRIPT REFERENCE of QUICKTEST PROFESSIONAL HELP.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 131: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Manipulating Strings with Functions 6-21

Manipulating Strings with FunctionsVBScript 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.

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

Function Description

String Accepts a number and a character. Returns a string created with the character that is repeated the given number of times.

Len Returns the number of characters in a given string.

InStr Accepts two strings and returns whether the second is contained within the first or not.

Left, Right Accept a string and a length, and return a substring of the given length from the beginning or the end of the original string.Return the original string if the given number is larger than the actual length of the string.

Mid Accepts a string, a starting point, and a length. Returns a substring of the given length from the starting point of the original string.

Split Accepts a string and a delimiter character, and returns an array of substrings as shown:

Table 6-4. Functions for String Manipulation

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 132: 23319158-Advanced-QTP-9-2

Manipulating Dates with Functions6-22

Using VBScript Operators, Statements and Functions

Manipulating Dates with FunctionsVBScript 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.

DateAdd Adds the specified number of years, months, weeks, days, hours, minutes, or seconds to the given date.

DateDiff Returns the number of years, months, weeks, days, hours, minutes, or seconds between the two given dates. The return value is negative if the first date is after the second date.

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

Table 6-5. Functions for Date Manipulation

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 133: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Converting Data Types with Functions 6-23

Converting Data Types with FunctionsVBScript 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.

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

Note: VBScript also provides the functions IsNumeric and IsDate functions to check the type of an expression.

Function Description

CInt Converts an expression to an integer value, as shown:

CBool Converts an expression to a Boolean value. If the expression evaluates to a nonzero value, CBool returns true; otherwise, CBool returns false.

CStr Converts an expression to a string value.

CDate Converts an expression to a date value.

CCur Converts an expression to a currency value, as shown:

Table 6-6. Functions for Type Conversion

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 134: 23319158-Advanced-QTP-9-2

Discussion: Value of Each Expression6-24

Using VBScript Operators, Statements and Functions

Discussion: Value of Each Expression

Figure 6-7 Discussion: Sample VBScript Functions

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

Instructor Notes

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

Len(“abcd” & String(5, “e”))A: 9.

Right(Left(“IG_CRT_Special”, 6), 3)A: “CRT”.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 135: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Functions for Opening Dialog Boxes 6-25

Functions for Opening Dialog BoxesVBScript 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.

Table 6-7. InputBox and MsgBox Functions

The following example shows the code to prompt a user for the birth year and then calculates the birthday:

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

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.

MsgBox Displays a given message in a new dialog box, waits for the user to click a button, and returns the button that is clicked.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 136: 23319158-Advanced-QTP-9-2

Summary6-26

Using VBScript Operators, Statements and Functions

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 137: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

Review Questions 6-27

Review QuestionsNow 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?

The Set statement enables to assign a variable to point to an object. _________

4. What does the Split function do?

The Split function accepts a string and a delimiter character, and returns an array of substrings._____________________________________________________

_______________________________________________________________

5. What are two VBScript functions that invoke dialog boxes to interact with users?

InputBox and MsgBox are the VBScript functions that invoke dialog boxes to interact with users. ________________________________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 138: 23319158-Advanced-QTP-9-2

Exercise: Using VBScript Operators, Statements and Functions6-28

Using VBScript Operators, Statements and Functions

Exercise: Using VBScript Operators, Statements and Functions

In this exercise, you determine the VBScript operators, statements, and functions required for a specific purpose. You update a test by using VBScript and other features in QuickTest Professional.

The exercise consists of the following parts:

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

Instructor Notes

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

Specific objectivesAt the end of this exercise, students should be able to:- Use the ChildObjects method to retrieve dynamic objects.- Write VBScript code that has correct syntax and that works as desired.

- Write an IF ... THEN statement to control the flow of your test and use string manipulation functions.

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

Technical setupIn 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, VBScript., with which to begin the exercise. The test works as described in Part 1.-- The VBScriptSolution1 and VBScriptSolution2 tests provide sample solutions.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 139: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

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

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.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 140: 23319158-Advanced-QTP-9-2

Exercise: Using VBScript Operators, Statements and Functions6-30

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

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

__________________________________________________________________

b) How do you retrieve a count of the above objects on the itinerary page?

Use the ChildObject method to retrieve the collection of all objects on the page with the desired characteristics. Use the Count method on the collection to retrieve the number of the objects. _____________________________________________

__________________________________________________________________

__________________________________________________________________

c) How do you save the count of the original number of itineraries to compare it to a later count?

Use a variable to save the count of the original number of itineraries and to compare it to a later count. ____________________________________________________

__________________________________________________________________

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.

__________________________________________________________________

__________________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 141: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

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

__________________________________________________________________

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.

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"

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 142: 23319158-Advanced-QTP-9-2

Exercise: Using VBScript Operators, Statements and Functions6-32

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 objTableDesc("name").Value = strNameSet objBookedTables = Browser("Welcome: Mercury Tours").Page("Itinerary: Mercury Tours").ChildObjects(objTableDesc)

Retrieves the WebTable objects that have the same name as the first check box of the itinerary. ________________________________________________________

__________________________________________________________________

iv. Code 4:If objBookedTables.Count <> 1 ThenReporter.ReportEvent micWarning , "objBookedTables.Count", objBookedTables.Count&" were found when one object should have been found."

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

v. Code 5:ElsestrBookedFirstItinerary = 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”)

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 143: 23319158-Advanced-QTP-9-2

Using VBScript Operators, Statements and Functions

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

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”. Another way to do this is to use the MonthName VBScript function available in HELP.___________________________________________________________

_______________________________________________________________

_______________________________________________________________

Part 2: Update the Script to Confirm that the Number of Itineraries Increases by One After a Flight Purchase

1. Within the Mercury Tours application, cancel all itineraries except one.

Note: You can do this by clicking CANCEL ALL RESERVATIONS and then adding a new purchase, or by selecting all the itineraries except one and clicking CANCEL CHECKED RESERVATIONS.

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

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 144: 23319158-Advanced-QTP-9-2

Exercise: Using VBScript Operators, Statements and Functions6-34

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 itinerary was booked.

5. Run and debug the updated test.

6. Confirm that your script works even when the Application Under Test (AUT) starts with no itineraries created.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 145: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

7-1

7Working with Dynamic Data

Purpose�This lesson explains how to retrieve data from application objects and work with the retrieved data. The lesson discusses the VBScript looping statements and how DATA TABLES are used to iterate actions.

Objectives

After completing this lesson, you will be able 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 146: 23319158-Advanced-QTP-9-2

Dynamic Data Versus Static Data7-2

Working with Dynamic Data

Dynamic Data Versus Static Data

Figure 7-1 Dynamic Data and Static Data

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

For static data, you hard-code specific test values in your scripts or in data sheets.

For dynamic data, you retrieve data from the run-time application or from an external 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 147: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Retrieving Data from Objects 7-3

Retrieving Data from ObjectsYou 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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 148: 23319158-Advanced-QTP-9-2

The WinComboBox and WinList Objects7-4

Working with Dynamic Data

The WinComboBox and WinList Objects

Figure 7-2 The WinComboBox and WinList Objects

The WINCOMBOBOX objects represent lists in Windows applications. The WINLIST objects represent information lists in Windows applications.

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

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:

�In the above example, the first item on the list is always numbered 0.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 149: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

The WebList Object 7-5

The WebList Object

Figure 7-3 The WebList Object

The WEBLIST object represents lists in Web applications.

Figure 7-3 shows the DEPARTING FROM object, which is of type WEBLIST.

You retrieve data from a WEBLIST object the same as t for a WINLIST object. The 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.

�In the above example, the first item on the list is always numbered 1.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 150: 23319158-Advanced-QTP-9-2

The WebTable Object7-6

Working with Dynamic Data

The WebTable Object

Figure 7-4 The WebTable Object

WEBTABLE objects represent information tables in Web applications, as shown in Figure 7-4.

You retrieve data from a WEBTABLE object by using the GetCellData, ColumnCount, and RowCount methods.

The following example shows how to retrieve data using the GetCellData and RowCount methods for a WEBTABLE object:

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

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 151: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Overviewing Looping Statements 7-7

Overviewing Looping StatementsOften 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

• DO...LOOP

These statements specify different looping durations.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 152: 23319158-Advanced-QTP-9-2

Using the For...Next Statement7-8

Working with Dynamic Data

Using the For...Next StatementThe 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:

The Step keyword is used to define how the counter increments for the FOR...NEXT statement.

The following example shows how to use the Step keyword to define the counter variable increments:

�A common practice using the FOR...NEXT statement is to name the loop counter variable i. When loops are nested, the next loop counter is named j, then k and so on.

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 153: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Using the While...Wend Statement 7-9

Using the While...Wend StatementThe 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:

In the above example, the script loops through values of a list until the desired value is found or until the script exhausts the list. At the end of the loop, the bFound keyword indicates whether the item is found or not. If found, the intFountItemIndex keyword indicates the location in the list of the desired item.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 154: 23319158-Advanced-QTP-9-2

Using the Do...Loop Statement7-10

Working with Dynamic Data

Using the Do...Loop StatementSimilar 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 155: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Using the Continuation and Termination Conditions 7-11

Using the Continuation and Termination Conditions

Figure 7-5 Continuation and Termination Conditions

You can use the DO...LOOP statement to provide a continuation condition or a termination condition. The condition depends on personal preference.

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 condition. The example on the right shows the use of the DO UNTIL statement for repeating a set of statements until a condition becomes True. This is called a termination condition.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 156: 23319158-Advanced-QTP-9-2

Evaluation at the Start Versus at the End7-12

Working with Dynamic Data

Evaluation at the Start Versus at the End

Figure 7-6 Evaluation at the Start Versus at the End

With the DO...LOOP statement; you can evaluate a condition at the start or at the end of a loop. Evaluating a condition at the end of the loop ensures that the loop is always executed at least once.

In Figure 7-6, after execution of the code on the left, i = 0. After execution of the code on the right, i = 1.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 157: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

An Overview of Nested Loops 7-13

An Overview of Nested LoopsEach 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:

�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 for each row. Therefore, the WebTable passes the row as an argument to the ColumnCount method.

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

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 158: 23319158-Advanced-QTP-9-2

Review: Using a Data Table to Manage Iterations7-14

Working with Dynamic Data

Review: Using a Data Table to Manage Iterations

Figure 7-7 Test Settings and Action Call Properties Windows

In addition to using the VBScript loop statements, you can also iterate a test, action, or component by using data sheets of DATA TABLE.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 159: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Populating a Data Table Dynamically 7-15

Populating a Data Table Dynamically

Figure 7-8 Dynamically Populating the Data Table

Instead of hard-coding data in a data sheet before a run session, you can retrieve the data from an application at run-time and store it in the DATA TABLE.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 160: 23319158-Advanced-QTP-9-2

Commonly Used Data Table Methods7-16

Working with Dynamic Data

Commonly Used Data Table Methods

Figure 7-9 Data Table Methods

Use the Step Generator to insert the following common methods used to work with the DATA TABLE:

• 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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 161: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Commonly Used Data Table Methods 7-17

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

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

• Value: To retrieve or assign data into a cell in a DATA TABLE object.

The following example shows how to use the Value method to get data from the data sheet and set the data into a specified cell of the data sheet:

Value is the default method of the DATA TABLE object. Therefore, in the above example, DataTable(“My Column Name”) is equivalent to DataTable.Value(“My Column Name”).

Example

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 162: 23319158-Advanced-QTP-9-2

Summary7-18

Working with Dynamic Data

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 163: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Review Questions 7-19

Review QuestionsNow 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. __________________

_______________________________________________________________

3. What does the GetSheet method in the DATA TABLE object do?

The GetSheet method is used to retrieve specific data sheets for further processing.

_______________________________________________________________

4. Which property is used to retrieve or assign data into a cell in a DATA TABLE object?

Use the Value property to retrieve or assign data into a cell in a DATA TABLE object.

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 164: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Data7-20

Working with Dynamic Data

Exercise: Working with Dynamic Data

In this exercise, you update a test script so that it no longer uses hard-coded data but uses data retrieved dynamically from the application.

The exercise consists of the following parts:

• Part 1: Review the existing script.

• Part 2: Analyze the requirements.

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

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

Instructor Notes

Exercise introductionStudents complete the DynamicData test by filling in two empty actions to achieve the desired objective.

Specific objectivesAt 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 setupIn 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, DynamicData to begin the exercise. -- The DynamicDataSolution test provides a sample solution.

Instructor Notes

Reconvene the class after this point to discuss the answers.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 165: 23319158-Advanced-QTP-9-2

Working with Dynamic Data

Exercise: Working with Dynamic Data 7-21

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?

Each action is executed once during a run session. _______________________

3. Between which two cities are the passengers traveling?

The passengers are traveling from New York to Paris. ____________________

Part 2: Analyze the Requirements

You need to update the script so that it:

• Retrieves the options for departure and arrival cities from the application at run-time.

• Tests that a flight can be purchased from three departure cities to three different arrival cities.

Answer the following questions to break down the requirements for this test case.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 166: 23319158-Advanced-QTP-9-2

Exercise: Working with Dynamic Data7-22

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.

_______________________________________________________________

_______________________________________________________________

Part 3: Update the Script for the First Objective

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

2. Update the test with code necessary to achieve this objective.

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

Part 4: Update the Script for the Second Objective

1. Update the test with the code necessary to validate purchases for each combination of departure and arrival cities.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 167: 23319158-Advanced-QTP-9-2

Retrieving External Data

8-1

8Retrieving External Data

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

Objectives

After completing this lesson, you will be able 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.HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 168: 23319158-Advanced-QTP-9-2

Using External Data Sources8-2

Retrieving External Data

Using External Data Sources

Figure 8-1 External Data Sources

You may want to test an application for different data sets. For example, you may want 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 169: 23319158-Advanced-QTP-9-2

Retrieving External Data

Importing and Exporting Data from Microsoft Excel 8-3

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 170: 23319158-Advanced-QTP-9-2

Using the DataTable.ImportSheet Method8-4

Retrieving External Data

Using the DataTable.ImportSheet Method

Figure 8-2 Microsoft Excel Data Source

Use the DataTable.ImportSheet method to import a worksheet of a Microsoft Excel file to a sheet in the run-time data log. In Figure 8-2, the imported data is stored in the DATASET1 worksheet of the file MERCTOURS_TESTDATA.XLS into the QuickTest Professional DATA TABLE for the GETDATA action.

After the data is imported from a Microsoft Excel file into DATA TABLE, use the DATA TABLE to drive the iterations of an action.

Use the data in the first row of the Microsoft Excel worksheet as column names for the 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 171: 23319158-Advanced-QTP-9-2

Retrieving External Data

Using the DataTable.ExportSheet Method 8-5

Using the DataTable.ExportSheet Method

Figure 8-3 Microsoft Excel Data Log

Export the data saved in the run-time data table to Microsoft Excel if you want to access the data in another QuickTest Professional test or component.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 172: 23319158-Advanced-QTP-9-2

Working with Databases8-6

Retrieving External Data

Working with DatabasesThe 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 173: 23319158-Advanced-QTP-9-2

Retrieving External Data

Introduction to ActiveX Data Objects (ADO) 8-7

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 174: 23319158-Advanced-QTP-9-2

Connecting to a Database8-8

Retrieving External Data

Connecting to a DatabaseTo 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:

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.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 175: 23319158-Advanced-QTP-9-2

Retrieving External Data

Executing a SQL Query 8-9

Executing a SQL QueryAfter 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:

�In the above example, FLIGHTS : TABLE (containing 4514 rows) is queried for all rows with SAN FRANCISCO as the departure city.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 176: 23319158-Advanced-QTP-9-2

Examining the Query Results8-10

Retrieving External Data

Examining the Query ResultsAfter 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 the SQL query.

• Fields(“MyColumn”) or Fields.Item(“MyColumn”).Value: These methods return the value saved in the specified column of the current record in the RecordSet object.

The following example shows how to use the properties and methods of the RecordSet object:

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.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 177: 23319158-Advanced-QTP-9-2

Retrieving External Data

Closing the Database Session 8-11

Closing the Database SessionAfter 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:

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 178: 23319158-Advanced-QTP-9-2

Working with Text Files8-12

Retrieving External Data

Working with Text FilesYou can store the test data for your application in a text file.

Use the FileSystemObject object to read data into the QuickTest script.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 179: 23319158-Advanced-QTP-9-2

Retrieving External Data

Reading from a File 8-13

Reading from a FileUse 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.

• ReadLine: Reads from a TextStream object until a newline character is encountered and returns a string.

• ReadAll: Reads an entire TextStream object and returns a string. This method is not recommended for large files.

The following example shows how to use the OpenTextFile method:

In the above example, the OpenTextFile method in the FileSystemObject object returns the TextStream object, strText.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 180: 23319158-Advanced-QTP-9-2

Writing to a File8-14

Retrieving External Data

Writing to a FileUse 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.

The following example shows how to use the CreateTextFile method:

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 181: 23319158-Advanced-QTP-9-2

Retrieving External Data

Summary 8-15

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 182: 23319158-Advanced-QTP-9-2

Review Questions8-16

Retrieving External Data

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

The methods used to import and export data to a Microsoft Excel file are: ImportSheet and ExportSheet. ____________________________________

_______________________________________________________________

3. What does the Close method do?

The Close method closes a database session. ___________________________

4. What are the methods of the TextStream object used for reading from a text file?

The methods of the TextStream object used for reading text from a text file are: Read, ReadLine, and ReadAll. ______________________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 183: 23319158-Advanced-QTP-9-2

Retrieving External Data

Exercise: Retrieving External Data 8-17

Exercise: Retrieving External Data

In this exercise, you update a script to retrieve test data from a Microsoft Excel file, MercTours_TestData.xls and a Microsoft Access file, MercTours_TestData.mdb.

The exercise consists of the following parts:

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

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

Part 1: Import Data from a Microsoft Excel File

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

Instructor Notes

Exercise introductionStudents 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 setupIn 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 C:\Training\QTP92Advanced\data folder. It contains the worksheet DataSet1.-- Provide the students with the Access database, MercTours_TestData.mdb. The database exists in the C:\Training\QTP92Advanced\data folder. -- Create a data source named MercTours_TestData on the student workstation. The data source name should point to MercTours_TestData.mdb.

Note-- The ExternalDataSolution1 test provides a sample solution for Part 1 of this exercise.-- The ExternalDataSolution1 test provides a sample solution for Part 2 of this exercise.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 184: 23319158-Advanced-QTP-9-2

Exercise: Retrieving External Data8-18

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.

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

Note: Check with your instructor if problems persist.

Part 2: Import Data from a Microsoft Access File

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 with the name MYEXTERNALDATAACCESS.

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

Update the GETDATA action. ________________________________________

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

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 185: 23319158-Advanced-QTP-9-2

Retrieving External Data

Exercise: Retrieving External Data 8-19

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") ______________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

6. Where will you store the results returned by the queries?

In the DATA TABLE of the GetData action. _____________________________

Write the VBScript code to store the list of departure cities.

i = 1

Do While Not objDepartureCities.EOF

DataTable.GetSheet(dtLocalSheet).SetCurrentRow i

DataTable("Departure_Cities", dtLocalSheet) = objDepartureCities.Fields("City")

objDepartureCities.MoveNext

i + 1

Loop

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 186: 23319158-Advanced-QTP-9-2

Exercise: Retrieving External Data8-20

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

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

8. Use code to update the test so that you can retrieve data from the Microsoft Access database.

9. Run and debug the updated test.

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

Note: Check with your instructor if problems persist.HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 187: 23319158-Advanced-QTP-9-2

Creating New Procedures

9-1

9Creating New Procedures

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

Objectives

After completing this lesson, you will be able 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 188: 23319158-Advanced-QTP-9-2

An Introduction to Procedures9-2

Creating New Procedures

An Introduction to ProceduresA 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 scenarios.

The following are the two types of procedures in VBScript:

• Subroutines

• Functions

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 189: 23319158-Advanced-QTP-9-2

Creating New Procedures

Comparing Subroutines and Functions 9-3

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

Accepts arguments True True

Can call other procedures True True

Can call itself True True

Table 9-1. Subroutines and Functions

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 190: 23319158-Advanced-QTP-9-2

Understanding the Subroutine Syntax9-4

Creating New Procedures

Understanding the Subroutine SyntaxYou 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 AEnd 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:

�A subroutine can be marked as public or private. You will learn about public and private procedures, in more detail, later in this lesson.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 191: 23319158-Advanced-QTP-9-2

Creating New Procedures

Understanding the Function Syntax 9-5

Understanding the Function SyntaxYou 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:

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 192: 23319158-Advanced-QTP-9-2

Creating a New Procedure9-6

Creating New Procedures

Creating a New ProcedureAfter 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 193: 23319158-Advanced-QTP-9-2

Creating New Procedures

Adding the Base Steps for a New Procedure 9-7

Adding the Base Steps for a New Procedure

Figure 9-1 A New Procedure

Building a procedure involves adding steps to a procedure in a script. Add steps in a script by using one of the following methods:

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 194: 23319158-Advanced-QTP-9-2

Declaring the Procedure9-8

Creating New Procedures

Declaring the Procedure

Figure 9-2 Procedure Declaration

After creating the code for a procedure, declare the procedure. Declaring a procedure depends on if the procedure is a subroutine or a function.

Note: Mark the end of a procedure with the appropriate ending keywords, as shown in Figure 9-2.�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. - Select the desired lines and press the TAB key. HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 195: 23319158-Advanced-QTP-9-2

Creating New Procedures

Defining an Argument 9-9

Defining an Argument

Figure 9-3 Procedure Arguments

After declaring a procedure, identify the values that the procedure will need passed in from the calling script. Type these values in the script as argument variables for the procedure. For example, after creating a procedure for log in, pass a user name and password to this procedure so that the procedure can log in by using these input values.

Use the ByVal keyword to prevent a procedure from changing the value of the variable passed into it, as shown in Figure 9-3. By default, QuickTest Professional uses the reference keyword, ByRef, to pass arguments to the procedure. The ByRef keyword enables a procedure to assign the argument variable to a new value.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 196: 23319158-Advanced-QTP-9-2

Setting Return Values9-10

Creating New Procedures

Setting Return Values

Figure 9-4 Setting Return Values

After building a new procedure, the procedure might be expected to return a value based on the operation it performs. For example, the login procedure is expected to return a variable that indicates whether or not the login succeeds.

Return a value from a function by assigning the function name to the desired value, as shown in Figure 9-4.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 197: 23319158-Advanced-QTP-9-2

Creating New Procedures

Handling Errors 9-11

Handling Errors

Figure 9-5 Error Handling

Enhance a procedure to handle alternate application under test states and to validate arguments.

Use the IF ... THEN statement to test the existence of the error dialog box and use the Exit statement to abort a procedure, if required, as shown in Figure 9-5.�Error handling and Exit statements are covered in more detail in lesson 10, “Managing QuickTest Professional Exception Handling”.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 198: 23319158-Advanced-QTP-9-2

Making a Procedure Available9-12

Creating New Procedures

Making a Procedure AvailableUse 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 199: 23319158-Advanced-QTP-9-2

Creating New Procedures

Using a Procedure Locally 9-13

Using a Procedure Locally

Figure 9-6 QuickTest Script and Step Generator

To use a procedure locally in the same script in which it is defined, add the procedure definition code to the current script.

After adding the procedure to the script, use the procedure either by typing its name 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 200: 23319158-Advanced-QTP-9-2

Associating a Procedure with a Test Object9-14

Creating New Procedures

Associating a Procedure with a Test ObjectWhen 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.

To register a procedure for use in a business component, you use a library file to create the procedure and register it in the library file.�Library files are discussed later in this lesson.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 201: 23319158-Advanced-QTP-9-2

Creating New Procedures

Registering a Procedure with an Object Class 9-15

Registering a Procedure with an Object ClassUse 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:

After associating a procedure with a test object class, the procedure remains registered with the object class until it is unregistered explicitly or until the next QuickTest Professional run session begins.

Note: To be registered with an object class, the procedure that you define must have an object as its first argument.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 202: 23319158-Advanced-QTP-9-2

Overriding an Existing Object Method9-16

Creating New Procedures

Overriding an Existing Object MethodUse 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:

�You use the registered SetWithDebug procedure whenever the Set method is called for a WEBEDIT object.

Note: To override an existing object method, the procedure you define must have an object as its first argument, and the remaining arguments should match the arguments of the original method.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 203: 23319158-Advanced-QTP-9-2

Creating New Procedures

Using the Function Definition Generator 9-17

Using the Function Definition Generator

Figure 9-7 Function Definition Generator

QuickTest provides a FUNCTION DEFINITION GENERATOR, which enables you to generate definitions for new user-defined functions and add header information to them.

To open the FUNCTION DEFINITION GENERATOR:

1. Ensure that the function library or test where you want to insert the function definition is the active document.

2. From the QuickTest Professional menu bar, select INSERT → FUNCTION DEFINITION GENERATOR. The FUNCTION DEFINITION GENERATOR dialog box 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 204: 23319158-Advanced-QTP-9-2

Unregistering a Procedure9-18

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:

You should unregister a procedure in the same context in which the procedure was registered. If a procedure is registered within a QuickTest Professional action, unregister it in the same action. Similarly, if a procedure is registered within a QuickTest Professional library file, unregister the procedure in the same library file.

Example

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 205: 23319158-Advanced-QTP-9-2

Creating New Procedures

Building a Library 9-19

Building a LibraryBuild 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.

There are several ways of associating a library file to a test.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 206: 23319158-Advanced-QTP-9-2

Creating a Library File Using a Standard Text Editor9-20

Creating New Procedures

Creating a Library File Using a Standard Text Editor

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

A QuickTest Professional library file is a text file that contains VBScript subroutines and functions. To create a library file:

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

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

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 207: 23319158-Advanced-QTP-9-2

Creating New Procedures

Opening the Function Library Editor 9-21

Opening the Function Library Editor

Figure 9-9 Library File Creation the Using Function Library Editor

QuickTest Professional has a built-in FUNCTION LIBRARY editor. The FUNCTION LIBRARY editor enables you to create and edit function libraries that contain VBScript functions and subroutines.

You can create, open, and work on multiple function libraries simultaneously. Each 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 208: 23319158-Advanced-QTP-9-2

Associating a Library9-22

Creating New Procedures

Associating a Library

Figure 9-10 Library Association

After creating a library, associate the library with the script where you intend to use the procedure defined in the library file.

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

1. From the QuickTest Professional menu bar, select SETTINGS → TEST SETTINGS → RESOURCES to open the RESOURCES tab.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 209: 23319158-Advanced-QTP-9-2

Creating New Procedures

Associating a Function Library with a Test 9-23

Associating a Function Library with a Test

Figure 9-11 Associate Function Library with a Test

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

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

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 210: 23319158-Advanced-QTP-9-2

Using a Procedure9-24

Creating New Procedures

Using a ProcedureYou can use a procedure in:

• Scripts

• Recovery Scenarios

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 211: 23319158-Advanced-QTP-9-2

Creating New Procedures

Using a Procedure in a Script 9-25

Using a Procedure in a Script

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

The following options are available within the STEP GENERATOR:

• New library procedures are available under LIBRARY FUNCTIONS in the FUNCTIONS 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 212: 23319158-Advanced-QTP-9-2

Using a Procedure in a Recovery Scenario9-26

Creating New Procedures

Using a Procedure in a Recovery Scenario

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

To use a function in a recovery scenario:

1. From the RECOVERY SCENARIO MANAGER, select the desired scenario and click the EDIT button. The RECOVERY SCENARIO WIZARD appears. Click NEXT until you reach the RECOVERY OPERATIONS page.

2. Check the ADD ANOTHER RECOVERY OPERATION check box and click NEXT.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 213: 23319158-Advanced-QTP-9-2

Creating New Procedures

Requirements for Recovery Scenario Procedures 9-27

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.

If you choose to define the function while defining the recovery scenario, QuickTest Professional provides the default input values for you.

Trigger Input

Pop-up window The detected pop-up window object

Object state The detected object

Test run error • The object in the faulty step

• The method in the faulty step

• The arguments that were passed into the method

• The result that was returned by the method

Application crash The name and ID of the process that failed

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 214: 23319158-Advanced-QTP-9-2

Summary9-28

Creating New Procedures

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 215: 23319158-Advanced-QTP-9-2

Creating New Procedures

Review Questions 9-29

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

_______________________________________________________________

_______________________________________________________________

2. What is the difference between a subroutine and function?

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

_______________________________________________________________

_______________________________________________________________

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

Associating a procedure with test object enables you to use the procedure whenever you use an instance of the test object. _________________________________

_______________________________________________________________

4. How do you create a library file?

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

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 216: 23319158-Advanced-QTP-9-2

Exercise: Creating New Procedures9-30

Creating New Procedures

Exercise: Creating New Procedures

In this exercise, you test a new procedure and library file. You then update a script to use the new procedure.

The exercise consists of the following parts:

• Part 1: Analyze the requirements.

• Part 2: Define and test the new procedure in QuickTest Professional.

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

Instructor Notes

Exercise introductionStudents modify the NewProcedure test to calculate the number of current itineraries.

Specific objectivesAt 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 setupIn 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.

Instructor Notes

The instructor should reconvene the class after this point to discuss the answers.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 217: 23319158-Advanced-QTP-9-2

Creating New Procedures

Exercise: Creating New Procedures 9-31

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.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 218: 23319158-Advanced-QTP-9-2

Exercise: Creating New Procedures9-32

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

Function GetCurrentItineraryCount

Dim objCheckboxDesc, objCheckboxes

Set objCheckboxDesc = Description.Create()

objCheckboxDesc("type").Value = "checkbox"

GetCurrentItineraryCount = Browser("Welcome: Mercury Tours").Page("Itenerary: Mercury Tours").ChildObjects(objCheckboxDesc).Count

End Function __________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 219: 23319158-Advanced-QTP-9-2

Creating New Procedures

Exercise: Creating New Procedures 9-33

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.

3. Update the test so that the procedure is called in the appropriate places.

4. Run and debug the test.

Part 3: Create and Associate a New Library File by Using the Function Library Editor

1. To create a new function library file:

a) From the QuickTest Professional menu bar, select FILE → NEW → FUNCTION LIBRARY.

b) Cut the GETCURRENTITINERARYCOUNT procedure from the NEWPROCEDURE test and paste the procedure into the new function library file.

c) Save the function library file as MYLIBRARYFILE.QFL in the folder C:\TRAINING\QTP92ADVANCED\FUNCTION LIBRARY folder.

2. To associate the library file with QuickTest script:

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 220: 23319158-Advanced-QTP-9-2

Exercise: Creating New Procedures9-34

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 221: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

10-1

10Handling QuickTest Exceptions

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

Objectives

After completing this lesson, you will be able to:

• Describe exceptions in a test.

• Handle positive and negative test data.

• Use recovery scenarios for exceptions in a script.

• Handle exceptions programmatically.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 222: 23319158-Advanced-QTP-9-2

Overview of Exceptions10-2

Handling QuickTest Exceptions

Overview of Exceptions

Figure 10-1 Run Error Window

Unexpected events, errors, and application crashes during a test run can disrupt tests and distort test results. For example, during testing, an application error could occur. This error does not permit the automated test to navigate to the feature, screen, or module that 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 unexpected errors and events are called run errors or exceptions.

When the QuickTest Professional encounters an exception within a run session, it displays a RUN ERROR window. The RUN ERROR window provides the following 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 223: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Handling Positive and Negative Test Data 10-3

Handling Positive and Negative Test Data

Figure 10-2 Positive and Negative Test Data

As a tester, you test with positive and negative data to ensure that the AUT responds correctly to both types of data. For example, to test login functionality, you test the application with a correct set of user name and password, which is positive data. You also check that the application denies login and generates a specific exception message if you use an incorrect set of user name and password, which is negative data.

Negative data causes an AUT to generate an error message. While enhancing a positive test case to validate the application for negative data, it is common for QuickTest Professional to encounter exceptions. Exception handling ensures that the test runs without exception.�You can work with both negative and positive data in two ways: - 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 224: 23319158-Advanced-QTP-9-2

Benefits of Exception Handling10-4

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 225: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

An Overview of the Recovery Scenario Wizard 10-5

An Overview of the Recovery Scenario Wizard

Figure 10-3 Recovery Scenario Wizard

Create recovery scenarios to handle exceptions. QuickTest Professional provides the RECOVERY SCENARIO WIZARD, which guides you through the process of defining a recovery scenario. The process of defining a recovery scenario includes defining an unexpected event and recovering the run session of a test.

A recovery scenario consists of the following components:

• TRIGGER: Interrupts the run session of the test. For example, the test may be interrupted by a window that may pop up on the screen.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 226: 23319158-Advanced-QTP-9-2

Types of Recovery Scenarios10-6

Handling QuickTest Exceptions

Types of Recovery Scenarios

Figure 10-4 Types of Recovery Scenarios

The types of recovery scenarios are defined by the type of triggers. These triggers are provided in the QuickTest Professional RECOVERY SCENARIO WIZARD.

The following are the trigger events in RECOVERY SCENARIO WIZARD:

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 227: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Using Recovery Scenarios for Exception Handling 10-7

Using Recovery Scenarios for Exception Handling

Figure 10-5 Exception Handling by Using Recovery Scenario Wizard

It is possible that you may be unable to predict where an exception could occur in a script. In such cases, including exception handling statements in the script is not useful.

For these cases you use recovery scenarios to identify and handle unpredictable 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 228: 23319158-Advanced-QTP-9-2

Viewing the Recovery Scenarios for a Test10-8

Handling QuickTest Exceptions

Viewing the Recovery Scenarios for a Test

Figure 10-6 View Recovery Scenarios for a Test

The RECOVERY tab of the TEST SETTINGS dialog box displays a list of all recovery scenarios associated with the current test. You can associate additional recovery 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 scenario in the TEST SETTINGS dialog box.HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 229: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Handling Exceptions Programmatically 10-9

Handling Exceptions ProgrammaticallyIn 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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 230: 23319158-Advanced-QTP-9-2

Using Conditional Statements10-10

Handling QuickTest Exceptions

Using Conditional Statements

Figure 10-7 Conditional Statement

Figure 10-7 shows how conditional statements separate the code to be executed for positive or negative test data. The code between the Then and ELSE statements is executed only for negative test data. The code between the ELSE and End If statements is executed only for positive test data. All the code outside the If ... End If statements is executed for both positive and negative test data.

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 231: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Using Exit Statements 10-11

Using Exit Statements

Figure 10-8 Exit Statement

If a test has multiple steps to be executed for positive test data and only a few steps for negative test data, you can use an Exit statement to terminate a process for negative test data.

Figure 10-8 shows how to use conditional statements to identify negative test data. The code uses an ExitGlobalIteration statement so that the remainder of the code in this 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.

The two types of Exit statements are:

• VBScript Exit statements

• QuickTest Professional Exit statements

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 232: 23319158-Advanced-QTP-9-2

VBScript Exit Statements10-12

Handling QuickTest Exceptions

VBScript Exit Statements

Figure 10-9 VBScript Exit Statement

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

Figure 10-9 shows how to search for a specified item in a WINLIST object. The figure shows the VBScript Exit statement in the following contexts:

• The block of code on the left uses the Exit statement to terminate the DO ... WHILE loop as soon as the desired item is found.

• The block of code on the right is similar to that on the left, except that the context is within a function. The Exit statement helps to immediately return from the function after the desired item is found.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 233: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

The Exit Statements 10-13

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

Exit Statements for QuickTest Professional Actions and

Tests

Exit Statements for QuickTest Professional Components

and Business Process Tests

ExitActionIteration

Terminates the current iteration of the action. Proceeds to the next iteration (if any).

ExitComponentIteration

Terminates the current iteration of the component. Proceeds to the next iteration (if any).

ExitAction

Terminates the current action regardless of the existence of additional iterations. Proceeds to the next action, if any, in the test.

ExitComponent

Terminates the current component regardless of the existence of additional iterations. Proceeds to the next component, if any, in the business process test.

ExitGlobalIteration

Terminates the current iteration of the actions in a test. Proceeds to the next iteration, if any, of the test.

ExitTestIteration

Terminates the current iteration of the components in a business process test. Proceeds to the next iteration, if any, of the business process test.

ExitRun

Terminates the entire run of the test.

ExitTest

Terminates the entire run of the business process test.

Table 10-1. QuickTest Professional Exit Statements

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 234: 23319158-Advanced-QTP-9-2

Using the On Error Resume Next Statement10-14

Handling QuickTest Exceptions

Using the On Error Resume Next Statement

Figure 10-10 Using the On Error Resume Next Statement

The VBScript On Error Resume Next statement enables a script to continue processing even after an exception occurs. When a script encounters an exception, it simply ignores the current line and proceeds to the next line.

Use the On Error Resume Next statement to enable cleanup code to run entirely, even if exceptions occur.

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 example on the right shows how you can include custom exception handling by having the next statement check for an anticipated exception.

Note: The On Error Resume Next statement skips all the exceptions in a test including the ones that you do not anticipate.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 235: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Summary 10-15

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 236: 23319158-Advanced-QTP-9-2

Review Questions10-16

Handling QuickTest Exceptions

Review QuestionsNow 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 test runs successfully. It also enables you to test positive and negative test data.

_______________________________________________________________

3. What statement can be used to terminate a process if a test has multiple steps to be executed for positive test data and only a few steps for negative test data?

You can use an Exit statement to terminate a process if a test has multiple steps to be executed for positive test data and only a few steps for negative test data. __

_______________________________________________________________

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

The VBScript On Error Resume Next statement enables a script to continue processing even after an exception occurs. _____________________________

_______________________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 237: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Exercise: Handling Negative and Positive Test Data 10-17

Exercise: Handling Negative and Positive Test Data

In this exercise, you edit a script that validates positive and negative test data.

The exercise consists of the following parts:

• Part 1: Analyze the requirements.

• Part 2: Code and debug a script.

Instructor Notes

Exercise introductionStudents 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 setupIn 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, ValidateLogin, to begin the exercise. -- The NegativePositive test provides sample solution.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 238: 23319158-Advanced-QTP-9-2

Exercise: Handling Negative and Positive Test Data10-18

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.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 239: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Exercise: Handling Negative and Positive Test Data 10-19

Figure 10-12 Data Set with User Names and Passwords

If the user name or the password is invalid, you need to update the script to ensure that the script:

• Confirms that the proper error message is displayed and dismisses the exception.

• Skips to the next user name and password combination.

Which action or actions in the VALIDATELOGIN script do you need to update and why?

Update the VALIDATELOGIN action to pick user name and password from DATA TABLE and insert it into the application under test. _______________________

_______________________________________________________________

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 240: 23319158-Advanced-QTP-9-2

Exercise: Handling Negative and Positive Test Data10-20

Handling QuickTest Exceptions

Figure 10-13 Checks for Test Cases

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

Check with your instructor if problems persist.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 241: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Exercise: Handling Exceptions Programmatically 10-21

Exercise: Handling Exceptions Programmatically

In this exercise, you update the script so that it handles run errors programmatically.

The exercise consists of the following parts:

• Part 1: Analyze the requirements.

• Part 2: Code and debug a script.

Instructor Notes

Exercise introductionStudents modify the failing ExceptionHandling test so that it handles exceptions programmatically.This test uses the Web add-in.

Specific objectivesAt 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 setupIn 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, ExceptionHandling, to begin the exercise. -- The ExceptionHandlingSolution1 and ExceptionHandlingSolution2 tests provide sample solutions. The NoTomatoCans test uses a condition to intercept negative cases followed by an ExitAction statement. The NatKingCole test uses the On

Error Resume Next statement to skip to an exception handling the IF ... THEN statement when an error occurs.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 242: 23319158-Advanced-QTP-9-2

Exercise: Handling Exceptions Programmatically10-22

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.

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.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 243: 23319158-Advanced-QTP-9-2

Handling QuickTest Exceptions

Exercise: Handling Exceptions Programmatically 10-23

Figure 10-15 Data Set with Current and Retired Cities

If either the departure or the arrival city is invalid, you need to update the script to ensure that the script:

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

• Skips to the next departure-arrival combination.

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

Update the PURCHASEFLIGHT action to check that retired cities are not among the options in the application. Also update the CREATEPERMUTATIONS action to have 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. _______________________________________________________

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 244: 23319158-Advanced-QTP-9-2

Exercise: Handling Exceptions Programmatically10-24

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.

4. Run and debug the updated test.

Confirm in your test results that the PURCHASEFLIGHT action performed different checks depending on whether or not any cities were retired.

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

Check with your instructor if problems persist.

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 245: 23319158-Advanced-QTP-9-2

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)

2. How much do you agree with the following statements regarding the registration process and facility? (Please circle only one rating for each category):

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

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

On-line

Through a Resource Coordinator

Someone else registered me

Strongly Agree

Agree Neutral DisagreeStrongly Disagree

N/A

My registration was handled efficiently. 5 4 3 2 1 -The classroom/facilities were clean and well maintained.

5 4 3 2 1 on-site

The classroom equipment worked properly and effectively supported the class.

5 4 3 2 1 on-site

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

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 246: 23319158-Advanced-QTP-9-2

5. If you completed pre-work for this class, how helpful was it in preparing you for this class?

6. How would you rate your technical ability going into the class?

7. How would you rate your familiarity with the product going into the class?

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

9. How could the course materials be improved?

Very helpful Somewhat helpful I’m not sure Not very helpful Not helpful at all

5 4 3 2 1

5 - Highly technical

4 - Above average

3 - Average

2 - Below average

1 - Not at all technical

5 - I consider myself a product expert

4 - I have above average knowledge of the product

3 - I'm comfortable with common product functions

2 - I've used the product a little

1 - I've never used the product

Strongly Agree

Agree Neutral DisagreeStrongly Disagree

The objectives laid out in the course description were met.

5 4 3 2 1

The course materials were clearly written and easy to follow.

5 4 3 2 1

There was an appropriate amount of content - not too packed or too lean.

5 4 3 2 1

The lab exercises were well constructed and relevant. 5 4 3 2 1The graphics in the course materials were clear and effective.

5 4 3 2 1

I would recommend this course to others. 5 4 3 2 1

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 247: 23319158-Advanced-QTP-9-2

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

11. What suggestions do you have for the instructor?

12. How would you rate your overall experience with this class?

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

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.

Strongly Agree

Agree Neutral DisagreeStrongly Disagree

The instructor had a thorough knowledge of the course content.

5 4 3 2 1

The instructor encouraged participation from stu-dents.

5 4 3 2 1

The instructor was an effective communicator. 5 4 3 2 1The instructor conducted the class at an appropriate pace.

5 4 3 2 1

The instructor made the course relevant by using real-world examples.

5 4 3 2 1

I would recommend this instructor to others. 5 4 3 2 1

Excellent Good OK Needs Improvement Poor

5 4 3 2 1

I understood the course concepts,

and can apply most of them without

assistance

I understood the course concepts, can apply some

without assistance, but will need help

with others

I understood the course concepts, but will need help

applying them

I understood some of the course con-

cepts

I had a very hard time with this course

5 4 3 2 1HP S

oftware

Edu

catio

n - N

ot For

Duplic

ation

Page 248: 23319158-Advanced-QTP-9-2

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on

Page 249: 23319158-Advanced-QTP-9-2

QTP92Adv-Instruct-01B

HP Soft

ware E

duca

tion -

Not

For Dup

licati

on