qtp basics

69
QuickTest Professional 9.2 Table of Contents 1 Introduction............................................................................................................................................. 3 2 Test Process Of QTP.............................................................................................................................. 4 1.1 First step is Planning....................................................................................................................... 4 1.2 Second step is Creating Tests or Components................................................................................ 4 1.3 Third step is Inserting checkpoints into your test or component.................................................... 4 1.4 Fourth step is Parameterize the Test................................................................................................4 1.5 Fifth step is Running the test........................................................................................................... 5 1.6 Sixth step is analyzing the results....................................................................................................5 2 Test object Model, test object and run-time object ................................................................................ 6 3 Recording Test........................................................................................................................................ 7 4 Running Test........................................................................................................................................... 9 5 Checkpoints........................................................................................................................................... 12 5.1 Standard Checkpoints.................................................................................................................... 14 5.2 Text checkpoints............................................................................................................................16 5.3 Image Checkpoint..........................................................................................................................17 5.4 Bitmap Checkpoint........................................................................................................................ 18 5.5 Table Checkpoint.......................................................................................................................... 20 5.6 Page Checkpoint............................................................................................................................ 21 5.7 Database Checkpoint..................................................................................................................... 23 5.8 Accessibility Checkpoint............................................................................................................... 25 6 Output Values....................................................................................................................................... 26 7 PARAMETERS.................................................................................................................................... 29 7.1 Data Table parameters .................................................................................................................. 30 7.2 Environment variable Parameters................................................................................................. 35 7.3 Random number Parameters......................................................................................................... 36 8 PARAMETERIZATION...................................................................................................................... 37 8.1 Test parameters .............................................................................................................................37 8.2 Action Parameter .......................................................................................................................... 38 8.3 Parameterize a Checkpoint ........................................................................................................... 39 9 Actions.................................................................................................................................................. 40 9.1 Creating a new action................................................................................................................... 41 9.2 Inserting an existing action...........................................................................................................41 9.3 Nesting Actions............................................................................................................................ 42 9.4 Splitting Actions........................................................................................................................... 42 9.5 Exiting an Action..........................................................................................................................43 1

Upload: jaxtr455

Post on 07-Apr-2015

452 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: QTP Basics

QuickTest Professional 9.2

Table of Contents1 Introduction.............................................................................................................................................32 Test Process Of QTP..............................................................................................................................4

1.1 First step is Planning....................................................................................................................... 41.2 Second step is Creating Tests or Components................................................................................ 41.3 Third step is Inserting checkpoints into your test or component.................................................... 41.4 Fourth step is Parameterize the Test................................................................................................41.5 Fifth step is Running the test...........................................................................................................51.6 Sixth step is analyzing the results....................................................................................................5

2 Test object Model, test object and run-time object ................................................................................63 Recording Test........................................................................................................................................ 74 Running Test........................................................................................................................................... 95 Checkpoints...........................................................................................................................................12

5.1 Standard Checkpoints....................................................................................................................145.2 Text checkpoints............................................................................................................................165.3 Image Checkpoint..........................................................................................................................175.4 Bitmap Checkpoint........................................................................................................................185.5 Table Checkpoint.......................................................................................................................... 205.6 Page Checkpoint............................................................................................................................215.7 Database Checkpoint.....................................................................................................................235.8 Accessibility Checkpoint...............................................................................................................25

6 Output Values....................................................................................................................................... 267 PARAMETERS.................................................................................................................................... 29

7.1 Data Table parameters ..................................................................................................................307.2 Environment variable Parameters................................................................................................. 357.3 Random number Parameters......................................................................................................... 36

8 PARAMETERIZATION...................................................................................................................... 378.1 Test parameters .............................................................................................................................378.2 Action Parameter ..........................................................................................................................388.3 Parameterize a Checkpoint ...........................................................................................................39

9 Actions.................................................................................................................................................. 409.1 Creating a new action................................................................................................................... 419.2 Inserting an existing action...........................................................................................................419.3 Nesting Actions............................................................................................................................ 429.4 Splitting Actions...........................................................................................................................429.5 Exiting an Action..........................................................................................................................43

1

Page 2: QTP Basics

QuickTest Professional 9.2

9.6 Reusable Actions .........................................................................................................................4410 Object Management............................................................................................................................ 45

10.1 Object Identification....................................................................................................................4510.2 Object Spy.................................................................................................................................. 4610.3 Object Repository.......................................................................................................................47

11 Descriptive Programming................................................................................................................... 5311.1 Static Descriptive Programming................................................................................................ 5411.2 Dynamic Descriptive Programming...........................................................................................5611.3 Retrieving child objects in Descriptive Programming............................................................... 5711.4 Creating checkpoints.................................................................................................................. 5811.5 Using Index Property..................................................................................................................59

12 Best Practices...................................................................................................................................... 6013 Function Libraries............................................................................................................................... 63

2

Page 3: QTP Basics

QuickTest Professional 9.2

1 IntroductionQTP (QuickTest Professional) is Mercury's advanced keyword-driven testing solution. QTP provides for functional test and regression test automation.

With QTP (QuickTest Professional) you will be able to test

1. Standard Windows applications

2. Web objects,

3. ActiveX controls, and

4. .Net

5. Java

6. SAP (Systeme, Anwendungen und Produkte in der Datenverarbeitung, Systems, Applications and Products in Data Processing)

7. Visual Basic applications.

8. Siebel

9. Oracle

10. PeopleSoft and

