Download - 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

Transcript
Page 1: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

QuickTest Professional – A Basic Guide This book covers the basic concepts of QuickTest Professional and its use to test your applications. In this book, you will learn about the step-by-step instructions to create, debug, and run tests, and to report defects detected during the testing process.

Page 2: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

2

Contents Chapter 1: About This Book .......................................................................................................................... 5

1.1 Objectives............................................................................................................................................ 5

1.2 Audience ............................................................................................................................................. 5

1.3 Contents .............................................................................................................................................. 5

Chapter 2: Getting Started ............................................................................................................................ 6

2.1 Introduction ........................................................................................................................................ 6

2.2 Why QTP? ............................................................................................................................................ 6

2.3 Features of QTP ................................................................................................................................... 6

Chapter 3: Installation of QTP ....................................................................................................................... 8

3.1 Installing QuickTest Professional ........................................................................................................ 8

Chapter 4: Testing with QTP ....................................................................................................................... 14

Chapter 5: Key Elements of the QTP Window ............................................................................................ 16

Chapter 6: Sample Applications .................................................................................................................. 19

6.1 Flight Reservation Application .......................................................................................................... 19

6.2 Mercury Tours Web Site ................................................................................................................... 20

Chapter 7: Working with Script in QTP ....................................................................................................... 22

7.1 Recording a Script ............................................................................................................................. 22

7.1.1 Normal Mode ............................................................................................................................. 23

7.1.2 Analog Mode .............................................................................................................................. 23

7.1.3 Low-level Recording Mode ........................................................................................................ 23

7.2 Running a Script ................................................................................................................................ 23

7.3 Saving a Script ................................................................................................................................... 24

Chapter 8: Synchronization Point ............................................................................................................... 25

8.1 Define Synchronization Point ............................................................................................................ 25

8.2 Examples ........................................................................................................................................... 25

Page 3: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

3

8.3 Default Synchronization Time in QTP ............................................................................................... 26

Chapter 9: Checkpoints ............................................................................................................................... 27

9.1 Define a Checkpoint .......................................................................................................................... 27

9.2 Types of Checkpoints ....................................................................................................................... 27

9.3 Checking Objects ............................................................................................................................... 28

9.4 Checking Pages .................................................................................................................................. 33

9.5 Checking Tables ................................................................................................................................. 35

9.6 Checking Text .................................................................................................................................... 38

9.7 Managing Checkpoints in Object Repository .................................................................................... 41

9.8 Running and Analyzing a Test with Checkpoints .............................................................................. 42

9.9 Performing a Check Using a Function ............................................................................................... 47

Chapter 10: Parameterization ..................................................................................................................... 50

10. 1 Parameterizing Tests ...................................................................................................................... 50

10.2 Why Parameterization? .................................................................................................................. 50

10.3 Defining a Data Table Parameter .................................................................................................... 50

10.4 Parameterization Using Regular Expression ................................................................................... 54

Chapter 11: Object Repository .................................................................................................................... 60

11.1 Introducing Test Objects and Object Repositories ......................................................................... 60

11.1.1 Test objects .............................................................................................................................. 60

11.1.2 Run-time objects ...................................................................................................................... 60

11.1.3 Object Repositories .................................................................................................................. 60

11.1.5 Local Object Repository ........................................................................................................... 61

11.2 Learning Objects in Your Application .............................................................................................. 61

11.3 Using Multiple Object Repositories ................................................................................................ 67

Chapter 12: Action ...................................................................................................................................... 71

Page 4: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

4

12.1 Creating an Action ........................................................................................................................... 71

12.2 Different Ways to Insert Calls to Actions ........................................................................................ 74

12.3 Parameterizing an Action ................................................................................................................ 75

Summary ..................................................................................................................................................... 78

Page 5: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

5

Chapter 1: About This Book

1.1 Objectives This book covers the basic concepts of Quick Test Professional and its use to test your applications. In this book, you will learn about the step-by-step instructions to create, debug, and run tests, and to report defects detected during the testing process. 1.2 Audience This book caters to the need of Test Engineers, Test Analysts, Test Consultants, Test Managers, and individuals who are keen to learn QTP.

1.3 Contents In this book, you will learn about:

• QTP and its features

• Installation of QTP

• Testing with QTP

• Key elements of the QTP window

• Sample applications

• Recording, running, and saving a script

• Synchronization point

• Checkpoints

• Parameterization

• Object repository

• Action

Page 6: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

6

Chapter 2: Getting Started

2.1 Introduction Quick Test Professional (QTP) is an automated testing tool used for testing several software applications and environments. It is primarily used to test standard Windows applications, Web objects, ActiveX controls, Visual Basic applications, and multimedia objects on Web pages. It has an intuitive graphical user interface (GUI) to perform functional and regression testing. Let’s now learn about the purpose of using QTP and its features.

2.2 Why QTP? There are various drawbacks when you test an application manually. Manual testing is time-consuming and tedious, and it required huge investment in human resources. In addition, due to time constraint, it often becomes impossible to test every feature of an application thoroughly before it is released. This can result in critical bugs undetected in an application, which can bring adverse effects to the business. QTP addresses these problems with its speedy automated test processes. With QTP, you can create tests to check all aspects of your application. These tests can then be run every time your application undergoes a change.

2.3 Features of QTP QTP was originally launched by Mercury Interactive in November 2002; later it was taken over by HP in 2007. QTP has several comprehensive, powerful features that make it significantly distinct from other automation tools. Let's study the QTP features one-by-one. Intuitive User Interface QTP has an intuitive user interface that is much simpler to understand and operate. It provides two main views of a script: Keyword View and Expert View. These views help users modify, remove, or rearrange test steps easily. Simple Language QTP uses Microsoft's VBScript for its test procedures. With VBScript, you can also manipulate the objects and controls of an application under test. VBScript is preferable as it includes several existing functions and resources that are easily available for implementation. Use of Zero-Configuration Technology QTP follows next-generation "zero-configuration" Keyword Driven testing technology wherein keywords, such as commands, functions, methods, statements are used for creating test scripts. This technology helps in faster test creation and easier maintenance, it and provides more powerful data-driving capability.

Page 7: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

7

Insertion of Checkpoints QTP offers various types of checkpoints that you can add for thorough verification of an application under test. Using checkpoints, you can verify if the actual application behavior or state is consistent with the expected application behavior or state. Data-driven Testing QTP allows use of data table for feeding data. Data table is implemented as a Microsoft Excel workbook that can be accessed from within QTP. Data can be typed in or imported from databases, spreadsheets, or text files. Supported Technologies QTP supports functional testing of all popular environments, like Windows, Web, .Net, Visual Basic, ActiveX, Java, SAP, Siebel, Oracle, PeopleSoft, terminal emulators, and Web services. Test Results At the end of a test, QTP provides you with a test result indicating whether the test is passed or failed. The test result also shows error messages and may provide supporting information that helps you to determine the underlying cause of a failure. Exception Handling Exception handling is one of the features of QTP, which aims at running tests even in case of an unexpected failure. Licensing Model QTP is available through single-seat licenses, as well as floating or concurrent licenses.

Page 8: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

8

Chapter 3: Installation of QTP

3.1 Installing QuickTest Professional To learn the QTP tool, it is essential to install QTP software first. In this section, let’s learn to install QuickTest Professional on your computer. 1. Prerequisites a. Ensure that you are logged on with Administrator privileges. b. Select a local drive on which to install QuickTest Professional. Tip: You should not install QuickTest Professional on a network drive. c. Close any instances of QuickTest Professional. Also, close other open applications. 2. Insert the QuickTest Professional installation DVD into the DVD drive. a. If the DVD drive is on your local computer, and Autoplay is enabled, the QuickTest Professional Setup window opens. b. If Autoplay is disabled on your computer, right-click the DVD drive and select Autoplay. c. If you are installing from a network drive, double-click setup.exe in the root folder of the DVD. The Setup window opens.

Page 9: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

9

3. To start the QuickTest Professional Setup program, click QuickTest Professional Setup. 4. QuickTest requires specific software, for example, Microsoft Visual C++ Runtime components, to be installed before you install QuickTest. If Setup finds that the prerequisite software is not already installed on your computer, the following screen opens.

5. Click OK and follow the on-screen instructions to install the listed software before continuing with the QuickTest installation. Note: If you click Cancel, Setup will stop because QuickTest cannot be installed without the prerequisite software. 6. You may be prompted to restart your computer after installing the prerequisite software. To continue with the installation after restarting your computer, run the Setup program again. The Welcome to the HP QuickTest Professional Setup Wizard opens. 7. Click Next to proceed. The License Agreement screen opens.

Page 10: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

10

8. To install QuickTest Professional, select I Agree to accept the terms of the license agreement, and then click Next. 9. On the Customer Information screen, type your name and the name of your organization. 10. On the Custom Setup screen, select the QuickTest components and add-ins you want to install.

Note: You can select an item in the list to see a description of the feature as well as the space requirement for the feature on your drive. 11. Click an icon to view a menu and select how that feature is installed on your computer. The following options are available, depending on the feature:

• Will be installed on local hard drive. Installs the selected feature on your local hard drive. Sub-features of the selected feature are not installed.

• Entire feature will be installed on local hard drive. Installs the entire selected feature and its sub-features on your local hard drive. For example, you can instruct QuickTest to install the .NET Add-in with its sub add-ins, Silverlight and Windows Presentation Foundation.

• Entire feature will be unavailable. Excludes the feature from the installation and it is not available in QuickTest.

