Top Banner
For more QTP Scripts, www.ramupalanki.com 1.Activate: Activates the current Dialog Box. Syntax: object.Activate [BUTTON] Example: Sub Activate_Example() ‘The following example uses the Activate method to activate the ‘Internet Options dialog box. Browser(”Mercury Tours”).Dialog(”Internet Options”).Activate End Sub2. CaptureBitmap: Saves the screen capture of the object as a .png or .bmp image using the specified file name. Syntax: object.CaptureBitmap FullFileName, [OverrideExisting] Example: Sub CaptureBitmap_Example1() ‘The following example uses the CaptureBitmap method to capture a ’screen shot of the Internet Options dialog box. The file is ‘automatically saved to a different folder (the test run results ‘folder) in each run. Browser(”Mercury Tours”).Dialog(”Internet Options”).CaptureBitmap “internet_options.bmp” End Sub 3. ChildObjects: Returns the collection of child objects contained within the object. Syntax: object.ChildObjects (pDescription) Example: ‘The following example uses the ChildObjects method to retrieve a ’set of child objects matching the description listed in the function ‘call and uses the method to display a message indicating how many ‘objects are found with the specified description: none, one (unique), ‘or several (not unique). Public Function CheckObjectDesription(parent, descr) Dim oDesc ‘ Create description object Set oDesc = Description.Create() arProps = Split(descr, “,”) For i = 0 To UBound(arProps) arProp = Split(arProps(i), “:=”) www.ramupalanki.com
36

Qtp best tutorial

Nov 12, 2014

Download

Documents

Ramu Palanki

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

1.Activate: Activates the current Dialog Box.Syntax: object.Activate [BUTTON]Example:Sub Activate_Example()‘The following example uses the Activate method to activate the‘Internet Options dialog box.Browser(”Mercury Tours”).Dialog(”Internet Options”).ActivateEnd Sub2. CaptureBitmap: Saves the screen capture of the object as a .png or .bmp image using the specified file name.Syntax: object.CaptureBitmap FullFileName, [OverrideExisting]Example:Sub CaptureBitmap_Example1()‘The following example uses the CaptureBitmap method to capture a’screen shot of the Internet Options dialog box. The file is‘automatically saved to a different folder (the test run results‘folder) in each run.Browser(”Mercury Tours”).Dialog(”Internet Options”).CaptureBitmap “internet_options.bmp”End Sub

3. ChildObjects: Returns the collection of child objects contained within the object.Syntax: object.ChildObjects (pDescription)Example:‘The following example uses the ChildObjects method to retrieve a’set of child objects matching the description listed in the function‘call and uses the method to display a message indicating how many‘objects are found with the specified description: none, one (unique),‘or several (not unique).Public Function CheckObjectDesription(parent, descr)Dim oDesc‘ Create description objectSet oDesc = Description.Create()arProps = Split(descr, “,”)For i = 0 To UBound(arProps)arProp = Split(arProps(i), “:=”)If UBound(arProp) = 1 ThenPropName = Trim(arProp(0))PropValue = arProp(1)oDesc(PropName).Value = PropValueEnd IfNext

www.ramupalanki.com

Page 2: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

‘ Get all child objects with the given descriptionSet children = parent.ChildObjects(oDesc)If children.Count = 1 ThenCheckObjectDesription = “Object Unique”ElseIf children.Count = 0 ThenCheckObjectDesription = “Object Not Found”ElseCheckObjectDesription = “Object Not Unique”End IfEnd Function

4. Click: Clicks on a object.Syntax: object.Click [X], [Y], [BUTTON]Example:Sub Click_Example()‘The following example uses the Click method to click a right mouse‘button at coordinates 47, 131 on the Internet Options dialog box.

Browser(”Mercury Tours”).Dialog(”Internet Options”).Click 47, 131, 1

End Sub

5. Close: Closes the Dialog Box.Syntax: object.CloseExample:Sub Close_Example()‘The following example uses the Close method to close the Internet‘Options dialog box.Browser(”Mercury Tours”).Dialog(”Internet Options”).CloseEnd Sub

6. DblClick: Double clicks on a object.Syntax: object.DblClick X, Y, [BUTTON]Example:Sub DblClick_Example()‘The following example uses the DblClick method to double-click a right‘mouse button at coordinates 73, 120 on the SysListView32 object.Window(”Exploring”).WinListView(”SysListView32″).DblClick 73, 120, 1End Sub

7. Drag: Performs the ‘drag’ part of a drag and drop operation.Syntax: object.Drag X, Y, [BUTTON]Example:Sub Drag_Example1()

www.ramupalanki.com

Page 3: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

