35
Advanced QuickTest Professional 9.2 Web-based Training Exercises

QTP92Adv Cbt Exercise

Embed Size (px)

Citation preview

Page 1: QTP92Adv Cbt Exercise

Advanced QuickTest Professional 9.2 Web-based Training Exercises

Page 2: QTP92Adv Cbt Exercise

HP Software Education

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

Part 1: Translate the given KEYWORD VIEW steps into EXPERT VIEW code. Part 2: Open and run an existing script. Part 3: Type new steps in the script. Part 4: Run the updated script.

Figure 3-11 SearchFlights Action Part 1: Translate the Given Keyword View Steps into Expert View Code Figure 3-11 displays the steps of an action in KEYWORD VIEW. Type the VBScript code that corresponds to the steps shown in Figure 3-11. _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 3: QTP92Adv Cbt Exercise

HP Software Education

Part 2: Open and Run an Existing Script

1. Invoke QuickTest Professional. 2. In the QUICKTEST PROFESSIONAL - ADD-IN MANAGER dialog box, check the WEB check box

and click OK. 3. Open the LOGINLOGOUT test located in the C:\TRAINING\ADVANCEDQTP92\TESTS folder. The test runs on the Mercury Tours application and contains the LOGIN and LOGOUT actions.

Figure 3-12 LoginLogout Test

4. Select START >PROGRAMS >MERCURY TOURS >START SERVER to start the Apache Web server. 5. Verify that the START SERVER window displays the following line: Apache/1.3.17 <Win32> ApacheJServ/1.1.2 running... 6. Minimize the START SERVER window. 7. On the QuickTest Professional toolbar, click RUN to run the test. The RUN dialog box

appears. Click OK. 8. This test is set up to launch the AUT when a run session starts and to exit the application when the session ends. When the run completes, a TEST RESULTS window opens. 9. In the TEST RESULTS window, click VIEW EXPAND ALL. Confirm that the script runs completely and successfully.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 4: QTP92Adv Cbt Exercise

HP Software Education

Figure 3-13 LoginLogout Results

You can compare your test results with Figure 3-13. Part 3: Type New Steps in the Script

1. From the QuickTest Professional menu bar, select FILE >SAVE AS to save the test with the name USINGEXPERTVIEW. 2. In KEYWORD VIEW, create a new action named SEARCHFLIGHTS.

a) Click INSERT CALL TO NEW ACTION. A new window opens. b) Type SEARCHFLIGHTS as the name of the new action.

c) Select the AT THE END OF THE TEST option. d) Click OK. 3. Drag and drop the SEARCHFLIGHTS action so that it is the second action in the test flow. 4. Associate your new action with the shared object repository: C:/TRAINING/ADVANCED QTP92/OBJECTS/MERCURYTOURS.TSR

Figure 3-14 New SearchFlights Action

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 5: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

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

When you type BROWSER, what happens? _______________________________________________________________ _______________________________________________________________ 6. After typing the step, save the updated script in your tests folder as USINGEXPERTVIEW. Part 4: Run the Updated Script 1. Close any open browser running the Mercury Tours application. Note: Keep the command window with the Mercury Tours application server open. 2. Run the updated test. After it completes execution, the test opens a TEST RESULTS window. If your test did not complete successfully, use the QuickTest Professional debug features to identify the problems in the script. Note: Check with your instructor if problems persist.

Page 6: QTP92Adv Cbt Exercise

HP Software Education

Exercise: Working with Object Properties In this exercise, you enhance an existing script for the Flight Reservation application to retrieve run-time object properties.The exercise consists of the following parts:

Part 1: Open and run an existing script. Part 2: Determine the additional steps needed to update the script. Part 3: Type new steps in the script. Part 4: Run the updated script.

Part 1: Open and Run an Existing Script 1. Invoke QuickTest Professional. Select the Web add-in. 2. From the C:\TRAINING\QTP92ADVANCED\TESTS folder, open the OBJECTPROPERTIES test. The test runs on the Flight Reservation application and contains the LOGIN, FLIGHTORDER, and EXIT actions. The FLIGHTORDER action is driven by its local data table.

Figure 4-6 The ObjectProperties Test

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 7: QTP92Adv Cbt Exercise

HP Software Education

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

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

Figure 4-7 Test Results