12. Click Next. If you are upgrading from version 9.5 or later, the upgrade installation automatically installs QuickTest Professional in the same folder in which the previous version of QuickTest was installed. Proceed to step 10. 13. On the Select Installation Folder screen, choose the location where you want to install QuickTest Professional.

Page 11: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

11

14. To select a different location, click Browse, select a folder, and then click OK. You must specify a folder on a mapped drive (not a UNC path). Note: If the destination folder does not exist, the setup program creates it. 15. To view the required and available space on each of your mapped drives, click Disk Cost. 16. Ensure that you install QuickTest Professional on a drive with sufficient amount of free disk space. For more information, see the system requirements, as described in the HP QuickTest Professional Readme. Click Next to proceed. The Confirm Installation screen opens. 17. Click Next to proceed, and the installation process begins. The Installing HP QuickTest Professional screen displays the progress of the installation. 18. When the installation is complete, click Finish. The Additional Installation Requirements screen opens.

Page 12: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

12

19. In addition to the options to configure Internet Explorer and DCOM settings, and to run the License Wizard, the Additional Installation Requirements screen displays any prerequisite software that must be installed or configured to work with QuickTest, according to the options selected during installation. Select the required installation options. Tip: Select an option name to display a description of the feature. 20. To install or configure your selections, on the Additional Installation Requirements screen, click Run. 21. If you select to run the License Installation Wizard, the QuickTest Professional License Installation - License Type screen opens.

22. On the QuickTest Professional License Installation - License Type screen, select a license type.

• Seat license. Uses a license created for this computer. A seat license is a permanent license that is specific to the computer on which it is installed. When you select this option, you also get a 30-day demo period during which you must request a permanent seat license key from the HP Webware License Key Delivery Service. After you receive the seat license key, you can activate it to work with QuickTest Professional permanently.

Page 13: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

13

• Concurrent license. Uses a network-based license. A license server on the network regulates the number of concurrent QuickTest Professional users. You can work with a concurrent license only if a concurrent license server is installed on your local network, and that license server has at least one available license that is not currently in use.

23. If you chose to install QuickTest with a seat license, the QuickTest Professional License Installation - Welcome screen opens.

If you have a seat license key, you can install it. If you do not have a license key, make a record of the displayed locking code for your computer. You will need it to request your license key. Click the link on the QuickTest Professional License Installation – Welcome screen for the HP Webware License Key Delivery Service to request your license key. 24. The installation continues with installing the options you selected on the Additional Installation Requirements screen. When these options are installed and configured on your computer, the screen reopens. Note: A checkmark is displayed next to the options that were successfully installed or configured. 25. Click Show Readme if you want the HP QuickTest Professional Readme to open at the end of the installation. 26. Click Close. The Installation Complete screen opens. 27. Click Finish. The QuickTest Professional is successfully installed on your computer.

Page 14: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

14

Chapter 4: Testing with QTP

In this section, you will learn about the Test process of QTP. Testing with QTP involves the following stages: 1. Analyzing your application 2. Preparing the testing infrastructure 3. Building your tests and adding steps to them 4. Enhancing your test 5. Debugging, running, and analyzing your test 6. Reporting defects

Let’s understand each of these stages in detail.

1. Analyzing your application To determine the testing needs, you first need to analyze your application.

• What are the development environments of your application (for example Web, Java, or .NET)? Load QTP add-ins will be required for these environments to enable QTP to identify and work with the objects in your application.

• What business processes and functionality do you want to test? To understand this scenario, think about the various activities that customers perform in your application to accomplish specific tasks.

• Consider how to divide these business processes into smaller units. You will be creating actions based on these tasks. Smaller and more modular actions make your tests easier to read and follow, and help ease maintenance in the long run. At this stage of test process, you can already begin creating test skeletons and adding actions to them.

2. Preparing the testing infrastructure

Based on your testing needs, you can determine what resources are required and create these resources, accordingly. Resources include shared object repositories containing test objects (which are representations of the objects in your application), function libraries containing functions that enhance QTP functionality, etc. Next, you will need to configure QTP settings so that QTP will perform the required tasks, such as displaying a results report every time you run a test.

3. Building your tests and adding steps to them After the testing infrastructure is ready, the next step is to build your tests. You can create one or more empty tests and add actions to them to create the testing skeletons. Next, you can associate your object repositories with the relevant actions, and associate your function libraries with the relevant tests, so that you can insert steps using keywords. At this stage, you can also plan to configure test preferences.

Page 15: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

15

4. Enhancing your test Next, you can insert checkpoints in your test to easily search for a specific value of a page, object, or text string. Inserting a checkpoint will help you determine whether your application is functioning correctly. You can also broaden the scope of your test by replacing fixed values with parameters. This will help you determine how your application performs the same operations with multiple sets of data. Another option is to add logic and conditional or loop statements that enable you to add sophisticated checks to your test.

5. Debugging, running, and analyzing your test The next step is to debug a test to ensure that it operates smoothly and without interruption. After the test is working correctly, you run it to check the behavior of your application. While running the test, QTP opens the application and performs each step in your test. You then examine the test results to identify defects in your application.

6. Reporting defects The final step involves defect reporting. If you have Quality Center installed, you can report the defects you discovered to the database.

Page 16: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

16

Chapter 5: Key Elements of the QTP Window

Before creating tests, let’s get acquainted with the main QTP window. The picture below shows the QTP window. It comprises of toolbars, data table, and panes.

Document Area

• Test –Enables you to create, view, and modify your test in Keyword View or Expert View

• Function Library – Enables you to create, view, and modify functions (operations) for use with your test

• Start Page – Welcomes you to QuickTest and provides links to Process Guidance. You can use the shortcut buttons to open new and existing documents.

• Keyword View – Contains each step, and displays the object hierarchy, in a modular, icon-based table

• Expert View – Contains each step as a VBScript line. In object-based steps, the VBScript line defines the object hierarchy

Toolbars and Menus In addition to the document area, the QuickTest window contains the following key elements:

• QuickTest title bar – Displays the name of the active document. If changes have been made since it was last saved, an asterisk (*) is displayed next to the document name in the title bar

• Menu bar – Displays menus of QuickTest commands

Page 17: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

17

• Standard toolbar – Contains buttons to assist you in managing your testing documents

• View toolbar –Contains buttons to view the various panes that can assist you in the

testing process

• Tools toolbar –Contains buttons to assist you in setting options, checking syntax,

and working with the Object Spy

• Automation toolbar –Contains buttons to assist you in running and analyzing your

test

• Insert toolbar –Contains buttons to assist you in inserting steps, actions,

checkpoints, and output values into your test

• Edit toolbar –Contains buttons to assist you in editing your test steps

• Debug toolbar –Contains buttons to assist you in debugging tests

• Action toolbar –Contains buttons and a list of actions, enabling you to view the

details of an individual action or the entire test flow

Note: The Action toolbar is displayed only in the Keyword View. It is not displayed when you open QuickTest for the first time. You can display the Action toolbar by choosing View > Toolbars > Action. If you insert a reusable or external action in a test, the Action toolbar is displayed automatically in the Keyword View.

• Status bar – Displays the status of the QuickTest application and other relevant

information Panes You can show or hide the following panes from the View menu:

• Active Screen – Provides a snapshot of your application as it appeared when you performed a certain step during a recording session. (You can display the Active Screen by choosing View > Active Screen, or by clicking the Active Screen button

.)

• Available Keywords – Displays all the keywords available to your test. Enables you to drag and drop objects or calls to functions into your test. (You can display the Available Keywords pane by choosing View > Available Keywords, or by clicking

the Available Keywords Pane button .)

Page 18: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

18

• Data Table –Assists you in parameterizing your test. (You can display the Data

Table pane by choosing View > Data Table, or by clicking the Data Table button

.)

• Debug Viewer –Assists you in debugging your test. The Debug Viewer pane contains the Watch, Variables, and Command tabs. (The Debug Viewer pane is not displayed when you open QuickTest for the first time. You can display the Debug Viewer by choosing View > Debug Viewer.)

• Information –Displays a list of syntax errors found in your test and function library scripts. (You can display the Information pane by choosing View > Information.)

• Missing Resources –Provides a list of the resources that are specified in your test but cannot be found, such as missing Recovery Scenarios and missing Function Libraries. (The Missing Resources pane is not displayed when you open QuickTest for the first time. You can display the Missing Resources pane by choosing View >

Missing Resources, or by clicking the Missing Resources button .)

• Process Guidance –Displays two panes that provide procedures and descriptions on how to best perform specific processes, such as creating a test in QuickTest. The Process Guidance Activities pane lists the activities that you can perform, such as adding steps to a test. The Process Guidance Description pane describes the tasks that you need to perform for a selected activity. Your organization may also provide you with process guidance that is accessible from these panes. (You can display the Process Guidance panes by choosing View > Process Guidance, or by clicking the

Process Guidance panes button .)

• Test Flow – Displays the hierarchy of actions and action calls in the current test, and shows the order in which they are run. (You can display the Test Flow pane by

choosing View > Test Flow, or by clicking the Test Flow Pane button .)

• Resources – Displays all the resources associated with your current test and enables you to manage these resources. (You can display the Resources pane by

choosing View > Resources, or by clicking the Resources Pane button .)

• To Do – Displays and enables you to manage the tasks defined for the current test. The To Do pane also displays the TODO comment steps of the test's actions or currently open function libraries. (You can display the To Do pane by choosing View

> To Do, or by clicking the To Do Pane button .)

Page 19: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

19

Chapter 6: Sample Applications