‘The following example uses the Drag and Drop methods to drag the object from‘coordinates 10, 20 within the Test window and drop the object at‘coordinates 30, 40 within the same window.Window(”Test”).Drag 10, 20Window(”Test”).Drop 30, 40End Sub

8. Drop: Performs the ‘drop’ part of a drag and drop operation.Syntax: object.Drop X, Y, [BUTTON]Example:Sub Drop_Example1()‘The following example uses the Drag and Drop methods to drag the object from‘coordinates 10, 20 within the Test window and drop the object at‘coordinates 30, 40 within the same window.Window(”Test”).Drag 10, 20Window(”Test”).Drop 30, 40End Sub

9. Exist: Checks that an object exists.Syntax: object.Exist([TimeOut])Example:Sub Exist_Example()‘The following example uses the Exist method to determine the existence‘of the Internet Options dialog box. If the dialog box exists a‘message box appears confirming its appearance.If Browser(”Mercury Tours”).Dialog(”Internet Options”).Exist ThenMsgBox (”The object exists.”)End IfEnd Sub

10. GetRoProperty: Returns the current value of the test object property from the object in the application.Syntax: object.GetROProperty (Property, [PropData])Example:

Sub GetROProperty_Example()

‘The following example uses the GetROProperty method to retrieve the

‘x coordinate of the Test window.

x = Window(”Test”).GetROProperty(”x”)

y = Window(”Test”).GetROProperty(”y”)

End Sub

www.ramupalanki.com

Page 4: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

11. GetTextLocation: Checks whether the specified text string is contained in the specified window area.

Syntax: object.GetTextLocation (TextToFind, Left, Top, Right, Bottom, [MatchWholeWordOnly])

Example:

Sub GetTextLocation_Example()

‘The following example uses the GetTextLocation method to retrieve

‘all of the text within the object.

l = -1

t = -1

r = -1

b = -1

result = Dialog(”Dialog”).WinObject(”Date”).GetTextLocation(”2002″, l, t, r, b)

If result Then

MsgBox “Text found. Coordinates:” & l & “,” & t & “,” & r & “,” & b

End If

End Sub

12. GetToProperties: Returns the collection of properties and values used to identify the object.

Syntax: object.GetTOProperties

Example:

Sub GetTOProperties_Example1()

‘The following example uses the GetTOProperties method to retrieve the

‘list of properties and values used to identify the Internet Options

‘dialog box.

IEOptsDialog = Browser(”Mercury Tours”).Dialog(”Internet Options”).GetTOProperties()

End Sub

13. GetToProperty: Returns the value of a specified property from the test object description.

Syntax: object.GetTOProperty (Property)

Example:

Sub GetTOProperty_Example()

‘The following example uses the GetTOProperty method to retrieve the

‘RegExpWndClass property from the Object Repository.

Dim ObjectName

RegExpWndClass = Window(”Test”).GetTOProperty(”RegExpWndClass”)

End Sub

14. GetVisibleText: Returns the text from specified area.

Syntax: object.GetVisibleText ([Left], [Top], [Right], [Bottom])

Example:

Sub GetVisibleText_Example1()

‘The following example uses the GetVisibleText method to retrieve the

‘text from the Telnet window. If the returned string contains the “login:”

www.ramupalanki.com

Page 5: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

’sub-string, the Type method is used to type the guest string in the

‘window.

TelnetText = Window(”Telnet”).GetVisibleText

If InStr(1, TelnetText, “login:”, 1) > 0 Then

Window(”Telnet”).Type “guest”

End If

End Sub

15. MouseMove: Moves the mouse pointer to the designated position inside the activeXobject.Syntax: object.MouseMove X, YExample:Sub MouseMove_Example()‘The following example uses the MouseMove method to move the mouse‘pointer to the position (20, 30) inside the Advanced object.Browser(”MyPage”).Dialog(”Settings”).WinObject(”Advanced”).MouseMove 20, 30End Sub

16. Move: Moves the dialog box to the specified absolute location on the screen.Syntax: object.Move X, YExample:Sub Move_Example()‘The following example uses the Move method to move the Internet‘Options dialog box to the specified location.Browser(”Mercury Tours”).Dialog(”Internet Options”).Move 659, 35End Sub

17. Maximize: Maximize the dialog box to fill the entire screen.Syntax: object.MaximizeExample:Sub Maximize_Example()‘The following example uses the Maximize method to maximize the‘Internet Options dialog box.Browser(”Mercury Tours”).Dialog(”Internet Options”).MaximizeEnd Sub

18. Minimize: Minimizes the dialog box to an icon.Syntax: object.MinimizeExample:Sub Minimize_Example()‘The following example uses the Minimize method to minimize the‘Internet Options dialog box.Browser(”Mercury Tours”).Dialog(”Internet Options”).MinimizeEnd Sub