How many times did each action run? _______________________________________________________________ _______________________________________________________________ 5. Close the TEST RESULTS window.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 8: QTP92Adv Cbt Exercise

HP Software Education

Part 2: Determine the Additional Steps Needed to Update the Script You are asked to update the script so that it retrieves the total price and order number information for each flight booked. The information retrieved should be reported into the test results.

Figure 4-8 Flight Reservation

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

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

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________ Write the VBScript expressions that would identify the total price object and the order number object. Remember to include the object hierarchy.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 9: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

2. Do you use GETROPROPERTY or GETTOPROPERTY to retrieve the desired information? What is the name of the property you would retrieve? How did you find your answer? _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

Write the VBScript statements that retrieve the desired property from the two Objects. _______________________________________________________________ 3. Do you use a constant or a variable to store the information you retrieved? Explain your

answer. _______________________________________________________________ Write the VBScript statements for declaring and setting the values of your constants or variables. _______________________________________________________________ _______________________________________________________________ 4. Which object and method is used to report the information to the results? _______________________________________________________________ Write the VBScript statements that report the values of the information you retrieved. Review the actions in the OBJECTPROPERTIES test. In which action do you add the new steps? _______________________________________________________________

Page 10: QTP92Adv Cbt Exercise

HP Software Education

Part 3: Type New Steps in the Script

1. From the QuickTest Professional menu bar, select FILE > SAVE AS to save the test with the name MYOBJECTPROPERTIES. 2. From EXPERT VIEW, use the action list to select the FLIGHTORDER action for editing.

Figure 4-9 Action Drop Down List

3. Append the code to the existing script that you wrote in Part 2. 4. After appending the new code, save the updated script.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 11: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Part 4: Run the Updated Script

1. Close any open instances of the Flight Reservation application. 2. Run the updated test. View the TEST RESULTS at the completion of the test.

If the test did not complete successfully, use the QuickTest Professional debug features to identify the problems in the script. Note: Check with your instructor if problems persist.

Exercise: Working with Dynamic Objects In this exercise, you update an existing script for the Flight Reservation application so that the script works for dynamic objects. The exercise consists of the following parts:

Part 1: Open and run an existing script. Part 2: Determine the new steps needed to update the script. Part 3: Correct the script by updating the OBJECT REPOSITORY. Part 4: Correct the script by using programmatic descriptions.

Part 1: Open and Run an Existing Script

1. Open QuickTest Professional. Load the web add-in. 2. Open the FAXORDER test located in the C:\TRAINING\QTP92ADVANCED\TESTS folder.

The test runs on the Flight Reservation application and contains the LOGIN, ORDER_FAX_FLIGHT, and EXIT actions.

Page 12: QTP92Adv Cbt Exercise

HP Software Education

Figure 5-7 The FaxOrder Test Note: The ORDER_FAX_FLIGHT action is the only action defined in this script. The LOGIN and EXIT actions are calls to actions that enable you to login and exit the application respectively. 3. On the QuickTest Professional toolbar, click RUN to run the test. The RUN dialog box appears. 4. Click OK. This test launches the AUT when a run session starts.The test run does not complete successfully. Answer the following questions regarding the run session. a) On which step does the test script fail? What run error message is displayed?

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________

b) QuickTest Professional cannot locate a test object in the AUT. Which object is QuickTest Professional looking for and why is this object not in the AUT? _______________________________________________________________ _______________________________________________________________ Part 2: Determine the New Steps that You Need to Add to the Script You need to correct the script in Part 1. The FAX ORDER dialog box is named dynamically, based on the order number of the flight.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 13: QTP92Adv Cbt Exercise

HP Software Education

Figure 5-8 Fax Order Dialog Box

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

1. Review the code for the ORDER_FAX_FLIGHT action. Which steps in the action do you need to correct?

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________

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

3. The title of the FAX ORDER dialog box is set dynamically, based on the order number of the flight. How do you retrieve the correct order number for the flight? _______________________________________________________________

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________

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

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 14: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

_______________________________________________________________ _______________________________________________________________ Write the regular expression that you could enter in the OBJECT REPOSITORY to make the property that specifies the title of a dialog box object, match dynamic values. _______________________________________________________________

The & operator is used to concatenate strings. For example, the evaluation of “a” & “b” is “ab”. Using the & operator, write the programmatic description that you use to correctly identify the FAX ORDER dialog box. _______________________________________________________________