11. Terminal emulators ( http://www.emtec.com/zoc/terminal-emulator.html)

We need additional QuickTest add-ins for special environments e.g. .Net, Terminal emulators.

The current version of QTP (version 9.x) supports running tests on the following browsers:

● Microsoft Internet Explorer 6.0 Service Pack 1 or 7.0 Beta 2 and lower,

● Netscape Browser 8.0

● Mozilla FireFox 1.5.

QuickTest Professional 9.2 is compatible with: SAP 8.2, .NET 9.2, Web Services 9.2, Java 9.1, Oracle 8.2, PeopleSoft 8.2, Siebel 8.0, Stingray 8.2, Terminal Emulator 8.0, and VisualAge Smalltalk 8.2.

QTP (QuickTest Professional) is Unicode compliant according to the requirements of the Unicode standard, enabling you to test applications in many international languages.

As and when an application under test changes, such as when a "Log in" button is renamed "Sign Into," we can make one update to an XML-based Shared Object Repository (within the new Object Repository Manager), and the update will circulate (propagate) to all tests that reference this object. QuickTest Professional keeps object-level changes synchronized among users throughout test creation efforts.

Moreover, now users can invoke and run Mercury WinRunner™ scripts and functions from Mercury QuickTest Professional, and then automatically report WinRunner results back into the original scripts.

3

Page 4: QTP Basics

QuickTest Professional 9.2

2 Test Process Of QTPQTP (QuickTest Professional) lets you create tests and business components by recording operations as you perform them in your application.Test - A compilation of steps organized into one or more actions, which we can use to verify that our application performs as expected. A test is composed of actions (3 kinds of actions are there in QTP Non-reusable action, Reusable action and External action).

1.1 First step is Planning

Before starting to build a test, you should plan it and prepare the required infrastructure.For example, determine the functionality you want to test, short tests that check specific functions of the application or complete site.

Decide how you want to organize your object repositories.

1.2 Second step is Creating Tests or ComponentsWe can create a test or component by

1. Either recording a session on your application or Web site.

As we navigate through the application or site, QuickTest graphically displays each step we perform as a row in the Keyword View. The Documentation column of the Keyword View also displays a description of each step in easy-to-understand sentences. A step is something that causes or makes a change in your site or application, such as clicking a link or image, or submitting a data form.

2. Build an object repository and use these objects to add steps manually in the Keyword View or Expert View. We can then modify your test or component with special testing options and/or with programming statements.

1.3 Third step is Inserting checkpoints into your test or component.A checkpoint is a verification point that compares a recent value for a specified property with the expected value for that property. This enables you to identify whether the Web site or application is functioning correctly.

1.4 Fourth step is Parameterize the TestBroaden the scope of your test or component by replacing fixed values with parameters.To check how your application performs the same operations with different data you can parameterize your test or component.When you parameterize your test or component, QuickTest substitutes the fixed values in your test or component with parametersEach run session that uses a different set of parameterized data is called an iteration.We can also use output values to extract data from our test or component. An output value is a

4

Page 5: QTP Basics

QuickTest Professional 9.2

value retrieved during the run session and entered into the Data Table or saved as a variable or a parameter. We can subsequently use this output value as input data in your test or component.We can use many functional testing features of QuickTest to improve your test or component and/or add programming statements to achieve more complex testing goals.

1.5 Fifth step is Running the testAfter creating test or component, we run it.

Run test or component to check the site or application.

When we run the test or component, QuickTest connects to your Web site or application and performs each operation in a test or component, checking any text strings, objects, or tables you specified. If we parameterized the test with Data Table parameters, QuickTest repeats the test (or specific actions in your test) for each set of data values we defined.

Run the test or component to debug it.

We can control the run session to identify and eliminate defects in the test or component.

We can use the

● Step Into,

● Step Over,

● Step Outcommands to run a test or component step by step.

We can also set breakpoints to pause the test or component at pre-determined points.

We can view the value of variables in the test or component each time it stops at a breakpoint in the Debug Viewer.

1.6 Sixth step is analyzing the resultsAfter we run test or component, we can view the results.

● View the results in the Results window.

After running the test or component, we can view the results of the run in the Test Results window. We can view a summary of the results as well as a detailed report.

● Report defects identified during a run session.

If Quality Center is installed, we can report the defects fond out to a database. We can instruct QuickTest to automatically report each failed step in the test or component, or we can report them manually from the Test Results window.

5

Page 6: QTP Basics

QuickTest Professional 9.2

3 Test object Model, test object and run-time object Test object Model is a set of object types or Classes that QuickTest uses to represents the objects in our application.

A test object class comprises of a list of properties that can individually (uniquely) identify objects of that class and a set of appropriate methods that QuickTest can record for it.

A test object is an object that QuickTest creates in the test to correspond to (represent) the actual object in the application. QuickTest uses the stored information about the object during the run session to identify and check the object.

A run-time object is the real (actual) object in the application or Web site on which methods are performed during the run session.

Properties and methods of objects:The property set for each test object is created and maintained by QuickTest. The property set for each run-time object is created and maintained by the object architect (creator) (Microsoft for Internet Explorer objects, Netscape for Netscape objects).

Similarly, methods of test objects are methods that QuickTest recognizes and records when they are executed (performed) on an object while we are recording, and that QuickTest executes when the test or component runs. Methods of Run-time object are the methods of the object in the application as defined by the object architect (creator). We can access and execute run-time object methods using the Object property.

Some important points to remember about methods and properties :● Each test object method we execute (perform) while recording is recorded as a separate step in

the test. When we run the test, QuickTest executes (performs) the recorded test object method on the run-time object.

● Properties of test object are captured from object while recording. QuickTest uses the values of these properties to identify runtime objects in the application during a run session.

● Property values of objects in the application may change .To make the test object property values match the property values of the run-time object, we can modify test object properties manually while designing the test or component or using SetTOProperty statements during a run session. We can also use regular expressions to identify property values.

● We can view or modify the test object property values that are stored with the test or component in the Object Properties or Object Repository dialog box.

● We can view the syntax of the test object methods as well as the run-time methods of any object on our desktop using the Methods tab of the Object Spy.

● We can retrieve or modify property values of the TEST OBJECT during the run session by adding GetTOProperty and SetTOProperty statements in the Keyword View or Expert View. We can retrieve property values of the RUNTIME OBJECT during the run session by adding GetROProperty statements.

If the available test object methods or properties for an object are not sufficient or they do not provide the functionality we need, we can access the internal methods and properties of any run-time object using the Object property.

6

Page 7: QTP Basics

QuickTest Professional 9.2

2 Recording TestQuickTest records the operations we perform, displays them as steps in the Keyword View, and generates scripts in the expert view. Each test in Quick test includes a single action. Multiple actions can be included when needed.

● Before recording a test see to that all other browsers are closed. Choose how to open the application. This can be done as follows:

Go to Test->Record & Run Settings->web.If the page is already open select the ‘Record and run on any open web browser’ option. If you want to open the page automatically select the ‘Open the following browser when record and run session begins’ option and set the Url of the page you want to record.

● Click the Record button or choose Test > Record.

● Navigate through the application or Web site. QuickTest records each step performed and displays it in the Keyword View and Expert View.

● When you complete your recording, click the Stop button or choose Test --> Stop.

● Click the Save button to save the test.

RECORDING MODESThere are 3 recording modes in QTP:

1. Normal Recording

2. Analog Recording

3. Low level Recording

Normal mode : This is the default and takes full advantage of the Quick Test test object model, as it recognizes the objects in the application regardless of their location on the screen.

Analog Recording : Exact mouse and keyboard operations are recorded in relation to either the screen or the application window. In this QTP also records and tracks every movement of the mouse for example, recording a signature produced by dragging the mouse. Analog Recording steps are not editable from within QuickTest.

Low Level Recording : At any time, if an environment or on an object not recognized by QuickTest, use Low Level Recording. It records at object level and records all run-time objects as Window or WinObject test objects. QuickTest records all parent level objects as Window test objects and all other objects as WinObject test objects.

Each step recorded in Low Level Recording mode is shown in the Keyword View and Expert View.

All the three modes of recording can be used in a single test e.g. we can switch to either Analog Recording or Low Level Recording in the middle of a recording session for specific steps and then return to normal recordingmode.

7

Page 8: QTP Basics

QuickTest Professional 9.2

Analog Recording and Low Level Recording require more disk space than normal recording mode.

Use Analog Recording when :

● The actual movement of the mouse is what you want to record.

● Recording in Analog mode can be relative to the screen or relative to a specific window (see user guide for detail)

In Analog Recording a separate file is saved and stored with the action.

In Analog Recording mode, QuickTest adds to your test a RunAnalog statement that calls the recorded analog file.

Use Low Level Recording when :

● Environments or objects not supported by QuickTest.

● Exact location of the operation on your application screen is necessary. in normal mode QuickTest performs the step on an object even if it has moved to a new location on the screen.

● If the location of the object is important to your test, switch to Low Level Recording

8

Page 9: QTP Basics

QuickTest Professional 9.2

3 Running TestWhen you run a test, QuickTest performs the steps you recorded on the application.

● The Run option can be used to run the test from start to end.

● The Run from Step option in the Test menu is used to run the test from a selected step to the end of the current action, if running from the Expert View, or to the end of the test , if running from the Keyword View. Thus it enables us to check a specific part of the application or to confirm that a certain part of the test runs correctly.

● The Update Run option in the Test menu is used to update the Acany necessary changes, and then continue running the test from the breakpoint.

● The DebugViewer option in the View menu is used to view, set, or modify the current value of objects or variables in the test,when a test stops at a breakpoint.

● After a test run, the results are displayed in the Test Results window.If the window is not already open choose Test->Results.The Test result tree can be collapsed and expanded. Iterations, actions, and steps that contain checkpoints are marked Passed or Failed in the bottom right part of the Test Results window and are identified by the icon or in the tree pane. tive screens, Checkpoints and the test object descriptions. While recording, Quick Test saves the snapshots of the application as Active screens which can be used later to set Checkpoints and output values.

● The Pause option in the Debug menu is used to temporarily suspend the run. To resume running a paused test, click the Run button.

● The StepInto(F11) option in the Debug menu is used to run the current line of the test.

● The Insert\Remove Breakpoint(F9) option in the Debug menu is used to stop a test run at a pre-determined place in a test. A breakpoint is indicated by a red-colored hand in the left margin of the test window. The test run is paused when it reaches the breakpoint, before executing the step. You can examine the effects of the test run up to the breakpoint, make

9

Page 10: QTP Basics

QuickTest Professional 9.2

To add details in the Test results window Reporter event is used.

The following line of code can be used.

Reporter.ReportEvent 0, Search, “Search Successful"The first argument (0 or 1) represents the Event status.0 and 1 represent pass and fail respectively. The second argument indicates the step name and the third gives details about the executed test.

10

Page 11: QTP Basics

QuickTest Professional 9.2

EXAMPLE

We will test with the mercury sample application. QTP script consists of things like actions, functions etc. In QTP 9 we can place 120 actions in a script, this is a limit. We will begin with a simple test like the "hello world" program with which we start learning any programming language.1. First of all click on Record toolbar button ( or Automation menu --> Record or press F3). when

we click on Record, "Record and Run Settings" window opens up. Go to "Windows Applications" tab and choose first option "Record and run test on any open windows based application." and click on ok.

2. Open Flight application (Start --> All programs --> QuickTest Professional --> Sample Applications --> Flight)

3. Type Agent name as "Kumar" (You can enter any, but must be 4 characters or more) and enter password as "mercury".

4. In the flight reservation window that opens up5. In the Flight Schedule area, in Date of Flight enter tomorrow's date in mm/dd/yyyy format.( I

used tabs to move to next fields)6. In Fly From enter Denver7. In Fly To enter London8. Click on Flights button which is on the right hand side of "Fly To". Let the default option be

selected in the Flights Table.9. Click ok10. In the name field enter your name. It will fill rest of the required information by itself.11. Click on insert order and after the order is inserted12. Click on File --> exit.13. Now you have recorded your first script. You can click on the expert view tab to see the script

which QTP has recorded for you automatically.14. Click on run from Automation Menu (or press F5) to open up run dialog box. 15. Go to the "Results Location" tab, and below "write run results to", in "new run results folder"

radio button- let it be the default option -- C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\Test1\Res1(you can also change it)

16. click on ok.This will run you earlier recorded test and show you the results. But we have to go a long way. This is just the beginning.

11

Page 12: QTP Basics

QuickTest Professional 9.2

4 CheckpointsA checkpoint enables you to identify whether the Web site or application under test is functioning correctly or not by comparing a current value for a particular property with the expected value for that property.

After we add a checkpoint, QuickTest adds a checkpoint to the current row in the Keyword View and adds a Check CheckPoint statement in the Expert View.

By default, the checkpoint name receives the name of the test object on which the checkpoint is being performed. We can change the name of the checkpoint if needed.

Checkpoints can be added during recording and/or during editing a test:● During Recording: In the Keyword View or Expert View, choose Insert ->Checkpoint

option to select a type of checkpoint and select the object for which the checkpoint is to be added.

● During Editing: Right click the object in the Active screen and select the type of checkpoint to be added.

12

Page 13: QTP Basics

QuickTest Professional 9.2

Types of Checkpoints:

1. Standard checkpoint

2. Text checkpoints

3. Image Checkpoint

4. Bitmap checkpoints

5. Table Checkpoint

6. Page Checkpoint

7. Database Checkpoint

8. Accessibility Checkpoint

9. XML checkpoints

After selecting the object, add the property that is to be checked. For example, for a standard checkpoint on a radio button for the property ‘selected’ checks whether the radio button is selected or not. Checkpoints can also be placed in the Keyword view. Right click the object in the keyword view and insert the required checkpoint.Checkpoints cannot be added manually, they are inserted using QTP's interface. Results of the checkpoint can be viewed in the Test Results Window.Checkpoint information is stored in the Local Object Repository. It is in the Resource.mtr file which is in the action folder (if you created checkpoint in action1 then it will be action 1 folder under the folder in which you are saving the test/script, if you created checkpoint in action 2 then it will be action 2 folder and so on) .

13

Page 14: QTP Basics

QuickTest Professional 9.2

4.1 Standard Checkpoints

Standard checkpoints allow checking the object property values in the Web site or application under test. Standard checkpoints evaluate (compare) the expected values of object properties captured during recording to the object's current values during a run session.

For example we can check that a radio button is activated after it is selected. Standard checkpoints are supported for all add-in environments.

Standard checkpoints can be used to perform checks on variety of objects such as buttons, radio buttons, combo boxes etc. Standard checkpoints are supported for all add-in environments

EXAMPLE:1. Open a blank test.

2. Make sure that Flight application is open.(Now only QTP with blank test and Flight application should be open).

3. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Windows Applications" tab and choose first option "Record and run test on any open Windows based application." and click ok.

4. Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).The mouse pointer will become hand and QTP will be minimized.

5. Click on the "Flights..." button which is on the Right Hand Side of the "Fly To" combo box in the Flight application.

6. It will open "Object Selection - Checkpoint Properties" window (with WinButton:FLIGHT highlighted). Click ok.

7. It will open checkpoint properties window. (only one property will be checked in it i.e. 'enabled' with a value of False.)

8. Click ok. Click on Stop in order to stop the Recording.

9. Save the test.

This is a small test in which we have used standard checkpoint and captured the disabled button on the Flight application. Now we can run the test in two ways to see how it fails and passes the results of the checkpoint.

To see a pass test result:1. Make sure that this test and Flight application is open.

10. Click on run.

11. It will Run the test and show you the result as pass.

14

Page 15: QTP Basics

QuickTest Professional 9.2

To see a Fail test result: 1. Make sure that this test and Flight application is open.

2. In the Flight application enter the Date of Flight, Fly From and Fly To fields and nothing else. (The reason for doing this is that it will enable the 'Flight...' button)

3. Click on run in order to run the test.

It will Run the test and show you the result as Fail. This is because QTP was looking for a disabled 'Flight...' button for which it recorded the information at the record time, but now since the button was enabled at run time, so it failed.

15

Page 16: QTP Basics

QuickTest Professional 9.2

4.2 Text checkpointsThis check point is used to checks whether the text string is displayed in the appropriate place in your application or on a Web page.

Lets understand it with an example:

1. Open a blank test and a web page in offline mode like this below:

2. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Web" tab and choose first option "Record and run test on any open browser." and click on ok.

3. Go to Insert (menu)->Checkpoint->Text Checkpoint.The mouse pointer will become hand and QTP will be minimized.Click on the first paragraph (which starts with-The page you are looking..) of that web page.

4. "Text Checkpoint Properties" window opens up. It will show the text to be checked in "Checkpoint Summary" area in red color and also show in blue color the text which is displayed before and after the selected text.