www.ramupalanki.com

Page 6: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

19. Resize: Resize the dialog box to the specified dimensions.Syntax: object.Resize Width, HeightExample:Sub Resize_Example()‘The following example uses the Resize method to resize the Internet‘Options dialog box.Browser(”Mercury Tours”).Dialog(”Internet Options”).Resize 296, 348End Sub

20. Restore: Restores the dialog box to its previous size.Syntax: object.RestoreExample:Sub Restore_Example()‘The following example uses the Restore method to restore the‘Internet Options dialog box to its previous size.Browser(”Mercury Tours”).Dialog(”Internet Options”).RestoreEnd Sub

21. SetToProperty: Sets the value of the specified property in its test object description.Syntax: object.SetTOProperty Property, ValExample:Sub SetTOProperty_Example()

‘The following example uses the SetTOProperty method to set the

‘index of a window’s description.

Window(”Test”).SetTOProperty “Index”, 2

End Sub

22. Type: Type the specified string in the dialog box.

Syntax: object.Type KeyboardInput

Example: Not Available

23. WaitProperty: Waits until the specified object property achieves the specified value or exceeds the specified

timeout before continuing to the next step.

Syntax: object.WaitProperty (PropertyName, PropertyValue, [lTimeOut])

Example:

Sub WaitProperty_Example()

‘The following example uses the WaitProperty method to make the

‘program wait for the “Test” window to become active or for 3 seconds

‘(3 milliseconds) to pass, whichever comes first.

y = Window(”Test”).WaitProperty(”focused”, True, 3000)

End Sub

www.ramupalanki.com

Page 7: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

24. Output: Retrieves the current value of an item and stores it in a specified location.

Syntax: object.Output pVerify

Example:

Sub Output_Example()

‘The following example uses the Output method to output text into the

‘”You can change” Data Table column.

Browser(”index”).Dialog(”Internet Options”).Static(”You can change”).Output CheckPoint(”You can change”)

End Sub

QTP COMBO BOX PROPERTIES

1. GetContent: Returns a string containing the names of all of the items in the combo box.

Syntax: object.GetContent

Example:

Sub GetContent_Example ()

How to View Object Properties by using Object Spy This short tutorial guides you to a method by which you can view the Object Properties & Methods with the help of Object Spy in QTP.

We can view the Properties and Methods of any object in an open application with the help of Object Spy pointing hand

mechanism. As we move the pointing hand over the objects in the application,ि�र details get displayed in the Object

Spy.

These details displayed in the Object Spy are the hierarchy tree of the test object, its properties and values, and the methods associated with the object. For methods, the syntax is also displayed.

Steps to view test object properties or methods:

Step-1: Open the application to the page containing the object on which we want to spy say google.com.

Step-2: Choose Tools > Object Spy or click the Object Spy toolbar button to open the Object Spy dialog box and display

the Properties tab.

Or click the Object Spy button from the Object Repository dialog box.

Step-3: Select the details we want to view for the object.

Click Run-time Object Properties or Test Object Properties radio button.

www.ramupalanki.com

Page 8: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

To view the object’s available methods and syntax, click the Methods tab. Properties tab is displayed by

default, enabling us to view the object’s properties and values.

Step-4: In the Object Spy dialog box, click the pointing hand which is displayed on top. QuickTest remains hidden. As

we move the pointing hand over the test objects in our application, the test objects get highlighted, and we can view their test object properties or methods in the Object Spy dialog box. We can also view their parent objects in the object hierarchy tree area of the Object Spy dialog box.

Step-5: Highlight or click the object whose properties or methods we want to view। The Object Spy displays the object

hierarchy tree and the properties or methods of the object that is selected within the tree.

Step-6: Click the object whose associated methods we want to view. The Object Spy displays the object hierarchy tree

and details for the selected object according to our selection.

Step-7: To view the properties or methods of the test object, click the Test Object Properties radio button. To view the

properties or methods of the run-time object, click the Run-time Object Properties radio button.

Step-8: If we want to view properties, values, or methods for another object within the displayed tree, highlight or

click the object in the tree and select the relevant options, as described in step 3 above.

Step-9: If we want to copy an object property or value, or a method’s syntax to the Clipboard, click the property, value,

or method to highlight it. The value gets displayed in the selected property / value or method syntax box which islocated above the Description box. Highlight the text in the box and use CTRL + C to copy the text to the Clipboard orright-click the highlighted text and choose Copy from the menu.

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

www.ramupalanki.com

Page 9: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

folder (if you created checkpoint in action1 then it will be action 1 folder under the folder in which you are saving thetest/script, if you created checkpoint in action 2 then it will be action 2 folder and so on) .