Page 15: QTP92Adv Cbt Exercise

HP Software Education

Part 3: Correct the Test by Updating Object Repository

1. Open the FAXORDER test located in the C:\TRAINING\QTP92ADVANCED\TESTS folder. 2. Create a new OBJECT REPOSITORY: a) From the QuickTest Professional menu bar, select RESOURCES >OBJECT REPOSITORY MANAGER to open the OBJECT REPOSITORY MANAGER dialog box. b) From the OBJECT REPOSITORY MANAGER menu bar, open the file FLIGHTRESERVATION.TSR located in the C:\TRAINING\QTP92ADVANCED\OBJECTS folder. c) From the OBJECT REPOSITORY MANAGER menu bar, select FILE SAVE AS to save the OBJECT REPOSITORY with the name <YOURINITIALS>_FLIGHTRESERVATION.

Figure 5-9 The Object Repository Manager

3. To update the dynamic object description: a) Locate the FAX ORDER dialog box in the OBJECT REPOSITORY MANAGER. b) Update the appropriate property value to use the regular expression that you wrote in Part 2. c) Save the new OBJECT REPOSITORY in the OBJECT REPOSITORY MANAGER dialog box. d) Close the OBJECT REPOSITORY MANAGER dialog box. 4. To associate the new OBJECT REPOSITORY with your test:

a) From the QuickTest Professional menu bar, select RESOURCES > ASSOCIATE REPOSITORIES to open the ASSOCIATE REPOSITORIES dialog box.

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

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 16: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

you to confirm the removal. c) Click YES to confirm the removal of the repository. d) Click the ‘+’ ADD REPOSITORY button. e) Select the new saved OBJECT REPOSITORY. f) In the ASSOCIATE REPOSITORIES dialog box, in the AVAILABLE ACTIONS list, double-click ORDER_FAX_FLIGHT to move it to the ASSOCIATED ACTIONS list. g) Click OK to close the ASSOCIATE REPOSITORIES dialog box.

5. Close any open instances of the Flight Reservation application. 6. Run the test. The test should complete successfully. Note: Check with your instructor if problems persist.

Part 4: Correct the Test by Using Programmatic Descriptions

1. Open the FAXORDER test located in the C:\TRAINING\QTP92ADVANCED\TESTS folder. 2. From the QuickTest Professional menu bar, select FILE >SAVE AS to save the test with the name MYFAXORDER. 3. To ensure that the new test uses the original Object Repository:

Note: You must use the version of Object Repository that you used in Part 1. a) From the QuickTest Professional menu bar, select RESOURCES >ASSOCIATE REPOSITORIES to open the ASSOCIATE REPOSITORIES dialog box. b) Ensure that the FLIGHTRESERVATION.TSR file is loaded in the REPOSITORIES list. If not, remove the existing file by clicking the ‘X’ REMOVE REPOSITORY button and then select the FLIGHTRESERVATION.TSR file located in the C:\TRAINING\QTP92ADVANCED\OBJECTS folder. c) In the ASSOCIATE REPOSITORIES dialog box, in the AVAILABLE ACTIONS list, double-click ORDER_FAX_FLIGHT to move it to the ASSOCIATED ACTIONS list.

Page 17: QTP92Adv Cbt Exercise

HP Software Education

Figure 5-10 The Associate Repositories Dialog Box d) Close the ASSOCIATE REPOSITORY dialog box. 4. Within the test, click EXPERT VIEW. 5. In EXPERT VIEW, from the action list, select the ORDER_FAX_FLIGHT action to edit it. 6. Update the code to use the programmatic description that you wrote in Part 2. 7. After updating the code, save the updated script. 8. Close any open instances of the Flight Reservation application. 9. Run the updated test. Answer the following questions regarding the run session: a) The test still does not complete successfully. On which step does the test script fail? What run error message is displayed? _______________________________________________________________ _______________________________________________________________ b) Why is QuickTest unable to locate the object inside the FAX ORDER dialog box? _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 18: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