5. Click on Configure -here you can change your selected text, change before and after text and so on, but for now just click ok. At the bottom of the "Text Checkpoint Properties" window change 'Checkpoint timeout' to 0 seconds. Again Click ok to come out of "Text Checkpoint Properties" window.

6. Click on stop in order to stop recording.

Run the test and when it is passed just go to the results window and on the left hand side expand every option and click on last option Checkpoint "Cannot find server". On the right hand side it will show you the details.

16

Page 17: QTP Basics

QuickTest Professional 9.2

4.3 Image Checkpoint

Image checkpoints allow you to check the properties of an image in the application or Web page. For example, you can check that a selected image's source file is correct or not. An image checkpoint can also be created by inserting a standard checkpoint on an image object. Image checkpoints are supported for the Web add-in environment.

EXAMPLE:

1. Open a blank test. On your system under My Documents, there will be a folder named My Pictures, under this you will will find a folder- Sample Pictures( containing 4 pictures - Blue Hills, Sunset, Winter, Water lilies)

2. We will run this test with one of the image there- Sunset. Go to My Documents->My Pictures-> Sample Pictures and right click on image named 'Sunset' and open it with internet explorer.

Now only a new blank test and internet explorer with this image should be open.

3. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Web" tab and choose first option "Record and run test on any open browser." and click on Ok.

4. Go to Insert (menu)->Checkpoint->Standard Checkpoint(or press F12).The mouse pointer will become hand and QTP will be minimized.

5. Click on the image which is opened in the explorer. It will open 'Object Selection Checkpoint Properties' window with Image: Sunset highlighted. Click Ok.

6. It will Open 'Image Checkpoint Properties' Window. In this window just uncheck all the property values like href, html tag etc and only check last property which is src.

7. Rest every thing will be default. Click OK.

8. Click stop to stop recording the test.

In the expert view it will just add one line Browser("C:/Documents and S").Page("C:/Documents and S").Image("Sunset").Check CheckPoint("Sunset")

If you run it with that image open in Internet explorer it will pass. This test is not intelligent enough. It is just checking that the image in the explorer is in the same location in which it was when the test was recorded and its name is Sunset. If you change the name of some other picture in that folder to Sunset and run the test with that it will also pass.

In this way you can test for some or all the properties of the image which it showed in the 'Image Checkpoint Properties' Window.

17

Page 18: QTP Basics

QuickTest Professional 9.2

4.4 Bitmap Checkpoint

With Bitmap Checkpoint we can check an area of a Web page or application as a bitmap. While creating a test, we have to specify the area to check by selecting an object. An entire object or any area within an object can be checked. Bitmap checkpoints are supported for all add-in environment.

The bitmap checkpoint is different from the image checkpoint.

Make sure that QTP and the Flight application are open.

STYLE A1. Open a blank test.

2. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Windows Applications" tab and choose first option "Record and run test on any open windows based application." and click Ok.

3. Go to Insert (menu)->Checkpoint->Bitmap Checkpoint4. Click on the "Fly To" combo box.

5. "Object Selection- Bitmap Checkpoint Properties" window opens up. It will have "WinComboBox:Fly To" highlighted. Click ok

6. It will open "Bitmap Checkpoint Properties" window.

7. Change the "Checkpoint timeout" at the bottom of the window to 0 seconds, so that we will have no wait time while running the test.

8. Click ok.

9. Click stop to stop recording the test.

18

Page 19: QTP Basics

QuickTest Professional 9.2

STYLE B

1. Above, after 3rd point, instead of clicking on the "Fly To" combo box, click somewhere in the empty space above the "Fly From" Combo box but below the line, i.e. in the "Flight Schedule" area.

2. "Object Selection- Bitmap Checkpoint Properties" window opens up. It will have "WinObject:Flight Schedule" highlighted. Click ok

It will open "Bitmap Checkpoint Properties" winodow. This time it will have "Flight schedule" area instead of just the "Fly To" combo box.

3. Now click on the "Select Area..." button. Mouse pointer will change so that you can select any area by dragging. Just select "Fly From" combo box by dragging.

4. Change the "Checkpoint timeout" at the bottom of the window to 0 seconds. so that we will have no wait time while running the test.

5. Click ok.

6. Click stop to stop recording the test.

7. Run the test.

To see how it stores the results, just fail the test. If you have recorded in the style A then just select any value in the "Fly To" combo box and then run the test. In the result window on the left hand side when you click on Checkpoint "Fly To:", it will show you the expected bitmap and actual bitmap on the right hand side. (note: it will show that only in case of Failed result).

19

Page 20: QTP Basics

QuickTest Professional 9.2

4.5 Table Checkpoint

By adding table checkpoints to the test, we can check the content of tables displayed in the application.

For example, we can check that a specified value is displayed in a certain cell. Certain environments also support checking the properties of the table object. For example, a check that a table has the expected number of rows and columns. A table checkpoint can also be created by inserting a standard checkpoint on a table object.

EXAMPLE:

1. Open a blank test and also open a website "http://www.editorial.co.in/software/software-testing-life-cycle.php" in offline mode.

2. This website has a table at the bottom of the page.

3. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Web" tab and choose first option "Record and run test on any open browser." and click on ok.

4. Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).

5. The mouse pointer will become hand and QTP will be minimized.

6. Click somewhere inside the table.

7. "Object Selection - Checkpoint properties" window opens.

8. Select "WebTable: Software Testing Life Cycle" which has a table icon on its left, where "Software Testing Life Cycle" is the name of the table.

9. Click ok.

10. 'Table Checkpoint properties' window opens. It will show all the rows and columns of the selected table. This time we will not do any extra setting. Just change the Checkpoint timeout at the bottom of this window to 0 seconds and click ok.

11. Click stop in order to stop recording.

Run the test and analyze the results in the result window, mainly the checkpoint results to see how QTP verifies the result.

20

Page 21: QTP Basics

QuickTest Professional 9.2

4.6 Page Checkpoint

Page checkpoint is for web applications only. Common things to check with this are load time, broken links etc. A page checkpoint can also be created by inserting a standard checkpoint on page object. Page checkpoints are supported for the Web add-in environment

EXAMPLE:

1. Open a blank test.

2. Make sure thathttp://www.google.co.in/ is open.(Now only QTP with blank test and www.google.co.in should be open.)

3. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Web" tab and choose first option "Record and run test on any open browser." and click ok.

4. Go to Insert (menu)->Checkpoint->Standard Checkpoint (or press F12).

5. The mouse pointer will become hand and QTP will be minimized.

6. Click anywhere on the white space on the Google.co.in page.

7. It will Open "Object Selection - Checkpoint Properties" window. Click on 'Page : Google' option which has a page icon on left of it with right corner of the page slightly folded.

8. Click ok.

9. A 'Page Checkpoint Properties' window opens up. Let all the options be default. Click ok.

10. Click on Stop in order to stop the Recording.

In the Expert view it will add just one line: Browser("Google").Page("Google").Check CheckPoint("Google")

We will explore this line later on.I ran this test by opening www.google.co.in in offline mode (not on internet). It recorded the following properties:

Property Name Property Value

load time "0"

number of images "2"

number of links "20"

Here it shows the load time as 0 because I did not open Google at the time of running the test, it was already open.

21

Page 22: QTP Basics

QuickTest Professional 9.2

When you run it, in the results window, on left hand side, it will show (when every option is expanded):

Test Checkpoint-page Summary (where Checkpoint-page is the name with which test is saved)

Run-Time Data Table

Checkpoint-page Iteration 1 (Row 1)

Action1 Summary

Google (This will be the browser)

Google (This will be the Page)

Checkpoint "Google"

If you run this test on www.google.com it may fail.

22

Page 23: QTP Basics

QuickTest Professional 9.2

4.7 Database Checkpoint

The contents of a database accessed by your application can be checked by Database Checkpoint. Database checkpoints are supported for all add-in environments

Now we will try out Database checkpoint: using Oracle 9i

EXAMPLE:

1. First of all you have to connect oracle 9i to QTP 9.(before doing any recording)

2. For this go to Insert -> Checkpoint -> Database Checkpoint.

3. A Database Query Wizard opens.Select ' Specify SQL statement manually' from the Query definition area. Click Next.

4. Here click on 'Create' button which is on the right of "Connection String:" It will open 'Select Data Source' window. Click on 'Machine Data Source' Tab

5. Click on New Button.

6. 'Create New Data Source' window opens.

7. Select 'User Data Source' from Select a type of data source. Click Next.

8. It will show all the data source drives it could find.

9. Select Oracle (on my machine it was 'Oracle in OraHome9'). Click Next. Click Finish.

10. It will open 'Oracle ODBC Driver Configuration' window.

11. Enter 'Data Source name' ( I entered "oracle")

12. Enter 'description' (I entered "SQL")

13. Select 'TNS Service Name' ( I selected 'DB02', my oracle database name) from combo box. Enter userid (I used SCOTT).

14. Click 'Test Connection' Button.It will ask for a Password. Enter your password for Oracle.

15. If successful it will show 'Testing Connection' window with 'Connection Successful' written on it.

This completes our task of Connecting QTP with Oracle.

Now we will record a test.1. Open a blank test.

2. Click on Record. When we click on Record, "Record and Run Settings" window opens up. Go to "Windows Applications" tab and choose first option "Record and run test on any open Windows based application." and click on ok.

3. Go to Insert (menu)->Checkpoint->Database Checkpoint

23

Page 24: QTP Basics

QuickTest Professional 9.2

4. A 'Database Query Wizard' opens.

5. Select ' Specify SQL statement manually' from the Query definition area. Click Next. Click Create.

6. Go to 'Machine Data Source' Tab

7. Select Oracle from data source name. Click Ok. It will open 'Oracle ODBC Driver Connect'

8. Enter password. Click ok

9. It will come to Database Query Wizard window with 'Connection String' field filled with: "DSN=oracle;UID=SCOTT;PWD=TIGER;DBQ=DB02;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;"In the SQL Statement area type "select * from emp;". Click Finish.

10. It will open 'Database Checkpoint Properties' window with the result of the query. Click Ok.

11. Click Stop in order to stop the Recording.

12. In the Expert View, it just adds one line "DbTable("DbTable").Check CheckPoint "DbTable")"

This is the simplest database checkpoint example.