In the expert view, on any blank line type Checkpoint and put "(". As soon as you put the starting bracket it will show

all the checkpoints you have used in the test.Now we will start with checkpoints. I will try to show easy to understand example of each and every checkpoint.Lets start with simple example of standard checkpoint which checks a variety of objects such as buttons, radio buttons,

combo boxes etc. Standard checkpoints are supported for all add-in environments

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 "WindowsApplications" tab and choose first option "Record and run test on any open Windows based application." andclick 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.

www.ramupalanki.com

Page 10: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

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:

Make sure that this test and Flight application is open. Click on run.

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

To see a Fail test result:

Make sure that this test and Flight application is open.

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)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.This will help you in understanding the standard checkpoint in QTP more deeply.Labels: Automated testing,Checkpoint,QTP

QTP Tutorials 5 - Page Checkpoint Page checkpoint:It is for web applications only.Common things to check with this are load time, broken links etc. 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.

www.ramupalanki.com

Page 11: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

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.

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 I saved the test

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. How To close MsgBox Runtime Write the below line as the first-line in your script. Set sh = CreateObject(”Scripting.Shell”) …This will create a shell object at run-time and will be available until the test ends. If you are getting problem like ,Activex Component can’t create object Then use Set sh =CreateObject(”WScript.Shell”)

Now… where ever you are having “msgbox” replace it with..sh.Popup “message content”, 5, “msg header”, (0+4)the above line will show the message content for 5 seconds(and vanishes after that).The alert-box’s header will have “header info”. Last parameter(0+4) is actually two things. 0 -> show OK button in the

www.ramupalanki.com

Page 12: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

alertBox 48 -> “!” icon… if you use 64 u will see X icon instead BTW… since u need the message to be displayed

QTP Tips and Faqs

Data Table Two Types of data tables

Global data sheet: Accessible to all the actions

Local data sheet: Accessible to the associated action only

Usage:

DataTable(”Column Name”,dtGlobalSheet) for Global data sheet

DataTable(”Column Name”,dtLocalSheet) for Local data sheet

If we change any thing in the Data Table at Run-Time the data is changed only in the run-time data table. The run-timedata table is accessible onlythrough then test result. The run-time data table can also be exported usingDataTable.Export or DataTable.ExportSheet

How can i save the changes to my DataTable in the test itself?

Well QTP does not allow anything for saving the run time changes to the actual data sheet. The only work

around is to share thespreadsheet and then access it using the Excel COM Api’s.

How can i check if a parameter exists in DataTable or not?

The best way would be to use the below code:code:on error resume next val=DataTable(”ParamName”,dtGlobalSheet) if err.number<> 0 then ‘Parameter does not exist

else ‘Parameter exists end if

www.ramupalanki.com

Page 13: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

How can i make some rows colored in the data table?

Well you can’t do it normally but you can use Excel COM API’s do the same. Below code will explain some

expects of Excel COM APIs

code:

Set xlApp=Createobject(”Excel.Application”) set xlWorkBook=xlApp.workbooks.add setxlWorkSheet=xlWorkbook.worksheets.add xlWorkSheet.Range(”A1:B10″).interior.colorindex = 34 ‘Change the color ofthe cells xlWorkSheet.Range(”A1:A10″).value=”text” ‘Will set values of all 10 rows to “text”xlWorkSheet.Cells(1,1).value=”Text” ‘Will set the value of first row and first colrowsCount=xlWorkSheet.Evaluate(”COUNTA(A:A)”) ‘Will count the # of rows which have non blank value in the

column A colsCount=xlWorkSheet.Evaluate(”COUNTA(1:1)”) ‘Will count the # of non blank columns in 1st rowxlWorkbook.SaveAs “C:\Test.xls” xlWorkBook.Close Set xlWorkSheet=Nothing Set xlWorkBook=Nothing setxlApp=Nothing

SMART IdentificationSmart Identification is nothing but an algorithm used by QTP when it is not able to recognize

one of the object. A very generic example as per the QTP manual would be, A photograph of a 8 year old girl and boyand QTP records identification properties of that girl when she was 8, now when both are 10 years old then QTPwould not be able to recognize the girl. But there is something that is still the same, that is there is only one girl in thephotograph. So it kind of PI (Programmed intelligence) not AI.

When should i use SMART Identification?

Something that people don’t think about too much. But the thing is that you should disable SI while creating your testcases. So that youare able to recognize the objects that are dynamic or inconsistent in their properties. When the scripthas been created, the SI should be enabled,so that the script does not fail in case of small changes. But the developer ofthe script should always check for the test results to verify if the SIfeature was used to identify a object

www.ramupalanki.com

Page 14: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