_______________________________________________________________ c) How can you correct the step? _______________________________________________________________ __________________________________________________________________ __________________________________________________________________ _______________________________________________________________ _______________________________________________________________ d) Are there any other steps that are to be corrected in the same way? _______________________________________________________________ _______________________________________________________________ 10. Correct the steps and run the test again. If your test did not complete successfully, use the QuickTest Professional debug features to help pinpoint the problem areas in the script. Note: Check with your instructor if problems persist.

Page 19: QTP92Adv Cbt Exercise

HP Software Education

Exercise: Using VBScript Operators, Statements and Functions In this exercise, you determine the VBScript operators, statements, and functions required for a specific purpose. You update a test by using VBScript and other features in QuickTest Professional. The exercise consists of the following parts:

Part 1: Analyze the requirements. Part 2: Update the script to confirm that the number of itineraries increases by one after a flight purchase.

Optional Part 3: Update the script so that the results contain the year and month when the first itinerary is booked.

Part 1: Analyze the Requirements You need to update a flight purchase script. The updated script should have achieved following objectives: • After a flight purchase, the number of itineraries increases by one. • The script reports the year and month of the booking of the first itinerary to results. Answer the following questions to break down the requirements for this test case. 1. The itinerary page of the Mercury Tours application, as shown in Figure 6-8, includes dynamic objects to display the complete list of flights that you booked.

Figure 6-8 The Dynamic Itinerary Page of the Flight Reservation Application

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 20: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

a) Which objects on the itinerary page do you count to determine the number of current itineraries? Which properties you use to identify those objects? (Hint: Open the Mercury Tours application and use the OBJECT SPY to examine how the objects are defined.) __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ b) How do you retrieve a count of the above objects on the itinerary page? __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ c) How do you save the count of the original number of itineraries to compare it to a later count? __________________________________________________________________ __________________________________________________________________ d) How do you indicate success in the test results if the number of itineraries increments correctly and indicates failure if the number does not increment successfully? __________________________________________________________________ __________________________________________________________________

Optional - The ITINERARY page, as shown in Figure 6-9, displays a list of booked itineraries in the order that they were purchased, with the earliest itinerary listedfirst. For each itinerary, there is a WebTable cell with the text, “ Booked YYYY-MM-DD HH:MM:SS”. (Note: There is a space character before “Booked”). The WebTable represents information in tables in Web applications. The name property for the WebTable always matches the name of the check box object for that same itinerary.

Page 21: QTP92Adv Cbt Exercise

HP Software Education

Figure 6-9 The Dynamic Itinerary Page and Object Spy a) The following code is not commented. Use the space provided to describe the functionality of each block of code. i. Code 1: Set objCheckboxDesc = Description.Create() objCheckboxDesc ("type").Value = "checkbox"

Set objCheckboxes = Browser("Welcome: Mercury Tours").Page("Itinerary: Mercury Tours").ChildObjects(objCheckboxDesc) __________________________________________________________________ ii. Code 2: strName = objCheckboxes(0).GetROProperty("name") __________________________________________________________________ iii. Code 3: Set objTableDesc= Description.Create() objTableDesc("html tag").Value = "table" objTableDesc("rows").Value = 1 objTableDesc("name").Value = strName Set objBookedTables = Browser("Welcome: Mercury Tours").Page("Itinerary: Mercury Tours").ChildObjects(objTableDesc) __________________________________________________________________ __________________________________________________________________ iv. Code 4: If objBookedTables.Count <> 1 Then Reporter.ReportEvent micWarning , "objBookedTables.Count", objBookedTables.Count&" were found when one object should have been found." __________________________________________________________________ v. Code 5: Else strBookedFirstItinerary = objBookedTables(0).GetROProperty("text")

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 22: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Reporter.ReportEvent micDone, "strBookedFirstItinerary", strBookedFirstItinerary End If __________________________________________________________________ __________________________________________________________________

b) How do you retrieve year information from the text string “ Booked YYYYMM- DD HH:MM:SS”? (Note: There is a space character before “Booked”)

_______________________________________________________________ __________________________________________________________________ c) How do you retrieve month information from the text string “ Booked YYYYMM- DD HH:MM:SS”? (Note: There is a space character before “Booked”) _______________________________________________________________ _______________________________________________________________ d) How do you convert the month value from a number to the name for that month? _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