13. Lets run it. Click on Run. ( we don't need to open any other window or application to run this as our Oracle is running at the back end as a service - default way in which it was installed- nothing special.)

When it is passed it will show following in the Result window:

Test Checkpoint-database Summary (Checkpoint-database is the name with which a test is saved)

Run-Time Data Table

Checkpoint-database Iteration 1 (Row 1)

Action1 Summary

DbTable

Checkpoint "DbTable"

(when you click on this, in details it will show checked 112 cells (in your case number of cells may differ). It means if you go to the oracle and add or delete any row and run this test again it will fail.)

Just try to think how QTP is comparing the expected results with the actual one, with the count of cells.

24

Page 25: QTP Basics

QuickTest Professional 9.2

4.8 Accessibility Checkpoint

Accessibility Checkpoint recognizes areas of your Web site that may not conform to the World Wide Web Consortium (W3C) Web Content Accessibility Guidelines. For example, check if the images on a Web page include ALT properties, required by the W3C Web Content Accessibility Guidelines. Accessibility checkpoints are supported for the Web add-in environment.

25

Page 26: QTP Basics

QuickTest Professional 9.2

4.9 XML Checkpoint

By adding XML checkpoints to your test, you can check the contents of individual XML data files or documents that are part of your Web application. The XML Checkpoint option is supported for all add-in environments.

26

Page 27: QTP Basics

QuickTest Professional 9.2

4.10 Checkpoint Return Value

We will use the Standard Checkpoint which we did in section 6.1

Open that test that contains the standard Checkpoint. In the expert view of the test you will see only one line i.e.

Window("Flight Reservation").WinButton("FLIGHT").Check CheckPoint("FLIGHT")

Now we will make some changes in this one line so that it can return some value.

NOTE: Checkpoint always returns a value, it depends on us whether we capture it or not.

Lets now capture it.

.1 Declare a variable and catch the return value in that variable:

Dim return

return = Window("Flight Reservation").WinButton("FLIGHT").Check CheckPoint("FLIGHT")

msgbox (return)

.2 One thing more we need to do here is that we have to enclose Checkpoint ("FLIGHT") in brackets. So the final version looks like this:

Dim return

return = Window("Flight Reservation").WinButton("FLIGHT").Check (CheckPoint("FLIGHT"))

msgbox (return)

Now run the test and see the msgbox appearing with the return value.

27

Page 28: QTP Basics

QuickTest Professional 9.2

5 Output ValuesOutput Value is used to retrieve the current value of any object in the application and stores it in a specified location. Output values can be added in the following ways

● During Recording: In the Keyword View or Expert View, choose Insert -> Output Value and select the type of output value and the object for which the value is to be outputted.

● During Editing: Right click the object in the Active screen and select the type of output value to be added.If the location clicked is associated with more than one object, then the Object Selection - Output Value Properties dialog box opens. From here select the required object.

Types of Output valuesWe can create the following categories of output values: ● Standard Output Values: to output the property values of most objects like

editbox,button,radio button,list box,etc.

● Text Output Values: to output text strings displayed in the application. When creating a text output value, we can output a part of the object's text. The text before and after the output text can also specified.

● Text Area Output Values: to output text strings displayed within a defined area of the application. We can also output a part of the object’s test.

● Database Output Values: to output the contents of database cells, based on the results of a

28

Page 29: QTP Basics

QuickTest Professional 9.2

query on the database. We can create output values from the entire contents of the result set, or from a part of it.

● XML Output Values: to output the values of XML elements and attributes in XML documents.

EXAMPLE 1

1. Open a new test and also open a sample Flight application (Flight Reservation window)

2. Make sure that both (new test and Flight Reservation window) are open and visible.

3. Click on Record in order to record a test.

4. Go to Insert (Menu)->Output Value->Standard Output Value.

5. QTP will be minimized and mouse pointer will take the shape of a hand. Click on 'Insert Order' button in 'Flight Reservation window.'

6. "Object Selection - Output Value Properties" window opens with WinButton :Insert Order highlighted. Click Ok.

7. "Output Value Properties" window opens with 'Insert Order' in the Name text field.

8. Click on first checkbox (which is Property enabled and Value False).

9. In the 'Configure Value' area click on Modify button.

10. 'Output Options' window opens. In this window just click Ok. (It creates Insert_Order_enabled_Out column in Global datasheet in Data Table with a Value False in the first row)

11. It will bring you back to "Output Value Properties" window. Now earlier where under Value it was showing False (see step 8) now it will show Insert_Order_enabled_Out.

12. Again Click Ok to come out of this "Output Value Properties" window.

13. Click Stop in order to stop the test.

14. Now it means whatever the value of Insert Order button's Enable Property will be, QTP will show that value in Data Table (under Insert_Order_enabled_Out column) at Run time.

Just make that Insert Order button enable by putting some values in Flight Reservation window and then see that column (Insert_Order_enabled_Out ) in Data table. It will show a true value in there at run time. It will also show that captured value in the Results window.

29

Page 30: QTP Basics

QuickTest Professional 9.2

EXAMPLE 2

These above steps show you how to use output values with Data Table. Below tutorial shows how to use output values with Environment variables.

1. Open a new test and also open a sample Flight application (Flight Reservation window)

2. Make sure that both (new test and Flight Reservation window) are open and visible.

3. Click on Record in order to record a test.

4. Go to Insert (Menu)->Output Value->Standard Output Value.

5. QTP will be minimized and mouse pointer will take the shape of a hand. Click on 'Insert Order' button in Flight Reservation window.

6. "Object Selection - Output Value Properties" window opens with WinButton : Insert Order highlighted. Click Ok.

7. "Output Value Properties" window opens with 'Insert Order' in the Name text field.

8. Click on first checkbox (which is Property enabled and Value False).

9. In the Configure Value area click on Modify button.

10. Output Options window opens.

11. In 'Output Options' window, from 'Output Types' dropdown, select Environment, and click Ok.

12. Now Insert_Order_enabled_out will be User-Defined internal environment variable.

13. Click Ok to come out of this "Output Value Properties" window. (You can check that environment variable by going to File->Settings, Environment Tab and choosing User-Defined from variable type)

14. Just add the below line in the Expert View at the end to see the value of the environment variable.

msgbox(environment("Insert_Order_enabled_out"))

15. Now you can Run the test. Just make that Insert Order button enable by putting some values in Flight Reservation window and then see that environment variable value (Insert_Order_enabled_Out ). It will show a true value in there at run time. It will also show that captured value in the Results window.

30

Page 31: QTP Basics

QuickTest Professional 9.2

6 PARAMETERSBy replacing fixed values with parameters QuickTest enables you to enlarge the scope of a basic test. It is known as parameterization, greatly increases the power and flexibility of a test. A parameter is a variable that is assigned a value from an external data source or generator. Values in steps and checkpoints and also the values of action parameters can be parameterize.

Parameters let us check how the application performs the same operations with multiple sets of data.Parameterization can be done in three ways using Quick Test.

● Datatable

● Environment variables

● Random numbers

A property of an object can be parameterised from the object repository. Select the property to be parameterised and check the Parameter option from the configure value frame.

31

Page 32: QTP Basics

QuickTest Professional 9.2

6.1 Data Table parameters Date table parameters allow us to create a data-driven test (or action) that runs several times using the data that we supply. In each repetition, or iteration, QuickTest uses a different value from the Data Table.

The test runs once for each line of data in the DataTable. Each iteration takes a different value from the datatable. To run selected rows in the datatable choose the Run tab from Test->Settings and specify an option in the Datatable iterations frame.

We can provide parameters using Global and/or Action Data Tables.

Example 1

How, for each row, in global data sheet, QTP iterates all rows of any action data sheet.

1. Open a new Test.

2. Click on Record.

3. Go to Start->All Programs->QuickTest Professional->Sample Applications->Flight.

4. Enter the Agent Name as 'mary' and Password as 'mercury'. Click Ok (make sure we click ok with mouse and not hit the return (enter) Key.)

5. When the Flight Reservation window is open, go to File->Exit.

6. Click Stop in order to stop recording the test.

7. In the Keyword View under 'Value' column, make a single click on 'mary' (Agent Name), a button like <#> will appear, click on this button to open 'Value Configuration Options'

32

Page 33: QTP Basics

QuickTest Professional 9.2

window.

8. Click on Parameter radio button and select Data Table from the dropdown and let rest everything be default. click ok to come out of that window.

9. In the Global Data sheet it will add a new columns with 'mary' as its first value.

10. Go to Insert (menu) -> Call to New Action to insert action2.

11. For this action2, repeat steps from 2 to 7. (This time I have used the Agent Name as 'bill')

12. After repeating step 7, when you click on 'Parameter' radio button and select Data Table from the dropdown, make sure you select Current action sheet (local) in the Location in Data Table area. Click Ok to close that window.

13. It will add a new column in action2 Data Sheet with 'bill ' (because I used bill as an Agent Name ) as its first row.

14. Now you have two actions (action1 and action2), both of them do the same job but their data is in different sheets.

15. Go to Global Data Sheet and Add one more row in it below 'mary'. I added 'rama'.

16. In the Local Data Sheet (action2) add two more rows to make them a total of 3. I added 'amar' and 'Sumit'.

17. Right click on action1 and select action call properties, go to Run Tab and select "Run on all rows" radio button. Do the same for action2.

18. Go to Expert View of action one and type : msgbox("acton1"). Now my action1 looks like this:SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4a.exe","","C:\Program Files\MercuryInteractive\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set DataTable("p_Text", dtGlobalSheet)

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

Dialog("Login").WinEdit("Password:").SetSecure "4725bcebeea3b6682d186bf7b15ae92cc4e6c0ba"

msgbox("acton1")

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

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

19. Do the same for action2 and type msgbox("acton2") in its Expert view, as we did for action1.

20. Now Run the test.msgbox step has been added in both the action just to make you understand how the QTP is picking up the rows from Data Sheets.

33

Page 34: QTP Basics

QuickTest Professional 9.2

Example 2

This examples shows that each action can access data not only from Global Data Sheet or its own Local Data Sheet but also from other action's Data Sheet in the same test.

1. Open a new test.

2. Insert two actions.

In the Global Data table, in cell(A,1) type 'Global Data'.In the Action1 Data table, in cell(A,1) type 'Action1 Data'.In the Action2 Data table, in cell(A,1) type 'Action2 Data'.

3. In Expert View of action1 type:

msgbox("I am in action 1")

rc = DataTable.Value("A", dtGlobalSheet) 'accessing data from Global data sheet from action1

msgbox rc

rc = DataTable.Value("A", 2) 'accessing data from action1 data sheet from action1

msgbox rc

4. In expert view of action2 type:

msgbox("I am in action 2")

rc = DataTable.Value("A", dtGlobalSheet) 'accessing data from Global data sheetfrom action1

msgbox rc

rc = DataTable.Value("A", 2) 'accessing data from action1 data sheet from action2

msgbox rc

34

Page 35: QTP Basics

QuickTest Professional 9.2

We can also import Data Table from Database.

It is very simple to import data from database into Data Table.

1. Right-click somewhere inside the data table.

2. Go to Sheet->Import->From Database..."Database Query Wizard" opens.

3. Click on the radio button "Specify SQL statement manually".(make sure that "Maximum number of rows" checkbox is NOT checked)

4. Click Next.

5. Click Create button.

6. "Select Data Source" window opens

7. Click "Machine Data Source" Tab

8. Select Oracle from there and click ok.

9. Enter password for oracle in the "Oracle ODBC Driver Connect window"

10. After entering password when you click on ok, it open "Database Query Wizard" window with 'Connection string' automatically filled with info like DSN, UID etc.

11. Enter SQL statement "select * from emp;" in SQL statement Box.

12. Click Finish and all the data is there in the data table.

35

Page 36: QTP Basics

QuickTest Professional 9.2

6.2Environment variable ParametersUser-Defined Internal, User-Defined External, Built-in are the types of environment variables available in QTP.

Built-in variables as the name suggests are predefined by QTP. Examples of such variables are OS, OSVersion, ActionName which are for Operating System, Operating System Version and name of the action which is currently running, respectively.

Lets look at an example of this:

1. Open a new Test.

2. Go to File (Menu)->Settings, a Test Settings window opens.

3. Go to Environment Tab. By default Built-in variable type is selected and you will be able to see Name and Description of Built-in variables below Variable type dropdown box.

4. You can click on any of those variables to see their current value.

5. I just did the above four steps in order to show you from where you can access Built-in variables.

6. Now close this Test Settings window and go to test.

7. In the Expert View type:

a = environment("ActionName") & " is running on " & environment("OS")msgbox (a)

8. Run the test.It is just a simple way to show how a Built-in environment variable works.

User Defined Internal variables are the variables defined by you (the user) within the test and which are saved within the test and also accessible from within the test.

Lets look at an example of this:

1. Open a new Test.

2. Go to File (Menu)->Settings, a Test Settings window opens.

3. Go to Environment Tab. From Variable type dropdown select User-defined.

4. Click on the '+' which is on the right of Variable type dropdown.

5. 'Add New Environment Parameter' window opens up, type the name and value of the variable e.g. in Name type 'a' and in Value type 'hello' (without quotes, I have added quotes just for clarity) and click on OK. It will add the variable with its type as 'internal'.

6. Click Apply and OK to come out of Test Settings window.

7. Go to expert view and type:msgbox(environment("a"))

36

Page 37: QTP Basics

QuickTest Professional 9.2

8. Now Run the test. It will show you the value of variable 'a' in the message box.

User-Defined external variables are the variables which are defined in the file outside of test. These act as read only for the test. You can create as many files for environment variables as you want and choose them for your test.

Now lets look at an example of this:

1. Open a new text file and type the following lines in it and save it with .xml extension. ( I saved it in 'tests' folder in the 'QuickTest Professional' folder under C:\Program files.)

2. Open a new Test.

3. Go to File (Menu)->Settings, a Test Settings window opens.

4. Go to Environment Tab. From Variable type dropdown select User-defined.

5. Click on "Load variables and values from external file" check box and import that external xml file that we created above. As soon as it is imported the complete path of that file will be shown in the File text box and the variable in it will show under Name, Value and Type heading (in our case it will show Address under Name, 25 yellow Road under Value and External under Type).

6. Click on Apply and Ok to come out of it.

7. Go to expert view and type:msgbox(environment("Address"))

8. Now run the test. It will show you the value of variable 'Address' in the message box.

6.3 Random number Parameters

When you define parameters for an action you can set the parameter's value as Random numbers. There are many different ways in which you can use Random numbers in QTP.

EXAMPLE:

For i=1 to 5var1=RandomNumber (0, 100)msgbox(var1)Next

37

Page 38: QTP Basics

QuickTest Professional 9.2

7 PARAMETERIZATION

7.1 Test parameters You use the Parameters tab of the Test Settings dialog box (File > Settings) to define input parameters that pass values into your test and output parameters that pass values from your test to external sources. You can also use the Parameters tab to modify or delete existing test parameters.

EXAMPLE

1. Open a New Test.

2. Go to File->Settings, a 'Test Settings' window will open, go to 'Parameters' Tab.

3. Click on '+' sign which is on the top right.

4. Enter the Name of the parameter as 'vartest' and its Default Value as 'hello'. Click Apply and then Ok. The Type of this parameter is string.

Above we have created a Test Parameter.

5. Now in the Keyword View right click on Action1 and select 'Action Properties'. 'Action Properties' window opens.

6. Go to 'Parameters' Tab. Click on '+' sign which is on the top right.

7. Enter the Name of the parameter as 'varaction' and its Type as string and no default value. Click Ok to come out of that window.

8. Again in the Keyword View right click on Action1 and select 'Action Call Properties'. 'Action Call Properties' window opens.

9. Go to 'Parameter Values' Tab. There you will see the 'varaction' action parameter we created earlier. Make a single click under 'Value' heading, it will show a button like this <#>. Just click on this button to open 'Value Configuration Options' window.

10. Click on 'Parameter' radio button and select 'Test/action Parameter' from that dropdown.

11. 'Test Parameters' radio button will be selected by default and under 'Test Parameters' radio button select 'vartest' from Parameter dropdown.[ remember this vartest is a test parameter we created at the beginning]

12. When you click on ok to come out of 'Value Configuration Options' window, in the 'Action Call Properties' window, under 'Value' it will show <vartest>. Click Ok.

13. Go to Expert View and type:msgbox(parameter("varaction"))

14. Now run the test. While running it will show 'hello' in the msgbox.

This example show how to declare test parameters and how to access those.

Remember (from QTP guide):

38

Page 39: QTP Basics

QuickTest Professional 9.2

You can directly access test parameters only when parameterizing the value of a top-level action input parameter or when specifying the storage location for a top-level output parameter. To use values supplied for test parameters in steps within an action, you must pass the test parameter to the action containing the step. For more information, see Setting Action Parameters.

Alternatively, you can enter the parameter name in the Expert View using the Parameter utility object, in the format: Parameter "ParameterName").