or not.Sometimes SI needs to be disabled for particular objects in the OR, this is advisable when you use

SetTOProperty to change any of the TO properties of an object and especially ordinal identifiers like index, location

and creationtime.

Descriptive Programming

Descriptive programming is nothing but a technique using which operations can be performed on the AUT

object which are not present in the OR.

Recovery ScenariosWhat is a Recovery Scenario?

Recovery scenario gives you an option to take some action for recovering from a fatal error in the test. The error could range in fromoccasional to typical errors. Occasional error would be like “Out of paper” popup error while printing something and typical errors would be like”object is disabled” or “object not found”. A test case have more then one scenario associated with it and also have the priority or order in which itshould be checked.

What does a Recovery Scenario consists of?

Trigger: Trigger is nothing but the cause for initiating the recovery scenario. It could be any popup window,

any test error, particular stateof an object or any application error.

Action: Action defines what needs to be done if scenario has been triggered. It can consist of amouse/keyboard event, close application, call arecovery function defined in library file or restart windows.You can have a series of all the specified actions.

Post-recovery operation: Basically defined what need to be done after the recovery action has been taken. It

www.ramupalanki.com

Page 15: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

could be to repeat the step, moveto next step etc….

When to use a Recovery Scenario and when to us on error resume next?

Recovery scenarios are used when you cannot predict at what step the error can occur or when you know thaterror won’t occur in yourQTP script but could occur in the world outside QTP, again the example would be“out of paper”, as this error is caused by printer device driver. “Onerror resume next” should be used whenyou know if an error is expected and dont want to raise it, you may want to have different actionsdependingupon the error that occurred. Use err.number & err.description to get more details about the error.

Library Files or VBScript Files

How do we associate a library file with a test ?

Library files are files containing normal VBScript code. The file can contain function, sub procedure, classes etc…. You can also use executefilefunction to include a file at run-time also. To associate a library file with your script go to Test->Settings… and add your library file to resourcestab.

When to associate a library file with a test and when to use execute file?

When we associate a library file with the test, then all the functions within that library are available to all theactions present in the test. Butwhen we use Executefile function to load a library file, then the function areavailable in the action that called executefile. By associated a library toa test we share variables across action(global variables basically), using association also makes it possible to execute code as soon as the scriptrunsbecause while loading the script on startup QTP executes all the code on the global scope. We can useexecutefile in a library file associated

with the test to load dynamic files and they will be available to all the actions in the test.

Test and Run-time Object

What is the difference between Test Objects and Run Time Objects ?

www.ramupalanki.com

Page 16: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

Test objects are basic and generic objects that QTP recognize. Run time object means the actual object to which

a test object maps.

Can i change properties of a test object

Yes. You can use SetTOProperty to change the test object properties. It is recommended that you switch off the

Smart Identification for theobject on which you use SetTOProperty function.

Can i change properties of a run time object?

No (but Yes also). You can use GetROProperty(”outerText”) to get the outerText of a object but there is nofunction like SetROProperty tochange this property. But you can useWebElement().object.outerText=”Something” to change the property.

Action & Functions

What is the difference between an Action and a function?

Action is a thing specific to QTP while functions are a generic thing which is a feature of VB Scripting. Actioncan have a object repositoryassociated with it while a function can’t. A function is just lines of code withsome/none parameters and a single return value while an action canhave more than one output parameters.

Where to use function or action?

Well answer depends on the scenario. If you want to use the OR feature then you have to go for Action only. Ifthe functionality is not about anyautomation script i.e. a function like getting a string between to specificcharacters, now this is something not specific to QTP and can be done onpure VB Script, so this should bedone in a function and not an action. Code specific to QTP can also be put into an function using DP.

www.ramupalanki.com

Page 17: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

Decisionofusing function/action depends on what any one would be comfortable using in a given situation.

Checkpoint & Output value

What is checkpoint?

Checkpoint is basically a point in the test which validates for truthfulness of a specific things in the AUT.There are different types ofcheckpoints depending on the type of data that needs to be tested in the AUT. Itcan be text, image/bitmap, attributes, XML etc….

What’s the difference between a checkpoint and output value? •

Checkpoint only checks for the specific attribute of an object in AUT while Output value can output those attributes value to a column in datatable. How can i check if a checkpoint passes or not? code: chk_PassFail = Browser(…).Page(…).WebEdit(…).Check (Checkpoint(”Check1″)) if chk_PassFail then MsgBox “Check Point passed” else MsgBox “Check Point failed” end if My test fails due to checkpoint failing, Can i validate a checkpoint without my test failing due to checpoint failure? code:

Reporter.Filter = rfDisableAll ‘Disables all the reporting stuff chk_PassFail = Browser(…).Page(…).WebEdit(…).Check