Part 2: Update the Script to Confirm that the Number of Itineraries Increases by One After a Flight Purchase 1. Within the Mercury Tours application, cancel all itineraries except one. Note: You can do this by clicking CANCEL ALL RESERVATIONS and then adding a new purchase, or by selecting all the itineraries except one and clicking CANCEL CHECKED RESERVATIONS. 2. Open the VBSCRIPT test located in the C:\TRAINING\ADVANCED QTP92\TESTS folder. 3. Click the START SERVER shortcut on the desktop to start the application server for Mercury Tours. Minimize the START SERVER window but do not close it. 4. From the QuickTest Professional menu bar, select FILE >SAVE AS to save the test as MYVBSCRIPT1. 5. Update the test with the code that increases the number of itineraries by one. 6. Run and debug the updated test. If your test did not complete successfully, use the QuickTest Professional debug features to help identify the trouble areas in the script.

Note: Check with your instructor if problems persist.

Page 23: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Optional Part 3: Update the Script so that the Results Contain the Year and Month When the First Itinerary is Booked

1. Open the VBSCRIPT test located in the C:\TRAINING\QTP92ADVANCED\TESTS folder. 2. Click the START SERVER shortcut on the desktop to start the application server for Mercury Tours. Minimize the START SERVER window but do not close it. 3. From the QuickTest Professional menu bar, select FILE >SAVE AS to save the test as

MYVBSCRIPT2. 4. Update the test with the code that generates the year and month when the first itinerary was booked. 5. Run and debug the updated test. 6. Confirm that your script works even when the Application Under Test (AUT) starts with no itineraries created.

If your test does not complete successfully, use the QuickTest Professional debug features to help identify the trouble areas in the script. Note: Check with your instructor if problems persist.

Page 24: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Exercise: Working with Dynamic Data In this exercise, you update a test script so that it no longer uses hard-coded data but uses data retrieved dynamically from the application. The exercise consists of the following parts:

Part 1: Review the existing script. Part 2: Analyze the requirements. Part 3: Update the script for the first objective. Part 4: Update the script for the second objective.

Part 1: Review the Existing Script Open and run the script DYNAMICDATA script located in theC:\TRAINING\QTP92ADVANCED\TESTS folder. Answer the following questions:

1. How many actions are present in this script? _______________________________________________________________ _______________________________________________________________ 2. How many times is each action executed during a run session? _______________________________________________________________ 3. Between which two cities are the passengers traveling? _______________________________________________________________

Part 2: Analyze the Requirements You need to update the script so that it: • Retrieves the options for departure and arrival cities from the application at runtime. • Tests that a flight can be purchased from three departure cities to three different arrival cities. Answer the following questions to break down the requirements for this test case.

1. How do you retrieve the departure city information and arrival city information? In which of the existing actions do you add this code? _______________________________________________________________ _______________________________________________________________ 2. How do you build a list of the possible pairs of departure and arrival cities? In which of the existing actions do you add this code? _______________________________________________________________ _______________________________________________________________ 3. How do you save the list of departure-arrival pairs for use in the PURCHASEFLIGHT action? _______________________________________________________________ 4. How do you update the PURCHASEFLIGHT action to use the dynamic data? _______________________________________________________________ _______________________________________________________________

Page 25: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Part 3: Update the Script for the First Objective

1. From the QuickTest Professional menu bar, select FILE >SAVE AS to save the test as MYDYNAMICDATA. 2. Update the test with code necessary to achieve this objective. 3. Run and debug the updated test.

If your test did not complete successfully, use the QTP debug features to help identify the trouble areas in the script. Note: Check with your instructor if problems persist. Part 4: Update the Script for the Second Objective 1. Update the test with the code necessary to validate purchases for each combination of departure and arrival cities. Note: For the purposes of this exercise, reduce the number of the combinations by using just the first three departure cities and last three arrival cities instead of the full lists. 2. Run and debug the updated test. If your test did not complete successfully, use the QTP debug features to help identify the trouble areas in the script. Note: Check with your instructor if problems persist.

Page 26: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Exercise: Retrieving External Data In this exercise, you update a script to retrieve test data from a Microsoft Excel file, MercTours_TestData.xls and a Microsoft Access file, MercTours_TestData.mdb. The exercise consists of the following parts:

Part 1: Import data from a Microsoft Excel file. Part 2: Import data from a Microsoft Access file.

Part 1: Import Data from a Microsoft Excel File