7.2 Action Parameter You can specify input parameters for an action so that steps in the action can use values supplied from elsewhere in the test. Input values for an action parameter can be retrieved from the test (for a top-level action) or from the parameters of the parent action that calls it (for a nested action), or from the output of a previous action call (for a sibling action).

EXAMPLE1. In the Keyword View right click on Action1 and select 'Action Properties'. 'Action Properties'

window opens.

2. Go to 'Parameters' Tab. Click on '+' sign which is on the top right.

3. Enter the Name of the parameter as 'a' and its Type as Number. In the same way create another Number parameter 'b'.

4. Click Ok.

5. In the Keyword View right click on Action1 and select 'Action Properties'. 'Action Properties' window opens. In the general tab, click on 'Reusable Action' checkbox at the bottom to make the action reusable.

6. In the Expert View of Action1 type:

s1=parameter("a")s2=parameter("b")msgbox(s1+s2)

7. Go to Insert (menu)-> Call to New Action. 'Insert Call to New Action' window opens. Just click ok to insert a new action.

8. Make action2 reusable as we did for action1.

9. In the Expert View of action2 type:

RunAction "Action1", oneIteration, 2,210. In the keyword View right click on action2 and select 'Run from Step', it will show you the

sum 4 in msgbox.

39

Page 40: QTP Basics

QuickTest Professional 9.2

7.3 Parameterize a Checkpoint

You can create a Checkpoint while recording or editing a test. For this tutorial I will take into account Text Checkpoint created through Standard Checkpoint while editing.

EXAMPLE:

1. Open a new test.

2. Click on Record.

3. Go to Start-> All Programs->QuickTest Professional->Sample Applications->Flight.

4. Enter the Agent Name as "Sachin" and Password as "mercury". Make sure you use Tab key to move from one text box to another and hit Return (Enter) key after entering the Password.

5. When the Flight Reservation window is open Go to File (menu)->Exit.

6. Click on Stop in order to stop the recording.

7. In the Keyword view go to the row which has "Sachin" under Value column. Right-click anywhere on that row and choose "Insert Standard Checkpoint."

8. "Checkpoint Properties" window opens. Make sure only the Text property is checked which has a value of "Sachin" and rest all of the properties must be unchecked.

9. Just make a single click on Text Property, which you checked above, in order to highlight it and make "Configure Value" area enabled.

10. In this area click on Parameter Radio button. This is all we need to do.

[On the right hand side of Parameter Radio button you will see Parameter Options button (which has paper and pen image on it). you can click on it to see the default values QTP has set for us.]

11. In the "Checkpoint Properties" window just click on Ok to come out of it.

12. It will add a column in the Global Data Sheet with "Sachin" as its first value.

13. Add two more values in the subsequent rows. I added "aaaa" in the 2nd and "bbbb" in the 3rd.