(Checkpoint(”Check1″)) Reporter.Filter = rfEnableAll ‘Enable all the reporting stuff if chk_PassFail then MsgBox

“Check Point passed” else MsgBox “Check Point failed” end if

Environment How can i import environment from a file on disk •

Environment.LoadFromFile “C:\Env.xml” How can i check if a environment variable exist or not? •

When we use Environment(”Param1″).value then QTP expects the environment variable to be already defined.

But when we useEnvironment.value(”Param1″) then QTP will create a new internal environment variable if it

does not exists already. So to be sure that variable existin the environment try using

Environment(”Param1″).value.

How to connect to a database? code:

Const adOpenStatic = 3 Const adLockOptimistic = 3 Const adUseClient = 3 Set objConnection =

CreateObject(”ADODB.Connection”) Set objRecordset = CreateObject(”ADODB.Recordset”) objConnection.Open

“DRIVER={Microsoft ODBC for Oracle};UID=<UID>;PWD=<PWD>” objRecordset.CursorLocation = adUseClient

objRecordset.CursorType = adopenstatic objRecordset.LockType = adlockoptimistic ObjRecordset.Source=”select

field1,field2 from testTable” ObjRecordset.ActiveConnection=ObjConnection ObjRecordset.Open ‘This will execute

your Query If ObjRecordset.recordcount>0 then

www.ramupalanki.com

Page 18: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

Field1 = ObjRecordset(”Field1″).Value Field2 = bjRecordset(”Field2″).Value End if How to do the backward compatability in QTP How to run the scripts in 8.2 those are recorded in 9.0 or higher Sol: Step 1: Delete the object repository of 9.0Step 2: open a Blank test in 8.2Step 3: Create the shared object repository in 8.2 that should contain all the objects in 9.0 and save.Step 4: create the action structure in 8.2 should contain the same num of actions, same names and structure as the

script of 9.0.Step 5: save the test. (From now we call this as 8.2 scripts)Step 6: from 8.2 script copy Test.tsp file to the 9.0 script.Step 7: copy all Resource.MTR file found in Action0, Action 1, etc to 9.0 scriptsStep 8: now u can run the scripts with little modifications if require

1 INTRODUCTION

Mercury Quick Test Professional 8.0 provides the industry’s best solution for functional test and regression testautomation - addressing every major software application and environment. This next-generation automatedtesting solution deploys the concept of Keyword-driven testing to radically simplify test creation andmaintenance. Unique to Quick Test Professional’s Keyword-driven approach, test automation experts have fullaccess to the underlying test and object properties, via an integrated scripting and debugging environment that isround-trip synchronized with the Keyword View.Quick Test Professional 8.0 satisfies the needs of both technical and non-technical users. It enables you to deployhigher-quality applications faster, cheaper, and with less risk. It empowers the entire testing team to createsophisticated test suites with minimal training.

Advantages:• Empower the entire team to create sophisticated test suites with minimal training• Ensure correct functionality across all environments, data sets, and business processes• Fully document and replicate defects for developers, enabling them to fix defects faster and meet productiondeadlines• Easily regression-test ever-changing applications and environments

www.ramupalanki.com

Page 19: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

• Become a key player in enabling the organization to deliver quality products and services, and improverevenues and profitability

New Features in QTP 8.0

FEATURE USEKeyword View Lets you easily build and maintain tests without writing VBScriptsAuto-Documentation Provides improved test clarity and the ability to view test steps in plain EnglishStep Generator Allows you to quickly insert custom-built functions into your testsEnhanced Expert View Provides greater efficiency when generalizing test componentsAction Parameters Allows you to generalize testing actions for greater reusabilityCustom Reports Enables you to create custom reports for your unique needsUnicode Support Lets you test global deployments of your enterprise applications

2.0 RECORDING A SESSION

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

Example:

While recording the home page of Google the following code is

generated.

Browser("Google").Page("Google").WebEdit("Search").Set "QTP "

Browser("Google ").Page("Google").WebEdit("Search").Submit

Browser("Google").Page("GoogleSearch: QTP").Link("QTP").Click

Browser("Google ").Page("QTP").Sync

RECORDING MODES

www.ramupalanki.com

Page 20: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

Quick test supports the following recording modes:

a. Normal: recognizes the objects in the application irrespective of their location in the screen.

b. Analog: records the exact keyboard and mouse operations with respect to the screen coordinates or the

application window.

c. Low level: records any object irrespective of support from QTP. Recognizes all run time objects as windows

objects. It is used when an object is not identified by Quick test.

By default the normal recording mode is enabled.

3.0 RUNNING A SESSION

When 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 Active 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 any 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.

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"

www.ramupalanki.com