1. Open the EXTERNALDATA test, located in the C:\TRAINING\QTP92ADVANCED\TESTS folder. 2. From the QuickTest Professional menu bar, select FILE SAVE AS to save the test as MYEXTERNALDATA. 3. Which action in the script do you need to update for this exercise? _______________________________________________________________

4. Write the VBScript code to retrieve information from the Microsoft Excel file, MercTours_TestData.xls. _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ 5. Use code to update the test so that you canate the test with the code to retrieve data from the Microsoft Excel worksheet. 6. Run and debug the updated test.

If the test fails, use the QuickTest Professional debug feature to troubleshoot the script. Note: Check with your instructor if problems persist. Part 2: Import Data from a Microsoft Access File 1. Open the EXTERNALDATA test, located in the C:\TRAINING\QTP92ADVANCED\TESTS folder. 2. From the QuickTest Professional menu bar, select FILE SAVE AS to save the test with the

name MYEXTERNALDATAACCESS. 3. Which action in the script do you need to update for this exercise? _______________________________________________________________ 4. Write the VBScript code to open a connection to the Microsoft Access database, MercTours_TestData. _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ 5. Write the VBScript code to retrieve the list of departure and arrival cities.

Page 27: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Note: The MERCTOURS_TESTDATA database has two tables, DEPARTURE_CITIES and ARRIVAL_CITIES. Both tables have a column named CITY. The SQL query used to retrieve the departure cities data is: Select City From_Departure Cities

The SQL query to retrieve the arrival cities data is: Select City From Arrival_Cities _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ 6. Where will you store the results returned by the queries? _______________________________________________________________ 7. Write the VBScript code to store the list of departure cities.

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

8. Write the VBScript code to clean up the Connection and RecordSet objects.

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

9. Use code to update the test so that you can retrieve data from the Microsoft Access database. 10. Run and debug the updated test. If the test fails, use the QuickTest Professional debug feature to troubleshoot the script. Note: Check with your instructor if problems persist.

Page 28: QTP92Adv Cbt Exercise

HP Software Education

Exercise: Creating New Procedures In this exercise, you test a new procedure and library file. You then update a script to use the new procedure. The exercise consists of the following parts:

Part 1: Analyze the requirements. Part 2: Define and test the new procedure in QuickTest Professional. Part 3: Create and associate a new library file by using the FUNCTION LIBRARY editor.

Figure 9-14 Dynamic Itinerary Page

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

2. Are any input parameters required for the new procedure? _______________________________________________________________ 3. What assumptions does the new procedure make about the state of the application under test? _______________________________________________________________ 4. Open the NEWPROCEDURE test located in the C:\TRAINING\QTP92ADVANCED\TESTS folder.

This script includes code that retrieves the number of current itineraries.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 29: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

5. Write the VBScript code to create the desired new procedure. Name the procedure as GetCurrentItineraryCount. _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

_______________________________________________________________ _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

6. Do you mark the new procedure as Public or Private? _______________________________________________________________ Part 2: Define and Test the New Procedure in QuickTest Professional

1. From the QuickTest Professional menu bar, select FILE > SAVE AS to save the test as MYNEWPROCEDURE. 2. Type the GetCurrentItineraryCount procedure into the test with the code that you wrote in Part 1. 3. Update the test so that the procedure is called in the appropriate places. 4. Run and debug the test. Part 3: Create and Associate a New Library File by Using the Function Library Editor 1. To create a new function library file: a) From the QuickTest Professional menu bar, select FILE NEW FUNCTION LIBRARY. b) Cut the GETCURRENTITINERARYCOUNT procedure from the NEWPROCEDURE test and paste the procedure into the new function library file. c) Save the function library file as MYLIBRARYFILE.QFL in the folder C:\TRAINING\QTP92ADVANCED\FUNCTION LIBRARY folder. 2. To associate the library file with QuickTest script: a) With the NEWPROCEDURE test open, from the QuickTest Professional menu bar, select FILE OPEN FUNCTION LIBRARY and select the MYLIBRARYFILE.QFL file created in the previous step. b) From the QuickTest Professional menu bar, select FILE ASSOCIATE LIBRARY ‘MYLIBRARYFILE.QFL’ WITH ‘MYNEWPROCEDURE’. c) QuickTest associates the function library with the open test. 3. Run and debug the updated test.