In this tutorial, two sample applications are used for practice to work with QTP, namely Flight Reservation Application and Mercury Tours Web site.

• Flight Reservation Application – Comes pre-installed with the QTP tool • Mercury Tours Web site – Is a Web application

Let’s familiarize ourselves with these applications before we create tests using QTP. 6.1 Flight Reservation Application Let’s now explore the Flight Reservation Application. Flight Reservation is a default application provided with QTP and it comes pre-installed with QTP.

To run Flight Reservation, follow the steps given below: 1. To open the Flight Reservation Application, click Start> Program Files > Quick Test Professional > Sample Application > Flight Reservation. 2. The next step is to enter the credentials for logging into the application. In the Login dialog box, in the Agent Name box, you should enter a user name and in the Password box, you should enter a password, and then click OK. Note: The default username and password is mercury.

The Flight Reservation window opens.

Page 20: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

20

3. In the Flight Reservation window, you can book a flight between two cities, even modify or delete an existing booking. As you navigate the application, think about what you might want to test, and which pages and objects need to be included in each test that you might create. While exploring the flight reservation options, do not enter the actual information in the application. You may enter fictitious information for practice.

4. After you have explored the Flight Reservation Application, you can terminate the current session by clicking Close in the Flight Reservation window. You are now ready to create tests on the Flight Reservation Application using QuickTest! 6.2 Mercury Tours Web Site This site simulates a Web-based flight information and reservation service. Before you create and record a test, you should be a registered user to access the Mercury Tours Web site. To run Mercury Tours, follow the steps given below: 1. To launch the Mercury Tours application, in your Web browser, type the URL, http://newtours.demoaut.com. The Mercury Tours home page opens. 2. The next step is to register on the Mercury Tours Web site. To register as a user, on the Mercury Tours home page, click REGISTER.

Page 21: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

21

3. On the REGISTER page, under User Information, in the User Name box, enter your user name; in the Password box, type your password; and in the Confirm Password box, type the same password again for confirmation, and then click SUBMIT. Note: Fields under Contact Information and Mailing Information are optional and you can skip. Your registration is complete. After the registration is completed, a thank you message appears confirming your registration. 4. To log on the Mercy Tours Web site, on the home page, click SIGN-ON. 5. On the SIGN-ON page, in the User Name box, type your user name and in the Password box, type your password, and then click SUBMIT. The FLIGHT FINDER page is displayed. 6. On the FLIGHT FINDER page, you can check the flight details and reserve a flight. You can select a round trip or a one-way flight journey, enter the number of passengers traveling, and specify the departure and arrival place of flight. After entering all the information, click CONTINUE. The SELECT FLIGHT page is displayed. 7. On the SELECT FLIGHT page, you can select your departure and return flight from the selections displayed. After selecting the required flight, click CONTINUE. The BOOK A FLIGHT page is displayed. 8. On the BOOK A FLIGHT page, do not enter actual personal or credit card information. You can enter fictitious names for “practice” and then click SECURE PURCHASE. The FLIGHT CONFIRMATION page is displayed. 9. After you have explored the Mercury Tours Web site, you can log out or terminate the current session. To log out, on the FLIGHT CONFIRMATION page, click LOG OUT. Alternately, you can click SIGN-OFF on the top of the page. You are now ready to create tests on the MercuryTours application using QuickTest!

Page 22: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

22

Chapter 7: Working with Script in QTP In this section, we will learn about:

1. Recording a script 2. Running a script 3. Saving a script

7.1 Recording a Script QTP allows you to record scripts while navigating through your application. Before you begin to record a script, ensure that all browsers and applications are closed on your computer. To record a script, follow the steps given below: 1. First, you need to start QuickTest. To open the QTP window, click Start > All Programs > QuickTest Professional > QuickTest Professional. QuickTest Professional – Add-in Manager dialog box is displayed. 2. In the QuickTest Professional – Add-in Manager dialog box, select the required add-ins and then click OK to close the dialog box. The QuickTest Professional window is displayed. 3. Next, in the QuickTest Professional window, click File. In the File menu, click New. A blank test opens. 4. To begin recording a test, in the test window, on the toolbar, click the Record button. The Record and Run Settings dialog box opens. 5. The Record and Run Settings dialog box provides options to record Web applications and Windows applications. Choose the option as per your requirement and click OK to close the Record and Run Settings dialog box. QuickTest begins recording. 6. Perform the steps you want to record. After all the steps are performed, navigate back to the QuickTest Professional window and then click Stop. QuickTest recorded the steps you performed from the time you clicked the Record button until you clicked the Stop button. All the steps performed can be viewed in the action-based Keyword View or the code-based Expert View. Using QTP, you can record the test scripts in three modes: 1. Normal mode 2. Analog mode 3. Low-level recording mode

Page 23: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

23

7.1.1 Normal Mode The Normal recording mode is the default, recording mode in QTP. It records the objects in your application and the operations performed on them. This mode takes full advantage of the QTP test object model, recognizing the objects in your application regardless of their location on the screen. This mode is also called as Context Sensitive Mode. 7.1.2 Analog Mode In this mode, you can record the exact mouse and keyboard operations that you perform in relation to either the screen or the application window. This mode is useful for recording operations that you cannot record at the level of an object, for example, recording a signature, drawing a picture, etc. Note that the steps you record cannot be edited in Analog mode. 7.1.3 Low-level Recording Mode You can use the low-level recording mode to record objects in your application or when an object is not recognized by QTP. In this mode, you can also record the exact coordinates of the object in an application. Note that the steps recorded using the low-level recording mode may not run correctly on all objects.

7.2 Running a Script QTP allows you to run the script to replicate the operations you performed while recording. Follow the steps given below to run a script: 1. In the QuickTest Professional window, click the Run button. The Run dialog box opens. 2. The Run dialog box provides options to specify the location in which you can save the run session results. a. In the Run dialog box, you can select the New run results folder option. This option displays the default path and folder name in which the results are saved. When you select this option, for each run, a new result folder will be created with the name “RES” and the number, i:e if you run the script for the first time, the folder names Res1 will be created; for next run, it would be Res2, and so on. b. In the Run dialog box, you can select the Temporary run results folder (overwrites any existing temporary results) option. This option saves the run results in a temporary folder and overwrites any results previously saved in this folder. 3. To close the Run dialog box, click OK. QuickTest opens the browser and starts running the script. Note:

• While developing a test script, it is recommended to choose the Temporary option and once the script is baseline, you can use the New folder option.

Page 24: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

24

• In the QTP window, while the script is running, you will observe a yellow marker pointing at the step currently being executed.

7.3 Saving a Script When you create a test and save it with a specific name, a test name directory is created automatically and all the files and folders related to the test are saved in the test name directory. By default, QTP creates certain files and directories in each test directory. Following folders and files are created to save the result script:

Folders/Files Description Action0 folder This directory contains files that control all

action except Action0in the test directory. Action1 folder This directory contains log of user actions on

the objects as these were captured during recording.

Script.mtr This file captures the user actions on objects and is located in the ACTION1 directory.

Default.xls This file contains the data that you specify in DATA TABLE to parameterize your test.

Snapshots folder This file contains the snapshots of each screen recording on the application and is located in the Action1 folder.

There are three other files created for each action folder:

Files Description Resources.mtr Contains resources for that action ObjectRepository.bdb Contains object list for that action Script.mts Contains the script for that action

Page 25: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

25

Chapter 8: Synchronization Point

8.1 Define Synchronization Point Synchronization point helps to anticipate the timing problems by ensuring that QTP waits for some time until the application is ready for the next step. If you do not want QTP to perform a step until an object in your application achieves a certain state, you can insert a synchronization point to instruct QTP to pause the test until the object property achieves the value you specify (or until a specified timeout is exceeded).

8.2 Examples Let's take an example of synchronization point using the flight reservation application. Suppose you insert an order and then stop your recording. Keep in mind not to close the application window or perform any other operation. Next, you play back the same test. You will observe that the QTP test result is generated before the order is inserted. In such scenarios, synchronization point is helpful.

Following are some of the examples of visual cues that QTP uses for synchronization:

• A progress bar reaches 100% completion • A status message appears • A button becomes enabled • A window opens and is ready for data entry • A pop-up message appears in response to an operation

Page 26: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

26

8.3 Default Synchronization Time in QTP • The default synchronization time in QTP is 20 sec.

To view the default time, in the QTP window, click File > Settings > Run. On the Run tab, in the Object Synchronization Timeout box, you can view 20 Sec.

• For Web Add-in, synchronization time is 60 sec. To view the synchronization time for Web add-in, select Web add-in in the Add-in Manager dialog box, and then click File> Settings> Web. On the Web tab, in the Browser navigation timeout box, you can view 60 Sec.

You can change the default timings for an object or Web ,and set the synchronization point as per your requirements to avoid the errors or test fails in real time projects.

Page 27: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

27

Chapter 9: Checkpoints 9.1 Define a Checkpoint QTP allows you to add checks to your test. A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. It can check for differences in the text strings, objects, and tables in your application or site. This feature helps you to identify whether your Web site or application is functioning correctly.

9.2 Types of Checkpoints QTP provides several types of checkpoints to check various objects in a Web site or application. See the table given below to study various checkpoints.

Checkpoint Type

Description Example of Use

Standard checkpoint

Checks values of an object's properties

Check that a radio button is selected.

Image checkpoint

Checks the property values of an image (This checkpoint type is inserted by selecting the Standard Checkpoint option and then selecting to check a Web Image object.)

Check that the image source file is correct.

Table checkpoint