Page 21: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

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.

4.0 ACTIONSA test is composed of actions or logical sections. The steps we add to the test are added within the test’s actions. Bydefault, 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 detailedresults for each action individually. Each action has its own sheet in the Data Table so that we can insert data thatapplies 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 actionis used the action is read only in the calling test. But, any existing action can be inserted as a copy of the originalaction. 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.Actions List Back ShowThe Action Tool Bar will be visible, only when, we have one or more external/reusable actions in our Action to

displayà Tool Barsàtest. If it is invisible, use View it.

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

www.ramupalanki.com

Page 22: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

button. The Insert New Action dialog box opens. (In QTP 8.0, Insert Call to New Action)3) Type a new action name or accept the default name.4) Add a description of the action.5) Select Reusable Action to make it reusable. This can be

modified at a later time in the Action properties dialog box.

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

7) Click OK.

4.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.a) Inserting calls to an action makes it easier to maintain tests, because when an object or procedure in theapplication changes, it needs to be updated only once, in the original action.

b) 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 anindependent, 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 onlythis action, and changes to the original action do not affect the inserted action. We can insert copies of bothreusable and non-reusable actions.

Select an existing action, and choose:Call to Copy of an action / Call toàInsert selectàUse the Browse button to choose the actionàExisting Action asrequired Click OK.àthe location

4.3 Nesting Actions

Running 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

www.ramupalanki.com

Page 23: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

current stepas 6th step.

4.4 Splitting Actions

To split an existing action:1) Select the step with which the new action should begin.Splità2) Choose Step Action. The following window appears:• If we select ‘Independent of each other’ option: it creates 2 independent actions, with second action beginningwith the selected step.• If we select ‘Nested’ option: It creates two actions, with first one calling the second. (A Parent-Childrelationship).

3) We can also change the Names and Descriptions of these actions.4.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.

5.0 OBJECT MANAGEMENTQuick Test identifies objects of two types• Test Objects: Objects in the test that represent objects in the application or website that are created and

maintained by QTP.

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

5.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 assistiveproperties to do the same. We can modify these properties using the Add\Remove button. Smart

www.ramupalanki.com

Page 24: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

Identification isused to identify the object if the learned properties are not sufficient.

5.2 Object RepositoryAll objects recorded for the test are stored in the repository. The Object Repository displays all objects in thecurrent action or the entire test. The Object Repository can be used to view or modify the properties of any objectin the reposirory or to add new objects to the repository. An object in the application can be highlighted using theHighlight option. A temporary frame appears around the object causing it to flash. But the application must beopen and the object should be visible in the page. The object spy can also be accessed from the Repository.

Set the object repository path from Test->Settings->Resource Tab. Select the repository file with the extension .tsr.If the repository file is not available create a file with extension .tsr. The repository path must be set before startingrecording.The Object Repository can be Per Action or Shared.• The shared repository can be used by multiple actions of the same test or by actions from different tests. Testobject properties are prone to frequent updation. While adding existing actions, we can copy an action using thesame Object Repository and Call actions using the same Object Repository, or Object Repository per action mode• Per Action object repository is used by one or very few tests.Test object properties are modified lessfrequently.While adding existing actions, if we are using different object repositories for different actions (Onerepository per action) then we can copy or call actions from tests using Object Repository per Action mode.5.3 Object SpyIt can be used to view the properties and values of an object in any open application. Click the pointing hand toselect 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 asmouse clicks or window focus hold the CTRL key.

6.0 CHECKPOINTS

www.ramupalanki.com

Page 25: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

A checkpoint is a verification point that compares a current value for a specified property with the expected value for that property. Thus it ensures proper functionality of the objects in the application. When you add a checkpoint for an object a statement containing Check Checkpoint is added in the Expert view. Checkpoints can be added in the following ways.

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

After selecting the object, add the property that is to be checked. For example, for a standard checkpoint on a radiobutton for the property ‘selected’ checks whether the radio button is selected or not. Checkpoints can also beplaced in the Keyword view. Right click the object in the keyword view and insert the required checkpoint.

Example:

Consider inserting a checkpoint for the Search textbox in the Home page of Google. The following code is

generated.Browser ("Google").Page ("Google").WebEdit ("Search").Check CheckPoint ("Search")If you want to retrieve value from the checkpoint, use parenthesis around the checkpoint argument.

TYPES OF CHECKPOINT

2TYPES DESCRIPTION

Standard CheckPoint

It checks the property value of an object in your application or Web page. It checks a variety of objects such as

buttons, radio buttons, combo boxes, lists, etc.Image CheckPointIt checks the value of an image in the application. We can create an image checkPoint by inserting a standard

checkPoint on the image object.Bitmap CheckPoint