If the test does not complete successfully, use the QuickTest Professional debug features to help identify the trouble areas in the script. Note: Check with your instructor if problems persist.

Page 30: QTP92Adv Cbt Exercise

HP Software Education

Exercise: Handling Negative and Positive Test Data In this exercise, you edit a script that validates positive and negative test data. The exercise consists of the following parts: Part 1: Analyze the requirements. Part 2: Code and debug a script.

Part 1: Analyze the Requirements An existing test VALIDATELOGIN performs the following test on the Flight32 application: • Imports a list of user names and passwords from an external Microsoft Excel worksheet. • Tests whether the application under test logins for the correct set of user names and passwords, and generates an appropriate error message for the incorrect set of user names and passwords. If you try to run the script, you see that an exception occurs.

Figure 10-11 Run Errors in Test Results The exceptions occur because some user names and passwords in the imported Microsoft Excel sheet are incorrect, for these the application does not login

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 31: QTP92Adv Cbt Exercise

HP Software Education

Figure 10-12 Data Set with User Names and Passwords If the user name or the password is invalid, you need to update the script to ensure that the script: • Confirms that the proper error message is displayed and dismisses the exception. • Skips to the next user name and password combination. Which action or actions in the VALIDATELOGIN script do you need to update and why? _______________________________________________________________ _______________________________________________________________ Part 2: Code and Debug a Script

1. Open the VALIDATELOGIN script located in the C:\TRAINING\ADVANCED QTP92\TESTS folder. 2. From the QuickTest Professional menu bar, select FILE >SAVE AS to save the test as MYVALIDATELOGIN. 3. Update the script with code to achieve the given objectives. 4. Run and debug the updated test.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 32: QTP92Adv Cbt Exercise

HP Software Education

Figure 10-13 Checks for Test Cases If your test does not complete successfully, use the QuickTest Professional debug features to help identify the trouble areas in the script. Check with your instructor if problems persist.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 33: QTP92Adv Cbt Exercise

HP Software Education

Exercise: Handling Exceptions Programmatically In this exercise, you update the script so that it handles run errors programmatically. The exercise consists of the following parts:

Part 1: Analyze the requirements. Part 2: Code and debug a script.

Part 1: Analyze the Requirements An existing script EXCEPTIONHANDLING performs the following test on the Mercury Tours application: • Imports a list of departure and arrival cities from a Microsoft Excel worksheet. • Tests that a flight can be purchased for each combination of cities. Note: For the purpose of this exercise, the EXCEPTIONHANDLING script uses just the first three departure cities and last three arrival cities instead of the complete lists of cities. This reduces the number of the combinations and the time needed to run the script. If you try to run the script, you see that an exception occurs.

Figure 10-14 Run Errors in Test Results The exceptions occur because some of the cities in the Microsoft Excel worksheet are retired airports,where the airlines no longer fly. The application does not offer the option to fly to or from these retired airports. This is the correct behavior expected of the application.

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 34: QTP92Adv Cbt Exercise

HP Software Education

Figure 10-15 Data Set with Current and Retired Cities If either the departure or the arrival city is invalid, you need to update the script to ensure that the script: • Confirms that the retired city is not among the options offered in the application. • Skips to the next departure-arrival combination. 1. Which action or actions in the GOODDEANFROMEZRA script do you need to update and why? _______________________________________________________________ _______________________________________________________________ _______________________________________________________________ 2. You need to handle the exceptions programmatically. Which exception handling approach do you use? _______________________________________________________________ _______________________________________________________________ _______________________________________________________________

© Copyright 2007 Hewlett-Packard Development Company, L.P.

Page 35: QTP92Adv Cbt Exercise

HP Software Education © Copyright 2007 Hewlett-Packard Development Company, L.P.

Part 2: Code and Debug a Script

1. Open the EXCEPTIONHANDLING script located in the C:\TRAINING\ADVANCED QTP92\TESTS folder. 2. From the QuickTest Professional menu bar, select FILE > SAVE AS to save the test as MYEXCEPTIONHANDLING. 3. Update the script with code to achieve the given objectives. 4. Run and debug the updated test.

Confirm in your test results that the PURCHASEFLIGHT action performed different checks depending on whether or not any cities were retired. If your test does not complete successfully, use the QuickTest Professional debug features to help identify the trouble areas in the script.