Checks information in a table (This checkpoint type is inserted by selecting the Standard Checkpoint option and then selecting to check any table object.)

Check that the value in a table cell is correct.

Page checkpoint

Checks the characteristics of a Web page (This checkpoint type is inserted by selecting the Standard Checkpoint option and then selecting to check a Web Page object.)

Check how long a Web page takes to load or if a Web page contains broken links.

Text checkpoint

Checks that a text string is displayed in the appropriate place in an application

Check whether the expected text string is displayed in the expected location in a test object.

Text Area checkpoint

Checks that a text string is displayed within a defined area in a Windows-based application

Check that an area of a dialog box includes text that was entered in another part of the application.

Bitmap checkpoint

Checks an area of an application after capturing it as a bitmap

Check that a Web page (or any portion of it) is displayed as expected.

Database checkpoint

Checks the contents of databases accessed by an application or Web site

Check that the value in a database query is correct.

Page 28: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

28

Accessibility checkpoint

Identifies areas of a Web site to check for Section 508 compliancy

Check if the images on a Web page include ALT properties, required by the W3C Web Content Accessibility Guidelines.

XML checkpoint

Checks the data content of XML documents

Check the content of an element to make sure that its tags, attributes, and values have not changed. Note: XML file checkpoints are used to check a specified XML file; XML application checkpoints are used to check an XML document within a Web page.

You can add most checkpoints to your test either while inserting steps or while recording. Note: When QTP creates a checkpoint, it assigns a name based on information inside the checkpoint—the checked value, for example. The checkpoint name remains unchanged, even if the information, on which the checkpoint is based, is modified. This point should be remembered when you look for checkpoints displayed in the Keyword View. However, the QTP may shorten the name displayed in the Keyword View. In the sections to follow, you will learn about adding a:

• Standard checkpoint • Page checkpoint • Table checkpoint • Text checkpoint

9.3 Checking Objects In this section, you will learn to add a standard checkpoint on the Flight Reservation page. This checkpoint will verify the value in the box containing the first name of the passenger.

To insert the checkpoint, you should first open the Mercury Tours application and in the application, open the page on which you want to insert the checkpoint. 1. To begin, start QTP and open the MercuryTours test.

• If QTP is currently not open, you can open it as described in steps 1, 2, and 3 of Section 4.1 Recording a script. Also, ensure that only the Web Add-in is loaded.

2. Next, save the test as checkpoint. To do so, click File > Save As. And, save the test as a checkpoint. 3. Navigate to the page where you want to add a standard checkpoint. Consider that you want to add a checkpoint that checks the property values of the First Name edit box after the passenger's name has been entered in the box. a. To display the Test Flow pane, click the Test Flow tab. If you are unable to view the Test Flow tab, click View > Test Flow or click the Test Flow Pane button to display it. b. In the Test Flow pane, double-click the BookFlight action.

Page 29: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

29

4. Next, open the Book a Flight page on the Mercury Tours application. a. Log on to the Mercury Tours Web site: http://newtours.demoaut.com. b. In the User Name and Password boxes, type tutorial. c. Click Sign-In. The Flight Finder page opens. d. On the Flight Finder page, enter flight details as follows:

Departing From: New York On: December 29 Arriving In: San Francisco Returning: December 31

e. After entering the flight details, click CONTINUE to accept the other default selections. The Select Flight page opens. f. On the Select Flight page, click CONTINUE to accept the default flight selections. The Book a Flight page opens. 5. Create a standard checkpoint. a. In the Item column of the Keyword View, select the passFirst0 row. b. Click Insert > Checkpoint > Standard Checkpoint. The Checkpoint Properties dialog box is displayed.

Page 30: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

30

Let’s learn about the object properties in the Checkpoint Properties dialog box.

Name – Name of the object as defined in the HTML code of the Web page

Class – Type of object. WebEdit indicates that the object is an edit box The ABC icon – Indicates that the value of the property is a constant

For each object class, QTPrecommends default property checks. The table below describes the default checks for the WebEdit class.

c. In the Checkpoint Properties dialog box, in the Name box, type CheckName as the new checkpoint name.

Property Value Explanation

html tag INPUT INPUT is the html tag as defined in the HTML source code.

innertext In this case, the value of innertext is empty. The checkpoint checks that the value is empty.

name passFirst0 passFirst0 is the name of the edit box.

type text text is the type of object as defined in the HTML source code.

value Currently, the value is empty. You need to enter the same value that you specified for the First Name edit box.

Page 31: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

31

d. In the object properties area, scroll down and select the row containing the property named value.

e. Next, you need to enter the value that matches the value you entered in the actual step.

Page 32: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

32

To do this, click in the Constant box and enter the first name value.