www.ramupalanki.com

Page 26: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

It checks an area of the application as a bitmap.To create a bitmap checkpoint of multiple objects, select the highest

level object that includes all the objects to include in the bitmap checkpoint.Text CheckPointIt checks whether the text string is displayed in the appropriate place in your application or on a Web pageText Area CheckPointIt checks whether the text string is displayed within the defined area in the application. If the area defined is

associated with more than one object, the Object Selection-Text Area Checkpoint Properties dialog box opens.Table CheckPointIt checks the information within a table or the table itself. The row or column values can also be checked.Accessibility CheckPointIt identifies areas of the Web site that do not conform to the World Wide Web Consortium (W3C) Web Content

Accessibility Guidelines.

Page CheckPointIt checks whether the page is displayed correctly and gives information like number of links, number of imagesand load time of the page

Database CheckPoint

It checks the contents of a database accessed by the applicationXML CheckPointIt checks the data content of XML documents in XML documents in the application7.0 OUTPUT VALUES

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

www.ramupalanki.com

Page 27: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

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

We can create the following categories of output values:• Standard Output Values: to output the property values of most objects like editbox,button,radio button,listbox,etc.• Text Output Values: to output text strings displayed in the application. When creating a text output value, wecan 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 alsooutput a part of the object’s test.• Database Output Values: to output the contents of database cells, based on the results of a 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.

ExampleBrowser("Google").Page("Google").WebEdit("Search").Set "QTP"Browser("Google").Page("Google").WebEdit("Search").Output CheckPoint("Search")Browser("Google").Page("Google").WebEdit("Search").SubmitBrowser("Google ").Page("Google Search: QTP").Link("QTP").ClickBrowser("Google ").Page("QTP").Sync

8.0 PARAMETERIZATION

A parameter is a variable that is assigned a value from an external data source at run time. We useparameterization when we want to change the value of properties at run time. Parameterization can be done inthree 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

www.ramupalanki.com

Page 28: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

and check the Parameter option from the configure vlue frame and enter the value in the datatable column.

8.1 DataTable ParametersThe 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 theDatatable iterations frame.

ExampleConsider parameterising the search string in the home page of Google.Each time you want to search for a differentstring. Enter the search string in the datatable and change the code as followsBrowser("Google").Page("Google").WebEdit("Search").SetDatatable.Value("SearchString")

Browser("Google").Page("Google").WebEdit("Search").Submit

The datatable contains the searchstrings for search. The datatable has two rows and thus the test runs for two iterations.We can import data for the datatable from an external source such as Excel. Choose the resources tab from Test->Settings and select Other location in the Datatable frame and specify the path of the Excel file.

8.2 Environment variable ParametersThe Environment variables can have Quick Test generated values or values supplied from external files. We canadd environment variables from Test->Settings->Environment tab. Choose User-defined from the variable type.Click New to create your own internal variables or Click Export to retrieve values from external sources.

8.3 Random number ParametersIt enables us to use random numbers as values in the test. We can specify the range from which the randomnumber is generated. By default, the random number range is between 0 and 100.

===================================================================================

Synchronization is a property that enables to instruct QTP to wait for a state of a property on a particular object tochange before preoceeding to the next step in the test case. It also enables a test to pause when the application processcompletes before moving to the next step. QTP displays an error message if it proceeds to the next step

www.ramupalanki.com

Page 29: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

beforecompleting the previous step.

Parameterisation facilitates reusabillity of an action or a test. By using parameters, you can record a test once and use it

several times and also enables to run multiple sets of data.

Addin envvironment enables to recognize objects in the development environment of Application Under Test(AUT).

The Default Add ins that come along with QTP are Web, Acttivex and Visual Basic.

types:

1. wait()

2. Synchronization point

1. Wait(): pause the test for fixed time specified in the

wait statement.

2. Synchronization point: To define the time mappingbetween the QTP and application, we use this concept. If wedont want to perform any operation until an object in ourapplication achieves certain status then we can insertsynchronization point to instruct QTP to pause the testuntil the object getting the certain value.

"checkpoint is a feture provided by qtp which is used forchecking something during executiion at any of time".checkpoints works in 2 phases:1.pre-execution phase2.while execution phasetypes of checkpoints:1.standard checkpoints

2.bitmap checkpoints

3.text checkpoints

4.textarea checkpoints

5.database checkpoints

6.xml checkpoints

www.ramupalanki.com

Page 30: Qtp best tutorial

For more QTP Scripts, www.ramupalanki.com

7.page checkpoints

8.table checkpoints

9.image checkpoints

10.accessability checkpoints7,8,9 are hidden checkpoints.7-10 are web related checkpoints.

www.ramupalanki.com