Now when we run the test and it opens the window where we need to enter the Agent Name and Password, you have to enter Agent Name all of the 3 times (Just enter the Agent Name, that's it, no Tab key or Return key). Make sure you enter "Sachin" during first time, "aaaa" during second time and so on. We don't need to enter the Password. Remember this is a Text Checkpoint on the "Agent Name" Text field. Any value entered there first time will be compared by first row of the Global Data Sheet which has "Sachin" and any value entered there Second time will be compared by second row of the Global Data Sheet which has "aaaa" and so on. Just try to enter some other value during second time like "xxxx" it will run the test but show you "Failed" in the Results window in the second iteration.

40

Page 41: QTP Basics

QuickTest Professional 9.2

8 ActionsA test is composed of actions or logical sections. The steps we add to the test are added within the test’s actions. By default, each test begins with a single action. Dividing a test into actions helps us to streamline the testing process. When we run a test with multiple actions, the Test Results are divided by actions so that we can view the detailed results for each action individually. Each action has its own sheet in the Data Table so that we can insert data that applies only to that action.

Actions can be of three types:● Non-re-usable: Action can be used in the local test, only once.● Reusable: Action can be used in the local test, multiple times.● External: These are reusable actions created in another test. This can be of two types. If a call

to an external action is used the action is read only in the calling test. But, any existing action can be inserted as a copy of the original action. In this case, we can modify this copy of the external action in the calling test.

Actions on Quick Test Window (Keyword View)Actions Tool Bar contains buttons and a list of actions, enabling us to view the details of an individual action or the entire test flow. The test flow displays the overall flow of the test with all the actions in the test.

There are two buttons on the Actions Tool Bar, i.e. BACK and SHOW, as shown below.The Action Tool Bar will be visible, only when, we have one or more external/reusable actions in our test. If it is invisible, use View -> Tool Bars -> Action to display it.

41

Actions Tool Bar

Page 42: QTP Basics

QuickTest Professional 9.2

8.1 Creating a new action

1. Click the step after which you want to insert the new action.

2. Choose Insert > New Action or click the New Action

3. button. The Insert New Action dialog box opens.

4. Type a new action name or accept the default name.

5. Add a description of the action.

6. Select Reusable Action to make it reusable. This can be modified at a later time in the Action properties dialog box.

7. To insert a new action at the end of the test, check the At the end of the test checkbox. To insert the new action within the action of the currently selected step, select After the current step.

8. Click OK.

8.2 Inserting an existing actionWe can insert an existing action by inserting a copy of the action, or by inserting a call to the original action.● Inserting calls to an action makes it easier to maintain tests, because when an object or

procedure in the application changes, it needs to be updated only once, in the original action.● When we insert a copy of an action into a test, the action is copied in its entirety, including

checkpoints, parameterization, and the corresponding action tab in the Data Table. The action is inserted into the test as an independent, non-reusable action (even if the original action was reusable). Once the action is copied into the test, we can add to, delete from, or modify the action. Any changes we make to this action after inserting it affect only this action, and changes to the original action do not affect the inserted action. We can insert copies of both reusable and non-reusable actions.

Select an existing action, and choose:

Insert -> Call to Copy of an action / Call to Existing Action as required Use the Browse button to choose the actionSelect the locationClick OK.

42

Page 43: QTP Basics

QuickTest Professional 9.2

8.3 Nesting ActionsRunning an Action within an action is nesting. The following are the uses of nesting actions.

● Helps maintaining the modularity of the test● Help running one action or another based on the results of a conditional statement● To insert a nested action, follow the same procedure for inserting a new Action, with,

select after the current step as 6th step.

8.4 Splitting ActionsTo split an existing action:1. Select the step with which the new action should begin.

2. Choose Step -> Split Action. The following window appears:

● If we select ‘Independent of each other’ option: it creates 2 independent actions, with second action beginning with the selected step.

● If we select ‘Nested’ option: It creates two actions, with first one calling the second. (A Parent-Child relationship).

3. We can also change the Names and Descriptions of these actions.

43

Page 44: QTP Basics

QuickTest Professional 9.2

8.5 Exiting an ActionThere are three types of Exit Action statements:● ExitAction - Exits the current action, regardless of its iteration attributes.● ExitActionIteration - Exits the current iteration of the action.● ExitRun - Exits the test, regardless of its iteration attributes.● ExitGlobalIteration - Exits the current global iteration.

44

Page 45: QTP Basics

QuickTest Professional 9.2

8.6 Reusable Actions

In this section we will see how to use more than one action in a test and how to call one action from another with in the same test.

1. Open a blank test. By default it will have Action1 in it (make sure you are inthe keyboard view). Make sure that Action1 is selected/highlighted and click on the Expert View tab.

2. In the Expert View type:msgbox ("my action 1")

3. Again when you go to keyword View and expand Action1 it will show you function call under it.

4. In that keyword View itself go to Insert (Menu) ->Call to New Action. 'Insert Call to New Action' Dialog box opens with Action2 as a default name of a new action. By default it will be added at the end of the test as this radio button is selected in the location area.

5. Click ok. It will add Action2 to your test.

6. Make sure that Action2 is selected and click on the Expert View tab.

7. In the Expert View type:msgbox ("my action 2")

8. Similarly insert a third Action.

9. After third action is added, select Action1(keyword view), right click on it and choose 'Action Properties'.

10. In the Action properties window that opens, check the 'Reusable action' checkbox at the bottom.

11. Click ok.

12. Now again highlight Action3 right click on it and choose 'Insert Call to Existing action'.

13. 'Select action' dialog box appears. In this dialog box in the 'action' dropdown box it will have Action1 by default since we made only that action as reusable.Just click ok.

14. In the keyword View where you can see all the three actions, make sure against Action3 it shows "Call to Action1 action" under Documentation.

15. Run the test. Three message boxes appear in succession showing 'my action 1', 'my action 2', and again 'my action 1'.

45

Page 46: QTP Basics

QuickTest Professional 9.2

9 Object ManagementQuick Test identifies objects of two types

1. Test Objects: Objects in the test that represent objects in the application or website that are created and maintained by QTP.

2. Run Time Objects: Objects in the application that are created and maintained by the Browser.

Three object management tools are available to maintain both the test and runtime objects in the test.

9.1 Object IdentificationIt is used to set the properties used to identify an object. Each object has mandatory and assistive properties which are used to identify them. For example, from the figure below, the mandatory properties used to identify an ActiveX button object are caption and progid. Thus an ActiveX button is always identified using these two properties. In case these properties are not enough for identifying the object Quick Test uses the assistive properties to do the same. We can modify these properties using the Add\Remove button. Smart Identification is used to identify the object if the learned properties are not sufficient.

46

Page 47: QTP Basics

QuickTest Professional 9.2

9.2 Object SpyIt can be used to view the properties and values of an object in any open application. Click the pointing hand to select the object in the application. The object’s properties (Test object properties and Run-Time object properties) and methods can be identified. The object’s hierarchy tree is also displayed. To perform other events such as mouse clicks or window focus hold the CTRL key.

47

Page 48: QTP Basics

QuickTest Professional 9.2

9.3 Object Repository

An object as we know is a graphic user element in an application e.g. a button or a list or an edit box and the special characteristics of an object within the QuickTest are called object properties. QTP stores the recorded object properties in Object Repository.The Object Repository displays all objects in the current action or the entire test. The Object Repository can be used to view or modify the properties of any object in the repository or to add new objects to the repository. An object in the application can be highlighted using the Highlight option. A temporary frame appears around the object causing it to flash. But the application must be open and the object should be visible in the page. The object spy can also be accessed from the Repository.

Object Repositories are of two types

● Local

● Shared

If objects are stored in a Local Object Repository then these are available to specific actions but not to all the actions. But if these objects are stored in one or more Shared Object Repositories then multiple actions or tests can use them.

By default QTP makes and uses Local Object Repository. If we create a new blank test and do a recording on it, QTP automatically creates a Local Object Repository for that test or action and stores the information about any object it finds in that corresponding Object Repository.

48

Page 49: QTP Basics

QuickTest Professional 9.2

In QTP, we can associate multiple Shared Object Repositories with an action. If multiple Shared Object Repositories are associated with an action then also while recording QTP stores objects in corresponding Local Object Repository on the condition that those objects are not already stored in any corresponding associated Shared Object Repositories. This is the default that every time we create a new action QTP creates a new corresponding Local Object Repository. It is also true that Object Repositories are associated with actions and no matter how many times we learn or record on the same object in our application in different actions the object will be stored as separate test object in each of the Local Object Repository. Local Object Repository is automatically saved with the test when we save it. The extension of the Local Object Repository is .mtr, but it is not accessible as a separate file as in case of the Shared Object Repository.

We can also manipulate some aspects of Local Object Repository using Quick test Object Repository Automation Object Model.

For example we can add, remove, rename test objects in Local Object Repository. [QuickTest Object Repository Automation documents the Object Repository automation object model that enables you to manipulate QuickTest object repositories and their contents from outside of QuickTest.]

When we open a test that was created using a version of QTP earlier that version 9 we are asked whether we want to convert it or view it in read only format. In any case if the test previously used per-action Object Repository, the objects in each per action repository are moved to the Local Object Repository of each action in the test.

If the test previously used a shared object repository, the same shared object repository is associated with each of the actions in the test, and the local object repository is empty.

While learning or recording we can specify Shared Object Repository for the selected action. We can specify and associate one or more Shared Object Repositories with each action. We can also create new Shared Object Repository and associate it with our action.

In case of Shared Object Repository, QTP uses existing information and does not add objects to the Object Repository if we record operations on an object that already exists either in Shared or Local Object Repository.QTP does not add objects directly to the associated Shared Object Repository as we record, instead it adds new objects in Local Object Repository (if that object does not already exist in associated Shared Object Repository).We can surely export Local objects to Shared Object Repository.There are different ways in which we can move objects from Local Object Repository to Shared Object Repository:1. Exporting the objects to the Shared Object Repository from the Local Object Repository:

In Object Repository window choose the action whose local objects you want to move. Choose File-> Export Local Objects.Select the location in which you want to save the file. Click on save.

2. We can update the Shared Object Repository with the Local Object Repository:

49

Page 50: QTP Basics

QuickTest Professional 9.2

If we create a new test it will be created with Local Object Repository, we can associate any new or old Shared Object Repository with it, and so we can update that Shared Object Repository with Local Object Repository. ● In Object Repository Manager open the Shared Object Repository (clear open in read only

check box).

● The test, in this case, should not be open.

● In Object Repository Manager go to Tools –> Update From Local Repository.

● Select the test who's Local Object Repository you want to use.

● Click update all. It will move all the objects to the Shared Object Repository.

3. Merge Object Repositories

We can also merge objects from two Object Repositories (called as primary and secondary) into a new single Object Repository (target Object Repository). The original source files are not changed. It also enables you to merge objects from Local Object Repository of one or more action(s) into a Shared Object Repository. It is recommended to use as a primary Object Repository the file in which you have invested alot of your effort, like which has more number of objects

If we do not specify a file extension for Shared Object Repository when creating a new Shared Object Repository QTP automatically appends a default extension name for Shared Object Repository as .tsr. This means that we can create Shared Object Repository with any extension other than .tsr, it should work fine (I have tried that and it works fine), I think it may create problems while merging two Object Repositories (I haven't tried that yet).

We can compare two Object Repositories using the Object Repository Comparison Tool. The tool enables you to identify similarities, variations or changes between two Object Repositories.

We can also copy objects to Local Object Repository from the Shared Object Repository. We can copy, paste and move objects in Local Object Repository and copy, paste and move objects within Shared Object Repository and between Shared Object Repositories. As said earlier we can also copy objects from shared Object Repository to Local Object Repository to modify them locally.

We cannot remove an association between the action and its Local Object Repository.

Whenever we make any changes to an Object Repository those changes are automatically updated in all the associated tests open on the same computer as soon as we make the change even if the Object Repository is not yet saved and if we close the same Object Repository without saving the changes the changes are rolled back in any open tests. For the test that was not open when we changed Object Repository, when we open the test on the same machine on which we modified the Object Repository the test is automatically updated with all the saved changes. To see saved changes in a test or repository open on a different computer, you must open the test or object repository file or lock it for editing on your computer to load the changes.

50

Page 51: QTP Basics

QuickTest Professional 9.2

Important points about Object Repositories

These are the points to consider while planning and creating test that how you want to store objects; either you want to store them in Local Object Repository or Shared Object Repository.

1. For each action, we can also use a combination of objects from the Local and Shared Object Repositories, according to our needs. Local objects can also be transferred to a shared object repository, if necessary. This will cut maintenance and increase the re-usability of the tests because it will enable us to maintain the objects in a single, shared location instead of multiple locations.

2. If there is a same name object in both the Local Object Repository and in a Shared Object Repository associated with the same action, the action uses the local object definition i.e. the local object is given preference over the shared object. If an object with the same name is stored in more than one Shared Object Repository associated with the same action, the object definition is used from the first occurrence of the object, according to the order in which the Shared Object Repositories are associated with the action.

3. When we open an existing test, it always uses the object repositories that are specified in the Associated Repositories tab of the Action Properties dialog box or in the Associate Repositories dialog box. When we access Shared Object Repositories from tests they are read-only; we can edit them only using the Object Repository Manager.

4. As and when an application under test changes, such as when a "Log in" button is renamed "Sign Into," we can make one update to an XML-based Shared Object Repository (within the new Object Repository Manager), and the update will circulate (propagate) to all tests that reference this object. QuickTest Professional keeps object-level changes synchronized among users throughout test creation efforts.

51

Page 52: QTP Basics

QuickTest Professional 9.2

Object Repository dialog box

Object Repository dialog box window shows a tree of all the objects (either Local or Shared) on its left hand side in the selected action. On selecting any object in the tree Object Repository window shows the information about the object like the name, repository in which it is stored etc. On the left hand side in a tree local objects are editable while the shared ones are grayed out (non-editable).

To view the test object properties, to modify test object properties and to add objects to Local Object Repository we can use Object Repository window. We can also delete objects from Object Repository window; this is needed as when an object is removed form the test it is not automatically removed from the Local Object Repository.

Object Repository in QTP is XML based means that if we change something related to the object in Shared Object Repository, the change will be propagated to all the tests that reference this object, in real time.

52

Page 53: QTP Basics

QuickTest Professional 9.2

Adding Objects to Repositories

We can add objects to Shared Object Repository or Local Object Repository in a number of different ways-We can decide whether to add only a selected object, or to add all objects of a certain type, such as all button objects, or to add all objects of a specific class, such as all WebButton objects.We can modify objects stored in a Local Object Repository using the Object Repository Window and objects in a Shared Object Repository using the Object Repository Manager.It is possible to add objects to the object repository before they exist in an application.We can also add objects to the Local Object Repository while editing our test.We can add the object directly to a Shared Object Repository using the Object Repository Manager, so that it is available in all actions that use this Shared Object Repository.If needed, we can merge test objects from the Local Object Repository into a Shared Object Repository. We can also add objects to a Shared Object Repository while navigating through the application ("Adding Objects Using the Navigate and Learn Option").We can also add an object to the Local Object Repository by choosing it from the application in the Select Object for Step dialog box (from a new step in the Keyword View or from the Step Generator).We can add objects to the object repository using the Add Objects to Local or Add Objects option.We can add objects to the Local Object Repository of the current action by selecting the required object in the Active Screen.

53

Page 54: QTP Basics

QuickTest Professional 9.2

10 Descriptive ProgrammingWhenever you record on any object using QTP, QTP adds the test object to the Object Repository. While running a test, QTP finds the object in the Object Repository and uses the stored test object’s description to identify the object in your application/website. Only after the object is found in the Object Repository, QTP can perform methods on those objects.

We can also instruct QTP to perform methods on objects without referring to the Object Repository. This is possible with the help of Programmatic descriptions or descriptive programming.

This implies that descriptive programming is very helpful if you want to perform an operation on an object that is not stored in Object Repository.

Descriptive Programming is also useful to perform the same operation on several objects with certain matching properties e.g. suppose there are 8 check boxes on a web page with names as chk_1, chk_2 and so on. So it’s not a good idea to put these in an Object Repository. With the help of Descriptive Programming you can Set these check boxes ON or OFF according to your application needs.

If you are dynamically creating test objects during the run session then also Descriptive Programming goes a long way to help you. Suppose in a web site you have to generate a list of all the customer's email addresses, who brought iPhone from you, based on the geographical information you provided and then after the email addresses are provided as checkboxes you have to send a rebate letter to them. You don't know how many check boxes will be there based on the geographical information you provided. So in this case, you can use a Descriptive programming to instruct QTP to perform a Set "ON" method for all objects that fit the description: HTML TAG = input, TYPE = check box.

Descriptive programming can be done in two ways:

● Static: We provide the set of properties and values, that describe the object, directly.

● Dynamic: We have to add a collection of properties and values to a description object and then provide the statement with the description object's name.

Static is easier but Dynamic provides more power, efficiency, and flexibility.

We will see examples of both static and dynamic type of descriptive programming in QTP.

54

Page 55: QTP Basics

QuickTest Professional 9.2

10.1 Static Descriptive Programming

This below example uses Descriptive Programming to open Flight Application and does not use object repository at all. So one of the other advantages is you can copy this script and Run this from any other machine (other than on which it was created) and it is supposed to work fine.

For this time just read the script and move on, you will better understand it as you read more.

[Example 1b is recorded version (which uses Object Repository)of Example 1a - just for your comparison of the two so that you can better understand both]

Example 1a: uses Descriptive Programming

We can describe the object directly by specifying property: =value pairs.

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4b.exe"

window("Title:=Login").WinEdit("AttachedText:=Agent Name:").Set "sachin"

window("Title:=Login").WinEdit("AttachedText:=Password:").Set "mercury"

window("Title:=Login").winbutton("Text:=OK").Click

window("Title:=Flight Reservation").close

Examle 1b: uses Object Repository

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"

Dialog("Login").WinEdit("Agent Name:").Set "sachin"

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

Dialog("Login").WinEdit("Password:").SetSecure "476a9c021bc5a7422cf5a84ad08503823abcbaae"

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

Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

Note: When using descriptive programming from a specific point within a test object hierarchy, you must continue to use programmatic descriptions from that point onwards within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have been specified using programmatic descriptions, QTP cannot identify the object.

55

Page 56: QTP Basics

QuickTest Professional 9.2

For example, you can use the following statement since it uses programmatic descriptions throughout the entire test object hierarchy:

Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Sachin"

Above line uses Descriptive Programming for all objects like Browser, Page, WebEdit.

You can also use the statement below, since it uses programmatic descriptions from a certain point in the description (starting from the Page object description):

Browser("Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author", "Index:=3").Set "Sachin"

Above line uses Object Repository for Browser object and Descriptive Programming for Page and WebEdit.

However, you cannot use the following statement, since it uses programmatic descriptions for the Browser and Page objects but then attempts to use an object repository name for the WebEdit test object:

Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours"). WebEdit("Author").Set "Sachin"

QTP tries to locate the WebEdit object based on its name, but cannot locate it in the repository because the parent objects were specified using programmatic descriptions.

If same programmatic description is used several times,we can assign the object to a variable:In the above Example 1a script, window("Title:=Login") is being used several times, we do this:

Set var = window("Title:=Login")SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4b.exe"var.WinEdit("AttachedText:=Agent Name:").Set "sachin"var.WinEdit("AttachedText:=Password:").Set "mercury"var.winbutton("Text:=OK").Clickwindow("Title:=Flight Reservation").close

Or

We can use 'With & End With' Statement like below:

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4b.exe"With window("Title:=Login").WinEdit("AttachedText:=Agent Name:").Set "sachin".WinEdit("AttachedText:=Password:").Set "mercury".winbutton("Text:=OK").ClickEnd withwindow("Title:=Flight Reservation").close

56

Page 57: QTP Basics

QuickTest Professional 9.2

10.2 Dynamic Descriptive Programming

Understand it like this – A Property Object is a property name and value. We use Description object to return a Properties collection object containing a set of Property Objects. Then only in place of an object name, returned properties collection, can be specified in a statement.

For creating Properties collection "Description.Create" statement is used.

Set Myvar = Description.Create()

Once Property Object (Myvar) is created, statements to add, edit, remove and retrieve properties and values to or from properties objects can be entered during the run time.

Lets take a complete example of this: [Note: Extra values (height & width) are not important in our example. Our example can run without height and width properties. I have just added those in order to make you understand this]

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4b.exe"

window("Title:=Login").WinEdit("AttachedText:=Agent Name:","height:=20","width:=119" ).Set "sachin"

window("Title:=Login").WinEdit("AttachedText:=Password:").Set "mercury"

window("Title:=Login").winbutton("Text:=OK").Click

window("Title:=Flight Reservation").close

Now modifying the above script using Description.Create.

Set myvar= description.Create()

myvar("AttachedText").value="Agent Name:"

myvar("height").value=20

myvar("width").value=119

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4b.exe"

window("Title:=Login").WinEdit(myvar ).Set "sachin"

window("Title:=Login").WinEdit("AttachedText:=Password:").Set "mercury"

window("Title:=Login").winbutton("Text:=OK").Click

window("Title:=Flight Reservation").close

57

Page 58: QTP Basics

QuickTest Professional 9.2

10.3 Retrieving child objects in Descriptive Programming

There is a ChildObjects method which can be used to get all objects located within a specific parent object or only those that match some criteria for programmatic description. In short we first of all need to create a description and then use a particular syntax to retrieve all child objects that match that description and manipulate them according to our own wish.

EXAMPLE:

1. Make sure that Flight Reservation window is open (Start- Programs- QuickTest Professional- Sample Applications- Flight). In this Flight reservation window go to File- Open Order.

2. We will use this childobjects method to count the checkboxes in this 'Open Order' dialogbox. In the below script childobjects method is being applied to dialog object and childobjects method uses mydescription property object we created.

Set mydescription=Description.Create()mydescription("Class Name").value="WinCheckBox"Set Checkboxes = window("text:=FLight Reservation").dialog("text:=Open Order").ChildObjects(mydescription)a=Checkboxes.countmsgbox(a)

Just try to understand the above code. This is just an example, in real life you can use this count in some kind of loop

58

Page 59: QTP Basics

QuickTest Professional 9.2

10.4 Creating checkpoints

Run-time value of a specified object property can be compared with expected value of that property by using programmatic description.Descriptive programming checks are helpful for the object whose properties you want to check but the object is not stored in Object Repository.

EXAMPLE:

This example checks if the "Flights.." button in Flight Reservation window is enable or disable. Message box has been used to show whether it is enable or disable, you can use the Report.ReportEvent Statement to send the results to the result window of QTP.

For the below script make sure that Flight reservation window is open:

a=window("Title:=Flight Reservation").winbutton("Text:=FLIGHT").GetROProperty("enabled")msgbox (a)If a = True Thenmsgbox ("button is enable")elsemsgbox ("button is disable")End If

In the above script GetROProperty method is being applied to 'Flight..' button to check the 'enable' property of the button.

[you can see an object's properties and methods from QTP help. Definitely there are other ways also to get these].

DP is also useful in case of programming WebElement objects (A WebElement is a general web object which can represent any web object.)

As an example, just open the website (http://newtours.demoaut.com/) and make sure the cursor is in the “User Name” text box and write the following line in the Expert View of new test:

browser("title:=Welcome: Mercury Tours").page("title:=Welcome: Mercury Tours").webelement("name:=password","index:=2").Click

It will just click the “Password” text box which just highlights that text box and places the mouse cursor in that box.

For all the methods and properties of WebElement object please refer QTP User Guide.

59

Page 60: QTP Basics

QuickTest Professional 9.2

10.5 Using Index Property

Index property is useful to identify a test object uniquely. QTP also, while learning an object, can assign a value to test object’s index property to uniquely identify it. Index property values are specific to an object and also the value is based on the order in which the object appears in the source code.The value starts with 0.

If you use Index:=1 with WebEdit test object, QTP will search for the second WebEdit object on a web page.

As an example, just open the website (http://newtours.demoaut.com/) and write the following line in the expert view of new test:

browser("title:=Welcome: Mercury Tours").page("title:=Welcome: Mercury Tours").WebEdit("Index:=1").Set "hello"

This will write “hello” in the “Password” text box. In the above line if you do Index:=0 then “hello” will be written in the “User Name” text box.

On the other hand if you use Index:=2 to describe a WebElement object, QTP will search for the third object on the page (it can be any, regardless of type) because WebElement object is general object that applies to all objects.

60

Page 61: QTP Basics

QuickTest Professional 9.2

11 Best PracticesThese scripts can be reused for all the applications with slight modification relative to project and application needs. These scripts can be used to run the test automatically without Manual Intervention in setting the initial Steps.

Task Code

To open the application without configuring in the Record & Run settings

Invoke Application “<path>”

To open & close application 'Open notepad

SystemUtil.Run("notepad.exe")'wait for 3 secondsWait(3)'Close the nodepadSystemUtil.CloseProcessByName("Notepad.exe")

To set the URL in the Browser ‘Declare an object variable

Dim IE‘Creates a browser object

Set IE = CreateObject("InternetExplorer.Application")GettheURL=”URL to open”‘Set URL in the browser

IE.Visible = True IE.Navigate GettheURL

To set the repository without configuring resources tab, use the following code.

‘Declare an object variable

Dim qtApp ‘Creates an object

Set qtApp = CreateObject ("QuickTest.Application")‘Create an object for Resources

Set qtTestResources= qtApp.Test.Settings.Resources ‘Set repository path

qtTestResources.ObjectRepositoryPath=”Repository path”

To change the values of environment variables in the test. (This is applicable only for

Environment.Value(“VariableName”)=”SetNewValue”

61

Page 62: QTP Basics

QuickTest Professional 9.2

Task Code

previously created Environment variables.)

To set and get the test object property values

‘Sets the value of the Search Textbox

Browser ("Google").Page ("Google").WebEdit ("q"). SetTOProperty "value","QTP"‘Gets the value of the Search Textbox

Val=Browser("Google").Page("Google").WebEdit("q"). GetTOProperty("value")

To get the current value of the test object property

Browser ("Google").Page ("Google").WebEdit ("q"). Set Datatable.Value("SearchString")‘Gets the current value of the Search Textbox

Val=Browser("Google").Page("Google").WebEdit("q"). GetROProperty("value")

To access the runtime object properties and methods

Set obj=Browser ("Google").Page ("Google"). WebEdit("q").Object‘Access the runtime method focus

obj.focus()

To import data to data table ‘ExternalData is an Environment variable containing the path of the file

ExternalFilePath=Environment.Value("ExternalData")Datatable.Import(ExternalFilePath)‘Organisation is the sheet name in the file

Datatable.ImportSheet ItemGroupValue, "Organisation","Global"

QTP can be programmed to send a mail to outlook regarding the Status or completion of the test run. The following code can be deployed

Function SendMail(SendTo,Subject,Body,Attachment) Set ol = CreateObject("Outlook.Application") Set Mail = ol.CreateItem(0) Mail.to = SendTo Mail.Subject = Subject Mail.Body = Body

62

Page 63: QTP Basics

QuickTest Professional 9.2

Task Code

If (Attachment <> "") Then Mail.Attachments.Add(Attachment) End If Mail.Send ol.Quit Set Mail = nothing Set ol = nothing End Function SendMail "[email protected]",TestCaseName, Status,"Attachment"

To create text file. Dim fso, new_file'create filesystemobject Set fso = createobject("scripting.filesystemobject")'create file Set new_file = fso.createtextfile("c:\testfile.txt", True) 'write to filenew_file.writeline("hello world!")'close the filenew_file.close

63

Page 64: QTP Basics

QuickTest Professional 9.2

12 Function LibrariesIf you have repeatable steps in a test or an action then consider using a user-defined function. User-defined functions will make your tests look shorter, easier to maintain, read and design. A user-defined function can then be called from within an action.

Advantages of using functions:

● Time and resources can be saved by implementing and using user-defined reusable functions.

● User-defined functions can be stored in a function library or within an action in the test.

● User-defined functions can be registered as a method for a QTP test object.

[It is advisable not to give user-defined functions same name as built-in functions (refer to the Built-in functions list in the Step Generator (Insert > Step Generator, in theStep Generator dialog box choose Built-in functions from Library Combo box, it will show all of the Built-in functions in Operation Combo box))]

If the function is stored in a function library then we have to associate that function library to a test so that the test can call all the public functions listed in that library.

Functions in an associated function library are accessible:

● From Step Generator (for tests and function libraries),

● From the Operation column in the Keyword View, or

● Can be entered manually in the Expert View.

Functions directly stored in an action in a test can be call from within that action only making them very private from the outside world.

A Private function can also be created in a function library and this private function can only be called from within the function library itself in which it is defined.

Creating Functions:

Functions can be created manually or by using Function Definition Generator.

It is easy to create a function library:

1. Open a new function library file->New->Function library).

2. Add content to it (your function). Associate it with a test (File-> Associate Library with Test).

You are ready to go.

Many different function libraries can be opened simultaneously as each opens in its own separate window and you can work on them separately.

If a test is open you can view all the function libraries associated with it. (Resources->Associated Function Libraries.)

You can save function library either from File->Save or right click on function library tab on the 64

Page 65: QTP Basics

QuickTest Professional 9.2

top of function library and choose save.

Some important points regarding function libraries:

● When we register a function, it applies to an entire test object class and it’s not possible to register a method for a specific test object.

● If we use options like Run from step or Debug from step, to begin running a test from a point after method registration was performed in a test step (and not in a function library), QTP does not recognize the method registration because it occurred earlier to the beginning of the current run session and this all is due to the reason that QTP clears all method registrations at the beginning of each run session.

● If you want to use Option Explicit statement in FunctionLibrary, you must include it in all the function libraries associated with the test otherwise QuickTest ignores all the Option Explicit statements in all function libraries.

● Steps using user-defined functions are not displayed in the test results tree of the Test Results window by default. For function to appear in the test results tree, you must add a Reporter.ReportEvent statement to the function code.

● If a function library that is referenced by a test is modified by you or any other user using an external editor, the changes will take effect only after the test is reopened.

● Always make sure that each function has a unique name, if more than one function with the same name exists in the test script or function library, QTP will always call the last function because QuickTest searches the test script for the function prior to searching the function libraries.

● Most important of all: If you register a method within a reusable action, it is strongly recommended to unregister the method at the end of the action (and then re-register it at the beginning of the next action if necessary), so that tests calling your action will not be affected by the method registration.

We can re-register the same method with different user-defined functions without first unregistering the method. When it is unregistered it is reset to its original QTP functionality e.g.

RegisterUserFunc "WebEdit", "Set", "MySet"

RegisterUserFunc "WebEdit", "Set", "MySet2"

UnRegisterUserFunc "WebEdit", "Set"

After running the UnRegisterUserFunc statement, the Set method stops using the functionality defined in the MySet2 function, and returns to the original QuickTest Set functionality, and not to the functionality defined in the MySet function.

If there are two associated function libraries that define the same variable in the global scope using a Dim statement or define two constants with the same name, the second definition causes a syntax error. Include a Dim statement only in the last function library (since function libraries are loaded in the reverse order). If you need to use more than one variable with the same name in the global scope.

65

Page 66: QTP Basics

QuickTest Professional 9.2

Example 1 (Simple example of a Function Library and test)

1. Open a new test. Go to File->New->Test.

2. Open a new function library. Go to File->New->Function library.(Now both new test and function library are open at the same time and we are in function library.)

3. Go to Insert->Function Definition Generator.

4. In the Function Definition Generator window, type the name of the function as my_sum.

5. In the Arguments area click on ‘+’ and type the name of first argument as ‘var1’ and again click on ‘+’ and type the name of second argument as ‘var2’ and let the Pass Mode be the default which is ‘By Value’.

6. In Additional Information area, enter the Description as ‘addition function’. Let the ‘Documentation’ be empty. Click on Ok to close that Function Definition Generator window.

7. Now it will add the function to your already open Library.

8. Now we have to write the function body (where it says TODO:)

9. Finally it will look like:

'@Description addition function

Public Function my_sum(var1, var2)

sum=var1+var2

msgbox sum

End Function

10. Save it. (Save it by giving any name and extension either .qfl (by default) or .vbs or .txt)

11. Associate it. (File-> Associate Library with Test)

12. In expert view of Associated test type:

my_sum 1, 2

66

Page 67: QTP Basics

QuickTest Professional 9.2

Example 2 (Example using private and public functions in function library)Another example which uses both public and private functions in the function library.1. Open a new function library. Go to File->New->Function library.

2. Open a new test. Go to File->New->Test.

3. Write the below two functions in the function library. One of the functions is private i.e. it can be accessed from within the function library itself and cannot be accessed from outside of this function library. One of the functions is public which we will access from the test.

Private Function my_name_tell(name2)msgbox "Hello " & name2

End Function

Public Function my_name(name1)msgbox(name1)my_name_tell(name1)

End Function

4. Save the function library.

5. Associate the function library with the test which is open.

6. In the expert view of the test type:

my_name("sachin")

7. When you run it, it will show two message boxes, one from the public function and second from the private function.

67

Page 68: QTP Basics

QuickTest Professional 9.2

Example 3 (Example of registering a function to a test object by creating a new operation)

1. Open a new test.

2. Open a Function Library.

3. Make sure that we are in Function Library.

4. Go to Insert-> Function Definition Generator.

5. Type the name of the function in the 'Function definition' area (function_1). Let Type and Scope be the default i.e. ‘Function’ and ‘Public’ respectively.

6. Click on '+' in the ‘Arguments’ area and type 'var1' under Name to create a new variable and let the Pass Mode be default i.e. 'By Value'.

7. Check the 'Register to a test object' checkbox.

8. From Test Object dropdown select 'WinEdit' and in the Operation dropdown instead of selecting one of the values it already shows there, just type a new value 'NewOperation'

9. In the ‘Additional information’ area, type 'my first operation on WinEdit' in Description text box.

10. Click Ok.

11. It copies the whole code it generated in the Preview area to the open library.

12. After it is copied to the already open library just complete the function body.

Finally it looks like this:

'@Description my first operation on WinEdit

Public Function function_1(test_object, var1)

' TODO: add function body here

msgbox var1

End Function

RegisterUserFunc "WinEdit", "NewOperation","function_1"

13. Save the function library.

14. Once it is saved, go to File->'Associate Library with Test' to associate this function library with the already open test.

15. After it is associated go the ‘Expert View’ of the test already open and type:Window("title:=Filght Reservation").WinEdit("Attached text:=Name:", "height:=20").as soon as you press . (dot), the list of operations which WinEdit supports are displayed by default (also called IntelliSense), just select NewOperation from there.

68

Page 69: QTP Basics

QuickTest Professional 9.2

16. After selecting NewOperation just supply one argument to it because while creating the function we provided one argument called var1. So the final line of code in the Expert View now looks like:

Window("title:=Filght Reservation").WinEdit("Attached text:=Name:", "height:=20").NewOperation "merry"

[You can open Flight Reservation window for this test, but it is not necessary]

17. Run the test.

It does nothing for the WinEdit object or anything special. It just displays a message box with the value which we have supplied to it at the time of writing the code. This is just a simple example to show how it works.

If in this same test you go to ‘Keyword View’, it will show you NewOperation under the Operation column. It is displayed as an operation in the Keyword View Operation list when that test object is selected from the Item list. But here we are not using any Object repository (we are using Descriptive Programming) so we cannot select any object from the Item list as the Object Repository is empty. But if we do the below steps it surely will show:

We will record a simple step in a new action.

1. Now insert another new action in this test. (Insert->Call to New Action)

2. Make sure ‘Flight Reservation’ window is open.

3. Click on Record.

4. In the ‘Flight Reservation’ window, in the Name text box enter any name.

5. Stop recording.

6. Now go to the ‘Keyword View’. In this ‘Keyword View’, go to the row which has 'Name' under item.

7. Make a single click under Operation column in that row (click where it shows Set) it will show a dropdown and you will be able to see NewOperation in that dropdown. This NewOperation will be there for every object of class WinEdit.

8. Now if you open any new test and again type

Window("title:=Filght Reservation").WinEdit("Attached text:=Name:", "height:=20").

Now QTP will not display NewOperation unless otherwise you associate the library we created earlier to this new test.

69