f. In the Insert statement area, select After current step. This inserts the checkpoint after the passFirst0 Set... step. (This is the step in which the passenger's first name is entered in the First Name box.)

Page 33: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

33

g. Accept the rest of the settings as default and click OK. QuickTest adds a standard checkpoint step to your test below the selected step.

6. To save the test, click File > Save. Alternately, you can click the Save button. You can repeat the steps shown above to add checkpoints as per your requirement. You can insert many object checkpoints in the manner described above.

9.4 Checking Pages In this section, you will learn to add a page checkpoint to your test. The page checkpoint checks that the number of links and images in the page when you run your test is the same as when you recorded your test. Follow the steps given below to add a page checkpoint: 1. Identify the page where you want to add a page checkpoint. a. In the Test Flow pane, double-click the BookFlight action. b. In the Item column of the Keyword View, select the Book a Flight: Mercury row. (This row is located directly above the row displaying passFirst0.) 2. Create a page checkpoint.

• To add a page checkpoint, click Insert > Checkpoint > Standard Checkpoint. The Page Checkpoint Properties dialog box opens.

Page 34: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

34

3. When you run the test, QuickTest checks the number of links and images in the page and the load time, as shown in the Page Checkpoint Properties dialog box figure shown above. The load time of the page may vary from computer to computer and your results may not match the above shown figure. QTP also checks the actual target URL of each link and the actual source of each image. Accept the default settings and click OK.QTP adds the page checkpoint to your test. Because this is the first operation on the Book a Flight: Mercury page, the operation is added directly to the existing Book a Flight: Mercury page node. It is displayed in the Keyword View as a checkpoint operation on the Book a Flight: Mercury page.

4. Next, click File > Save or click the Save button to save the test.

Page 35: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

35

9.5 Checking Tables In this section, you will learn to add a table checkpoint to check the cost of the outbound flight, as displayed on the Book a Flight: Mercury page. 1. Identify the page where you want to add a table checkpoint. a. In the Test Flow pane, double-click the BookFlight action. The action is displayed in the Keyword View. b. Select the passFirst0step (the step that enters the passenger's first name into the First Name edit box). 2. Open the Book A Flight page on the Mercury Tours Web site. a. On the Mercury Tours Web site (http://newtours.demoaut.com), in the User Name and Password boxes, type tutorial and then click Sign-In. The Flight Finder page opens. b. On the Flight Finder page, enter flight details as follows:

Departing From: New York On: December 29 Arriving In: San Francisco Returning: December 31

c. After entering the flight details, click CONTINUE to accept the other default selections. The Select Flight page opens. d. On the Select Flight page, click CONTINUE to accept the default flight selections. The Book a Flight page opens. 3. Configure QTP to record on the open browser page. a. In the QuickTest Professional window, click Automation > Record and Run Settings.

Page 36: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

36

The Record and Run Settings dialog box opens.

b. In the Record and Run Settings dialog box, click the Record and run test on any open browser option, and then click OK to close the dialog box. 4. Create a table checkpoint. a. In the Mercury Tours Web site, on the Book Flight page, under the Flight Departure Date and Price, select 270 (the price of the fare of the first leg between New York and San Francisco). b. Next, click the Record button or click Automation > Record. QuickTest begins a recording session. c. Next, click Insert > Checkpoint > Standard Checkpoint. The QuickTest window is hidden, and the pointer changes into a pointing hand. d. Select the highlighted string, 270. The Object Selection dialog box opens. e. Select WebTable: New York to San Francisco and click OK. The Table Checkpoint Properties dialog box opens, showing the rows and columns of the table.

Page 37: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

37

f. In the Table Checkpoint Properties dialog box, in the Name box, type CheckCost as the new checkpoint name.

Note: By default, check marks appear in all cells. You can double-click a cell to toggle the cell selection, or double-click a row or column header to toggle the selection for all the cells in the selected row or column. g. Double-click each column header to clear the check marks. Double-click column 3, row 3 to check the value of this cell. (QTP checks only cells containing check marks.)

h. Scroll through the rows and columns to make sure that only the cell in column 3, row 3 is checked. If any other cells are checked, select each checked cell and click the Remove from Check button. Tip: You can change the column widths and row heights by dragging the boundaries of the column and row headers. i. Accept the rest of the settings as default and click OK. QuickTest adds the table checkpoint to your test. It is displayed in the Keyword View as a new step under the Book a Flight: Mercury page.

Page 38: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

38

5. Next, click the Stop button to stop the recording session. 6. Next, click File > Save or click the Save button to save the test. 7. Finally, you can exit the Mercury Tours Web site.

9.6 Checking Text In this section, you will learn to add a text checkpoint to your test to check whether New York is displayed on the Flight Confirmation page. 1. Identify the page where you want to add a text checkpoint. a. In the Test Flow pane, double-click the FlightConfirmation action. The action is displayed in the Keyword View. b. In the Keyword View, select the first row displaying Flight Confirmation: Mercury. 2. Open the Flight Confirmation page on the Mercury Tours Web site. a. Log on to the Mercury Tours Web site (http://newtours.demoaut.com). b. In the User Name and Password boxes, type tutorial, and then click Sign-In. The Flight Finder page opens. c. On the Flight Finder page, enter flight details as follows:

Departing From: New York On: December 29 Arriving In: San Francisco Returning: December 31

d. After entering the flight details, click CONTINUE to accept the other default selections. The Select Flight page opens. e. On the Select Flight page, click CONTINUE to accept the default flight selections.

Page 39: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

39

f. On the Book a Flight page, click SECURE PURCHASE. The Flight Confirmation page opens. 3. Configure QTP to record on the open browser page. a. In the QuickTest Professional window, click Automation > Record and Run Settings. The Record and Run Settings dialog box opens.

b. In the Record and Run Settings dialog box, ensure that the Record and run test on any open browser option is selected and click OK to close the dialog box. 4. Create a text checkpoint. a. On the Flight Confirmation page, under Departing, select the text New York (add a space after it). b. Next, click the Record button or click Automation > Record. QuickTest begins a recording session. c. To add the text checkpoint, click Insert > Checkpoint > Text Checkpoint. The QuickTest window is hidden, and the pointer changes into a pointing hand. d. Select the text string, New York. The Text Checkpoint Properties dialog box opens.

Page 40: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

40

Note: In the Text Checkpoint Properties dialog box, when Checked Text appears in the list box, the Constant field displays the text string you highlighted. This is the text QTP looks for when running the test. e. In the Name box, type CheckDepartingText as the new checkpoint name. f. Next, remove San Francisco from the Checkpoint Summary pane. To do so, click the Configure button to open the Configure Text Selection dialog box.

g. Select the to text string. (Do not highlight San Francisco). h. Then, click the Text After button. San Francisco changes from black to gray. i. To close the Text Checkpoint Properties dialog box, click OK. San Francisco is removed from the text after part of the Checkpoint Summary pane. 5. Accept the rest of the settings as default and click OK. QuickTest adds the text checkpoint to your test. It is displayed in the Keyword View as a checkpoint operation on the Flight Confirmation: Mercury page.

Page 41: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

41

6. Click the Stop button to stop the recording session. 7. Next, ensure that the checkpoint is above the home step. Drag the step up a row, if needed. Otherwise, during the test run, QuickTest will click the BACK TO HOME button before performing the checkpoint. 8. Finally, to save the test, click File > Save or click the Save button.

9.7 Managing Checkpoints in Object Repository In addition to viewing checkpoints in a specific action, you can also view them in the object repository and modify their properties. If applicable, you can even use the same checkpoint in more than one location. For example, if you want to verify that your organization's logo appears on every page in your application, you can create a checkpoint and insert it in wherever steps open another page. For the purposes of this tutorial, you will not be reusing checkpoints. 1. Open the Object Repository window.

• In the QuickTest Professional window, click Resources > Object Repository or click the Object Repository button. The Object Repository window opens, displaying a tree of all test objects and all checkpoint and output objects in the current action. Note: The tree includes all local objects and all objects in any shared object repositories associated with the action.

2. Select an action to view its checkpoints. • In the Object Repository window, in the Action drop-down list, select an action.

Page 42: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

42

You can see the action's test objects, checkpoint objects, and output value objects. 3. Finally, to close the Object Repository window, click File > Close.

9.8 Running and Analyzing a Test with Checkpoints In this section, you will review your test with checkpoints, run the test, and analyze the checkpoint results. 1. Configure QTP to open the Mercury Tours Web page. a. In the QuickTest Professional window, click Automation > Record and Run Settings.

Page 43: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

43

The Record and Run Settings dialog box opens.

b. In the Record and Run Settings dialog box, select the Open the following address when a record or run session begins option and click OK to close the dialog box. 2. Run your test. a. To run the test, click Run or click Automation>Run. The Run dialog box opens. b. Ensure that the New run results folder is selected. Accept the default results folder name and click OK. 3. View the run results. When QTP finishes running the test, the Run Results Viewer opens. The run result should be Passed indicates that all checkpoints passed. If one or more checkpoints had failed, the run result would be Failed. 4. View the results of the page checkpoint. a. In the run results tree, expand all the child nodes of Checkpoint Iteration 1 (Row 1) until you reach Book a Flight: Mercury, and highlight Checkpoint "CheckLinks". b. In the Result Details pane, you can review the details of the page checkpoint, which

Page 44: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

44

lists the items checked. The load time of the page may vary from computer to computer and your results may not match the below image. Tip: You can drag the bottom of the Result Details pane to enlarge it and/or scroll within the pane to view all of the checkpoint details. The checkpoint passed because the actual values of the checked properties match the expected values.

5. View the results of the table checkpoint. a. In the results tree, on the Book a Flight: Mercury page, expand (arrow) Card Type and then select Checkpoint "CheckCost". b. In the Result Details pane, you can review the details of the table checkpoint. You can also review the values of the table cells (cell values that were checked are displayed in black; cell values that were not checked are displayed in gray). The checkpoint passed because the actual value of the checked cell matches the expected value.

Page 45: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

45

6. View the results of the standard checkpoint. a. In the results tree, on the Book a Flight: Mercury page, expand (arrow) passFirst0and then select Checkpoint "CheckName". b. In the Result Details pane, you can review the details of the standard checkpoint, which lists the properties that were checked and their values. The checkpoint passed because the actual values of the checked properties match the expected values.

7. View the results of the text checkpoint. a. In the results tree, expand Flight Confirmation: Mercury and select Checkpoint "CheckDepartingText".

Page 46: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

46

b. In the Result Details pane, you can review the details of the text checkpoint. The checkpoint passed because the actual text matches the expected text.

8. Finally, to close the Run Results Viewer, click File > Exit.

Page 47: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

47

9.9 Performing a Check Using a Function In this section, you will learn to use the function to check the date format of a Web element in the SelectFlight action. 1. Start QuickTest and open the Checkpoint test. 2. Next, you need to save the test as Function.

• To save the test, click File > Save As. 3. Open the Select Flight page on the Mercury Tours Web site. a. Log on to the Mercury Tours Web site (http://newtours.demoaut.com). b. In the User Name and Password boxes, type tutorial and then click Sign-In. The Flight Finder page opens. c. On the Flight Finder page, enter flight details as follows:

Departing From: New York On: December 29 Arriving In: San Francisco Returning: December 31

d. After entering the Flight Finder page, click CONTINUE to accept the other default selections. The Select Flight page opens. Note: The date displayed in the DEPART area is in MM/DD/YYYY format.

4. Add the 12/29/<current year> object to your repository. a. Open the Object Repository Manager (Resources > Object Repository Manager). b. Browse to and open MercuryToursSelectFlight.tsr. c. Enable the repository for editing (File > Enable Editing). d. Click the browser window to make the Mercury Tours Web site active. e. Learn the 12/29/<current year>object. f. Save the repository.

• In the Object Repository Manager, select Object > Add Objects.

Page 48: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

48

The Object Repository Manager window is minimized, and the cursor changes to a pointing hand.

• Click the text string 12/29/<current year>.

• Ensure that in the Object Selection dialog box, the object WebElement: 12/29/<current year> is highlighted and then click OK. The 12/29/<current year> object is added to your repository.

5. In QuickTest, display the action in which you want to add a function. • You want to add a function that checks the innertext property values of the date

displayed in the SelectFlight action. To do so, in the Test Flow pane, double-click the SelectFlight action.

6. Paste the following in the Expert View. • Click the Expert View tab and paste the function shown below before the

existing step. (You want the function to run before QuickTest navigates to the next page in the application.) Note: In the first line of the function, make sure to insert the current year. For example, if you are performing this tutorial in 2011, change 2010 to 2011.

departureDate=Browser("Select a Flight: Mercury").Page("Select a Flight: Mercury").WebElement("12/29/2010").GetROProperty("innertext") if check_data_validity( departureDate ) then reporter.ReportEvent micPass, "Date is valid" , departureDate end if

7. View these steps in the Keyword View. • Click the Keyword View tab. (The highlighted step is not part of the function—

it is the step that navigates to the next page in the Mercury Tours Web site.)

8. Next, save your test. To do so, click File > Save or click the Save button. a. Run your test.

• To run test, click Run or click Automation > Run. The Run dialog box opens.

b. Ensure that the New run results folder is selected. Accept the default results folder name and then click OK. When the test run is completed, the Run Results Viewer opens.

Page 49: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

49

9. View the run results. View the run result. The run result should be Passed, indicating that the function passed because the date is displayed in the expected format, and it contains acceptable values.

Page 50: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

50

Chapter 10: Parameterization 10. 1 Parameterizing Tests When testing your applications, you may want to check how the application performs the same operations with multiple sets of data. For example, suppose you want to check how your Web site responds to ten separate sets of data. For that, you could create ten separate tests, each with its own set of data. Alternatively, you can create Data Table parameters so that your test runs ten times, each time using a different set of data.

10.2 Why Parameterization? Parameterization reduces Time and Effort as it allows you to pick different values at runtime. You can also use Data Drivers for parameterization, as it enables us to quickly parameterize several properties of test objects, checkpoints, and method arguments containing the same value within a given action. Data Drivers show all the constants that could be parameterized in one single window. It can be accessed by clicking Tools > Data Drivers

10.3 Defining a Data Table Parameter Consider the Flight Reservation application. In this section, we will create a test scenario with multiple sets of data for AgentName & Password on the login page.

To begin, you first need to record the following steps:

• Open the Flight Reservation application. • Enter AgentName and Password. • Press OK. • Close the Flight Reservation application when it opens. • Stop Recording.

Page 51: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

51

Once we are done with the above steps, the following screen appears:

Now, let’s test the same scenario with a combination of valid ALPHANUMERIC Agent Name & Password. The test steps will remain the same, but you will have more combinations of Data to test. We can achieve that either by copying the 5 steps and give different data values to AgentName and Password, which has to be done manually. Alternately, you can use Parameterization. The easiest way to parameterize an argument is in the Keyword view. Follow the steps given below for parameterization: 1. Click the Parameterization icon. A Value Configuration Options dialog box opens in which currently the value is set to a constant. 2. In the Value Configuration Options dialog box, click the Parameter option. QTP assigns a default name to this parameter. 3. Enter a parameter name and then click OK. Note: For the purposes of this tutorial, enter AgentName and Password for their respective fields to make it easier to understand. Refer to the figure shown below.

Page 52: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

52

Once this procedure is done, you’ll observe that in the data table, columns A and B will be replaced by AgentName and Password. In the Global Sheet, a column with Header "Agent Name" and value “mercury” is created. We will enter more values for this parameter as we are planning to test 3 sets in this case. Likewise, a column with Header “Password” is also created with value “mercury”. Next, use the following 3 sets of data to enter in the data table: 1. AgentName: mercury Password: mercury 2. AgentName: mercury11 Password: mercury 3. AgentName: mercury22 Password: mercury

The data sheet means QTP will iterate the same 5 steps that we have recorded 3 times. During the first iteration, it will use the data in the first row. During the second, it will use data in the second row and so on.

Page 53: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

53

Next, you need to run the script. In the status bar, QTP gives information of the row it is currently using as test data and highlights the corresponding row in the data sheet. The results will show summary of the 3 iterations as shown below:

Page 54: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

54

10.4 Parameterization Using Regular Expression Sometimes, just changing the values in the data table doesn’t work as there are different windows for different applications. In that case, we use regular expressions. A regular expression is a string that describes or matches a set of strings. Consider an example of the Flight Reservation application. 1. Open the Flight Reservation window. 2. Click the Open Order check box. 3. Check order no. 4. Enter order number as 5. 5. Then open the fax order so the fax order for order no 5 would open. 6. Enter a dummy fax number; then click Cancel. 7. Finally, close the Flight Reservation window.

Refer the figure shown below to view the Keyword View.

This test would run successfully for order no 5. Next, you can parameterize for order no. and add order no. 6, 7, 8 to the data table.

Page 55: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

55

When you run this script, an error would occur as the windows for order no. 5,6,7,8 are different and it tries to open order no. 5 in each case.

To avoid the error, use regular expression. To do so, click QTP > Resources menu > Object repository.

Page 56: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

56

To parameterize for fax order no. 5, configure the value and change it to Fax Order No. .*. using regular expression.

Page 57: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

57

Now, when the test is run, it would run correctly for all four iterations. There are various kinds of regular expressions used in QTP. Special characters and sequences are used in writing patterns for regular expressions. The following table describes and gives an example of the characters and sequences that can be used.

Character Description \ Marks the next character as either a special

character or a literal. For example, "n" matches the character "n". "\n" matches a newline character. The sequence "\\" matches "\" and "\(" matches "(".

^ Matches the beginning of input. $ Matches the end of input. * Matches the preceding character zero or

more times. For example, "zo*" matches either "z" or "zoo".

+ Matches the preceding character one or more times. For example, "zo+" matches "zoo" but not "z".

? Matches the preceding character zero or one time. For example, "a?ve?" matches the "ve" in

Page 58: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

58

"never". . Matches any single character except a

newline character.

(pattern) Matches pattern and remembers the match. The matched substring can be retrieved from the resulting Matches collection, using Item [0]...[n]. To match parentheses characters ( ), use "\(" or "\)".

x|y Matches either x or y. For example, "z|wood" matches "z" or "wood". "(z|w)oo" matches "zoo" or "wood".

{n} n is a nonnegative integer. Matches exactly n times. For example, "o{2}" does not match the "o" in "Bob," but matches the first two o's in "foooood".

{n,} n is a nonnegative integer. Matches at least n times. For example, "o{2,}" does not match the "o" in "Bob" and matches all the o's in "foooood." "o{1,}" is equivalent to "o+". "o{0,}" is equivalent to "o*".

{n,m} m and n are nonnegative integers. Matches at least n and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood." "o{0,1}" is equivalent to "o?".

[xyz] A character set. Matches any one of the enclosed characters. For example, "[abc]" matches the "a" in "plain".

[^xyz] A negative character set. Matches any character not enclosed. For example, "[^abc]" matches the "p" in "plain".

[a-z] A range of characters. Matches any character in the specified range. For example, "[a-z]" matches any lowercase alphabetic character in the range "a" through "z".

[^m-z] A negative range characters. Matches any character not in the specified range. For example, "[m-z]" matches any character

Page 59: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

59

not in the range "m" through "z". \b Matches a word boundary, that is, the

position between a word and a space. For example, "er\b" matches the "er" in "never" but not the "er" in "verb".

\B Matches a non-word boundary. "ea*r\B" matches the "ear" in "never early".

\d Matches a digit character; equivalent to [0-9].

\D Matches a non-digit character; equivalent to [^0-9].

\f Matches a form-feed character. \n Matches a newline character. \r Matches a carriage return character. \s Matches any white space including space,

tab, form-feed, etc. Equivalent to "[ \f\n\r\t\v]".

\S Matches any nonwhite space character. Equivalent to "[^ \f\n\r\t\v]".

\t Matches a tab character. \v Matches a vertical tab character. \w Matches any word character including

underscore. Equivalent to "[A-Za-z0-9_]". \W Matches any non-word character. Equivalent

to "[^A-Za-z0-9_]". \num Matches num, where num is a positive

integer. A reference back to remembered matches. For example, "(.)\1" matches two consecutive identical characters.

\n Matches n, where n is an octal escape value. Octal escape values must be 1, 2, or 3 digits long. For example, "\11" and "\011" both match a tab character. "\0011" is the equivalent of "\001" & "1". Octal escape values must not exceed 256. If they do, only the first two digits comprise the expression. Allows ASCII codes to be used in regular expressions.

\xn Matches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, "\x41" matches "A". "\x041" is equivalent to "\x04" & "1". Allows ASCII codes to be used in regular expressions.

Page 60: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

60

Chapter 11: Object Repository In this section, you will learn about test objects and run-time objects, and how to create shared object repositories. 11.1 Introducing Test Objects and Object Repositories Before you create a test, you need to set up the resources that will be used by that test. One of the most important resources for any test is the object repository. An object repository is a storehouse for the test objects (and other object types) used in your test.

Let’s learn in brief about the: • Test objects • Run-time objects

11.1.1 Test objects Test objects are stored representations of the actual objects or controls in your application. QTP creates test objects by learning a select set of the properties and values of the objects in your application. QTP uses the information it learns to uniquely identify the run-time objects in your application.

Each test object is part of a test object hierarchy. For example, a Link object may be part of a Browser/Page/Link hierarchy. Top-level objects, such as Browser objects, are known as container objects, as they can contain lower-level objects, such as Frame or Page objects. 11.1.2 Run-time objects Run-time objects are created and maintained during a QuickTest run session by the object creator (for example, Microsoft for Microsoft Internet Explorer objects, Mozilla for Mozilla Firefox objects, the product developer for ActiveX objects, and so on). During a run session, QuickTest performs the specified test object method on the run-time object. Run-time objects are not stored in an object repository, as they are available only during the run session.

11.1.3 Object Repositories Test objects created by QTP are stored in two types of object repository files: shared and local. 11.1.4 Shared Object Repository A shared object repository stores test objects that can be used in multiple actions. This is the preferred repository type for storing and maintaining test objects. By associating a shared object repository with an action, the test objects in that repository become available for use in the action. Any maintenance performed on an object in a shared object repository is reflected in any step using that object.

Page 61: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

61

11.1.5 Local Object Repository A local object repository stores test objects that can be used in one specific action. You cannot use the objects in this type of repository in any other action. Local object repositories are useful for taking the back up of your test objects, or for learning one or several objects.

When you create an object repository, include only those objects that you would need for testing purposes. This keeps the object repository relatively small and helps make maintenance and object selection easier. Also, ensure that you provide logical names so that others can easily choose the correct objects when creating or modifying tests. During a run session, QTP references the test objects stored in the associated object repositories in order to perform operations on the corresponding objects in your application. 11.2 Learning Objects in Your Application In this section, you will learn to use the QTP Navigate and Learn options to add objects from the Mercury Tours Web site to a shared object repository. Then you will associate the object repository with your test.

1. To begin, start QTP and open the MercuryTours test. • If QTP is currently not open, you can open it as described in steps 1, 2, and 3 of

Section 4.1 Recording a script. Also, ensure that only the Web Add-in is loaded. 2. Set the learn settings for QuickTest. a. Click Automation > Record and Run Settings. The Record and Run Settings dialog box opens.

Page 62: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

62

b. In the Record and Run Settings dialog box, on the Web tab, select the Open the following address when a record or run session begins option. c. Ensure that the URL in the first box is http://newtours.demoaut.com. In the second box, select a browser on which you want to run your test session. For the purposes of this tutorial, Microsoft Internet Explorer is the browser selected. d. In the Record and Run Settings dialog box, ensure that the Do not record and run on browsers that are already open and Close the browser when the test closes check boxes are selected, and then click OK. e. Next, run the test. Your browser will open to the Mercury Tours Web site. When the run session ends, your browser will close. 3. Next, you need to open the Mercury Tours Web site.

• Open Internet Explorer and browse to the Mercury Tours Web site: http://newtours.demoaut.com.

4. View the properties and operations for some of the objects in the Mercury Tours Web site. a. In QuickTest, click Tools > Object Spy. The Object Spy dialog box opens. b. You can drag the Object Spy dialog box to the right side of your screen so that you are able to view the objects you want to spy on more clearly. Ensure that the Keep Object Spy is on top while spying button is pressed. c. Next, click the pointing hand button. QuickTest is hidden, and the Object Spy dialog box is displayed over the Mercury Tours Web site Welcome page. d. In the Object Spy dialog box, move the mouse cursor over the various objects on the page and view the results. f. Place the mouse cursor in the User Name edit box (but do not click it). The test object hierarchy of that object is displayed. g. In the hierarchy box, notice that the name of the object is WebEdit, which is its object class type, and then click the User Name edit box. h. In the hierarchy box, notice that the object class and name are now displayed (WebEdit:userName). To close the Object Spy dialog box, click Close. 5. Start the Navigate and Learn process by setting up the Define Object Filter. a. In QuickTest, click Resources > Object Repository Manager.

Page 63: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

63

The Object Repository Manager window opens. b. In the Object Repository Manager window, click Object > Navigate and Learn. Both QuickTest and the Object Repository Manager are hidden. c. The first time you use Navigate and Learn, a message box displaying a tooltip opens. To display the Navigate and Learn toolbar, click OK. d. On the Navigate and Learn toolbar, click the Define Object Filter button. The Define Object Filter dialog box opens.

e. In the Define Object Filter dialog box, select the Selected object types option, and then click Select. The Select Object Types dialog box opens.

f. In the Select Object Types dialog box, you can click the Clear All button to clear all of the check boxes. Then, you can select the Edit Box and Image check boxes and click OK. This instructs QuickTest to learn only the objects that are needed for your test and add them to the object repository. (This helps keep object repository maintenance to a minimum.) g. To close the Define Object Filter dialog box, click OK. 6. Learn the selected object types from the Mercury Tours Web site Welcome page. a. On the Mercury Tours Web site Welcome page, click the title bar to bring it into focus. b. On the Navigate and Learn toolbar, click the Learn button. The Web page flickers and the Adding Objects message box is displayed as QuickTest begins

Page 64: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

64

adding representations of the objects on the Web page to a new object repository. Note: Adding these objects takes a few seconds. Do not interact with the Web page while Navigate and Learn runs. When the flashing stops and the Adding Objects box closes, Navigate and Learn has finished adding the objects to the object repository. c. On the Navigate and Learn toolbar, click the Close button. The Navigate and Learn toolbar closes, and QuickTest and the Object Repository Manager window are visible again. 7. Remove unneeded objects from the object repository. a. To delete the extraneous objects, in the Object Repository Manager window, expand the objects in the Test Objects tree. You will see a list of objects similar to the following:

b. Next, delete all the test objects except the Sign-In (image), password (edit box), and userName (edit box). To do so, select the object and click Edit > Delete or click the Delete button. Note: You can select multiple objects using the SHIFT and CTRL keys. c. To confirm the deletion of objects, in the confirmation box, click Yes. After deleting the extraneous objects, your tree will resemble the following:

Page 65: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

65

8. See what QuickTest learned about one of the objects. a. In the Test Objects tree, highlight the userName object. b. In the right pane, notice the object properties of the userName object. These are the descriptive properties that QuickTest will use to identify the object during a run session.

c. Next, you need to save the object repository. In the Object Repository Manager window, click File > Save or click the Save button. The Save Shared Object Repository dialog box opens. d. In the Save Shared Object Repository dialog box, browse to the location in which you want to save your object repositories, create a folder named Tutorial_ObjectRepositories, and double-click it. e. In the File Name box, type MercuryToursLogin, and click Save. 9. Next, you can associate the object repository with the Login action.

Page 66: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

66

a. Switch to the QuickTest window. b. To open the Resources pane, click View > Resources or click the Resources button. c. In the Resources pane, right-click the Login action and choose Associate Repository with Action. The Open Object Repository dialog box opens. d. In the Open Object Repository dialog box, locate and select the MercuryToursLogin.tsr shared object repository and click Open. The object repository is now associated with the Login action, and is displayed in the Resources pane as a child of that action. Note: Associating an object repository with an action enables you to use any object from that repository in any step in the associated action. 10. Finally, you can save your test. To save the test, click File > Save or click the Save button. Note:

• If a test has changed and is not yet saved, the test name in the title bar contains an asterisk.

• Congratulations! You have created a shared object repository and associated it with your test's action.

Page 67: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

67

11.3 Using Multiple Object Repositories In the previous section, you created a shared object repository for the Welcome page of the Mercury Tours Web site. Now, you will learn to create a shared object repository for each of the remaining pages in the site. Tip: It is recommended to always create a separate shared object repository for each page in your Web site or each area of your application. This helps to find the correct object easily when adding or modifying test steps or when performing maintenance tasks when objects are added, removed, or modified in your application. For the purposes of this tutorial, instruct QuickTest to learn all of the objects on each page. At this point, do not associate the object repositories with a specific action. 1. Log on to the Mercury Tours Web site. a. Open Internet Explorer and browse to the Mercury Tours Web site (http://newtours.demoaut.com). b. In the User Name and Password boxes, type tutorial and then click Sign-In. The Flight Finder page opens. 2. Create a new shared object repository. a. To open the Object Repository Manager window, click Resources > Object Repository Manager in QuickTest. The Object Repository Manager window opens. b. In the Object Repository Manager window, click File > New. A blank shared object repository opens. 3. Start the Navigate and Learn process by setting up the Define Object Filter. a. In the Object Repository Manager window, click Object > Navigate and Learn. Both QuickTest and the Object Repository Manager are hidden. b. On the Navigate and Learn toolbar, click the Define Object Filter button. The Define Object Filter dialog box opens.

Page 68: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

68

c. In the Define Object Filter dialog box, select All object types and click OK. 4. Learn all of the objects from the Mercury Tours Web site Flight Finder page. To instruct QuickTest to learn all of the objects in the Mercury Tours Web site Flight Finder page that match your filter and to add them to a shared object repository, follow the steps given below: a. To change the focus from the Navigate and Learn toolbar to the Web page you want QuickTest to learn, click the Find a Flight page title bar. b. On the Navigate and Learn toolbar, click the Learn button. The Web page flickers and the Adding Objects message box is displayed as QuickTest begins adding representations of the objects on the Web page to a new object repository. Note: Adding these objects takes a few seconds. Do not interact with the Web page while Navigate and Learn runs. c. On the Navigate and Learn toolbar, click the Close button. The Navigate and Learn toolbar closes, and QuickTest and the Object Repository Manager window are visible again. 5. Save the shared object repository. a. In the Object Repository Manager window, click File > Save or click the Save button. The Save Shared Object Repository dialog box opens. b. In the Save Shared Object Repository dialog box, browse to the Tutorial_ObjectRepositories folders and select it. c. In the File Name box, type MercuryToursFlightFinder and click Save. 6. Create a new shared object repository; add objects to it, and save the repository. a. On the Flight Finder page, click Continue.

Page 69: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

69

The Select Flight page opens. You are now ready to add objects from this page. b. Switch to the Object Repository Manager window and click File > New. A blank shared object repository opens. c. In the Object Repository Manager window, click Object > Navigate and Learn. Both QuickTest and the Object Repository Manager are hidden. d. To change the focus from the Navigate and Learn toolbar to the Web page you want QuickTest to learn, click the Select Flight page title bar. e. On the Navigate and Learn toolbar, click the Learn button. The Web page flickers and the Adding Objects message box is displayed as QuickTest begins adding representations of the objects on the Web page to a new object repository. Note: Adding these objects takes a few seconds. Do not interact with the Web page while Navigate and Learn runs. f. On the Navigate and Learn toolbar, click the Close button. The Navigate and Learn toolbar closes, and QuickTest and the Object Repository Manager window are visible again. g. In the Object Repository Manager window, click File > Save or click the Save button. The Save Shared Object Repository dialog box opens. h. In the Save Shared Object Repository dialog box, browse to the Tutorial_ObjectRepositories folder and select it. i. In the File Name box, type MercuryToursSelectFlight and click Save. 7. Create new shared object repositories for each of the remaining Web pages. a. Repeat step 6 to create shared object repositories for the following pages:

• Book a Flight. • Flight Confirmation.

b. Name the object repositories MercuryToursBookFlight and MercuryToursFlightConfirmation, respectively. 8. Associate the MercuryToursFlightFinder.tsr object repository with the FlightFinder action. a. Switch to QuickTest and click View > Resources or click the Resources Pane button to open the Resources pane. b. In the Resources pane, right-click the FlightFinder action and choose Associate Repository with Action.

Page 70: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

70

The Open Shared Object Repository dialog box opens. c. In the Open Shared Object Repository dialog box, browse and select the MercuryToursFlightFinder.tsr shared object repository and click Open. The object repository is now associated with the FlightFinder action, and is displayed in the Resources pane as a child of that action. 9. Associate the remaining object repositories with the relevant actions. Repeat step 8 and:

• Associate MercuryToursSelectFlight.tsr with the SelectFlight action. • Associate the following repositories with the BookFlight action:

o MercuryToursBookFlight.tsr o MercuryToursFlightConfirmation.tsr

Note: Later, when you add steps to each action, all of the required test objects will be available for use. 10. Finally, save your test by clicking File > Save or click the Save button.

Page 71: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

71

Chapter 12: Action

12.1 Creating an Action Actions are defined as units that divide a test into logical sections. When you create a new test, it contains a call to one action. Dividing tests into calls to multiple actions helps you design more modular and efficient tests. QTP allows you to insert several types of actions into tests. An internal action, also known as a source test, is an action that is stored in the local test. An external action is a referenced call to an action that is stored in a different test. For example, you may want to use an action in multiple tests—you would store the action as an internal action in one test and insert calls to that action from other tests. In the other tests, the action would be available as an external action. When you insert a call to a new action, it is reusable by default and you are able to insert calls to the action from any test. Reusable actions are especially useful when you need to include a process in several tests, such as logging in to your application, or to insert several times in the same test, such as filling in user credential dialog boxes that open whenever a user tries to access a secure part of your application. Reusable actions can be internal or external actions. When you insert calls to existing (reusable) actions, they are read-only in the calling test. You can modify them in the test in which they are stored. Inserting calls to existing actions enables you to create and enhance your action's test steps only once and then to call the same action from several tests. This way, you can easily maintain tests, because when your application changes, you only have to update the existing action stored with the original tests. Also, this helps ease test maintenance because when you modify these actions, all tests containing calls to these actions are updated. You can then create and enhance your action's test steps only once and then insert calls to the existing actions as needed from any test. If you want to use the same or similar actions in many tests, you can create a repository test to store your reusable actions. Then, you can insert calls to these existing actions from other tests, linking these actions to the source test. You can also insert a copy of an action in your tests if you want to make changes to the action steps. This will insert the action as an internal action in the current test. Copies of actions are not linked to the source test, so that when you insert a call to a copy of an existing action, you can make changes to the copied action, and your changes will neither affect, nor be affected by, any other test. To prevent an action from being reused in any test, you can make it non-reusable. Non-reusable actions are internal actions that can be used only once. In this section, you will learn to create a new test and rename an action so that anyone viewing this test will know the purpose of the action. 1. Start QuickTest. a. To open QuickTest, click Start > Programs > HP QuickTest Professional > HP QuickTest Professional. The Add-in Manager dialog box is displayed. b. In the Add-in Manager dialog box, ensure that the Web Add-in is selected, and clear all

Page 72: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

72

other add-ins. c. To close the Add-in Manager dialog box, click OK. d. Open QuickTest. While QuickTest loads your selected add-ins, the QuickTest splash screen is displayed. This may take a few seconds. e. If QuickTest is already open, identify the add-ins that are loaded by selecting Help > About QuickTest Professional. If the Web Add-in is not loaded, you must exit and restart QuickTest. f. When the Add-in Manager opens, select the Web Add-in, and clear all other add-ins. Note: If the Add-in Manager does not open when starting QuickTest, click Tools > Options. Next, on the General tab, select Display Add-in Manager on startup. When you exit and restart QuickTest, the Add-in Manager opens. 2. Create a new test in one of the following ways: a. In the Start Page window, in the Welcome! area, click the New Test button. b. In the QuickTest main window, click File > New > Test, or click the New button down arrow and click Test. If a test is already open, clicking the New toolbar button opens a new test. A blank test opens. 3. Rename Action1 so that it has a logical name. a. To display the Test Flow pane, click the Test Flow tab. Note: If the Test Flow tab is not visible, then click View > Test Flow or click the Test Flow Pane button to display it. b. Next, in the Test Flow pane, select Action1 and click Edit > Action > Rename Action. c. In the confirmation box, click Yes. The Rename Action dialog box opens.

d. In the Rename Action dialog box, in the New name box, type the name of action and then click OK to save the change. 4. Create a new action named FlightFinder. a. To create a new action, click Insert > Call to New Action or click the Insert Call to

Page 73: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

73

New Action button. The Insert Call to New Action dialog box opens.

b. In the Insert Call to New Action dialog box, in the Name box, type FlightFinder. c. Ensure that the Reusable Action check box and the At the end of the test option are selected. d. To close the Insert Call to New Action dialog box, click OK. The dialog box closes and the FlightFinder action is added to the end of your test. 5. Create calls to additional actions.

• You can repeat step 4 to add the following actions: o SelectFlight o BookFlight

Your test now contains all of the actions needed to begin this tutorial. 6. Save your test. a. Finally, you can save your test by clicking File > Save or clicking the Save button. The Save dialog box opens to the Tests folder. b. In the Save dialog box, create a folder named Tutorial and select it. c. In the File name box, type MercuryTours. d. Ensure that Save Active Screen files is selected, and then click Save. The test name (MercuryTours) and path are displayed in the title bar of the main QuickTest window. Note: If a test has changed and is not yet saved, the test name in the title bar contains an asterisk.

Page 74: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

74

12.2 Different Ways to Insert Calls to Actions QTP gives you the liberty to insert calls to actions in your test at any time (except during a test run). You can use any of the following menu options or toolbar buttons to add actions to your test:

Toolbar buttons Action Insert > Call to New Action or use the Insert Call to New Action button

This option inserts a new, empty action in your test. (You can also click the down arrow and choose Call to Copy of Action or Call to Existing Action, described below.)

Edit > Action > Split Action or use the Split Action button

This option divides an existing action into two separate actions at the step you specify.

Insert > Call to Copy of Action or right-click an action and choose Insert Call to Copy of Action.

This option inserts a copy of an existing action in your test. The action is not linked to the source test from which you copied it.

Insert > Call to Existing Action or right-click an action and choose Insert Call to Existing Action.

This option inserts a call to an existing action in your test. You can insert a call to an action that is stored in the current test (if you want to insert the same action twice, for example), or you can insert a call to an action in another test. The action is linked to the source test from which you copied it.

Page 75: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

75

12.3 Parameterizing an Action In the QuickTest window of a test, the Data Table at the bottom of the window comprises of tab for each action and a Global tab. Note: If the Data Table is not visible, then click View > Data Table to display it, or click the Data Table button. The Global tab is a data sheet and the data on it is used for the entire test. If five rows of data are displayed in the Global table, the test will run five times (five full iterations). In addition, you can create data sets for each action, using the relevant action sheet. If you parameterize a step using a Data Table parameter from a local action sheet and enter five rows of data in that sheet, you can define that action to run five times within one test iteration. In this section, you will create a data set for the FlightFinder action to check how the application handles multiple orders during a single user session. 1. Open the FlightFinder action.

• In the Test Flow pane, double-click the FlightFinder action. The FlightFinder action opens.

2. Select a step to parameterize. • In the Keyword View, in the toPort row, click the Value cell and then click

the parameterization icon. The Value Configuration Options dialog box opens.

3. Enter the parameter information. a. In the Value Configuration Options dialog box, click the Parameter option and ensure that in the Parameter list, DataTable is selected. b. In the Name box, type arrival. c. To run the iteration on the test and not on the action, select the Global sheet option.

Page 76: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

76

d. To close the Value Configuration Options dialog box, click OK. QuickTest automatically adds the arrival column to the Global data sheet and inserts San Francisco into the first cell of the arrival column. 4. Parameterize additional steps. It is not logical for a single customer to fly to two different locations on the same dates, therefore, it makes important for you to parameterize the departure and arrival dates. a. In the Keyboard View, in the fromMonth row, click the Value cell and then click the parameterization icon.

The Value Configuration Options dialog box opens. b. In the Value Configuration Options dialog box, select Parameter and ensure that the DataTable option is selected. c. In the Name box, type fromMonth and then select the Global sheet option.

d. To close the Value Configuration Options dialog box, click OK. The third column of the Global sheet of the Data Table displays your changes. e. In the Keyword View, in the toMonth row, click the Value cell and then click the parameterization icon. The Value Configuration Options dialog box opens. f. In the Value Configuration Options dialog box, select Parameter and ensure that the DataTable option is selected. g. In the Name box, type toMonth and select the Global sheet option. h. To close the Value Configuration Options dialog box, click OK. The fourth column of the Global sheet of the Data Table displays your changes. 5. Enter the parameterization data in the Data Table. a. In the Data Table, click the Global tab. b. In the second row of the arrival column, type Portland. c. In the second row of the fromMonth and toMonth columns, type October. d. Click an empty cell of the first or second row to save your changes. The Data Table should appear similar to the following:

Page 77: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

77

6. Save the test. Finally, save the test by clicking File > Save or clicking the Save button. You have now created a test that signs in to the Mercury Tours site, submits two flight orders: a flight from New York to San Francisco from December 29 to December 31, and a flight from London to Portland from October 29 to October 31, and then returns to the starting point of the test by clicking the Home link.

Page 78: 114.79.143.8114.79.143.8/studentdesk/Download/STP_QuickTest_Professional_Version2.pdf · 2 Contents Chapter 1: About This Book ..........................................................................................................................5

78

Summary QuickTest Professional (QTP) is an automated testing tool used for testing several software applications and environments. It is primarily used to test standard Windows applications, Web objects, ActiveX controls, Visual Basic applications, and multimedia objects on Web pages. It has an intuitive graphical user interface (GUI) to perform functional and regression testing. It helps for faster test creation, easier maintenance, and more powerful data-driving capability. It also helps record events you perform on an application and replay them back. In this tutorial, you learned about:

• QTP and its features • Installation of QTP • Testing with QTP • Key elements of the QTP window • Sample applications • Recording, running, and saving a script • Synchronization point • Checkpoints • Parameterization • Object repository • Action