Thursday, 14 June 2012

SystemUtil Object Usage in QTP

SystemUtil Object:
SystemUtil Object used to control applications and processes during a run session


Run: Used to Runs a file or application.
e.g: Systemutil.Run "","","",""

CloseProcessByName: Closes a process according to its name.
e.g: Systemutil.CloseProcessByName("Excel.exe")

BlockInput: Used to Prevents keyboard and mouse input events from reaching applications.
e.g: Systemutil.BlockInput

UnblockInput: Used to Re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
e.g: Systemutil.UnblockInput

CloseDescendentProcesses: Used to Closes all processes opened by QuickTest.

CloseProcessByHwnd: Used to Closes a process that is the owner of a window with the specified handle.

CloseProcessById: Used to Closes a process according to its Process ID.

CloseProcessByWndTitle: Used to Closes all processes that are owners of windows with the specified title.

Friday, 8 June 2012

Recovery Scenarios in QTP

Recovery Scenarios in QTP: 
Unexpected events, errors, and application crashes during a run session can disrupt your run session and distort results. This is a problem particularly when running tests or components unattended, the test or component is suspended until you perform the operation needed to recover.

The Recovery Scenario Manager provides a wizard that guides you through the process of defining a recovery scenario-a definition of an unexpected event and the operation(s) necessary to recover the run session. For example, you can instruct QTP to detect a Printer out of paper message and recover the run session by clicking the OK button to close the message an continue the test or component.

A recovery scenario consists of the following: 
·        Trigger Event: The event that interrupts your run session. For example, a window that may pop up on screen, or a QTP run error.
·        Recovery Operation(s): The operation(s) that need to be performed in order to continue running the test or component. For example, clicking an OK button in a pop-up window, or restarting Microsoft Windows.
·        Post-Recovery Test Run Option: The instructions on how QTP should proceed once the recovery operations have been performed, and from which point in the test or component QTP should continue, if at all. For example, you may want to restart a test or component from the beginning, or skip a step entirely and continue with the next step in the test or component.

Recovery scenarios are saved in recovery scenario files. A recovery scenario file is a logical collection of recovery scenarios, grouped according to your own specific requirements.
To instruct QTP to perform a recovery scenario during a run session, you must first associate it with that test or component. A test or component can have any number of recovery scenarios associated with it. You can prioritize the scenarios associated with your test or component to ensure that trigger events are recognized and handled in the required order.
When you run a test or component for which you have defined recovery scenarios and an error occurs, QTP looks for the defined trigger event(s) that caused the error. If a trigger event has occurred, QTP performs the corresponding recovery and post-recovery operations. 
You can also control and activate your recovery scenarios during the run session by inserting Recovery statements into your test or component.

Recovery Scenario Functions:
Here, we will define a Function Call and use that Function Call to handle the error. The default syntax for the Recovery Scenario Function is:

Functions should have 4 parameters:

Function FunName (Object, Method, Arguments, retVal)
End Function

Object here refers to the object which has triggered the recovery scenario, Method of that object, Arguments and retVal.

When the recovery scenario is triggered, all 4 parameters will be passed to the function automatically by QTP

Function ProjRecovery(Object, Method, Arguments, retVal)
        'Error Handling Code
End Function

Variables Naming Convention in QTP Scripting

Variables Naming Convention in QTP Scripting:

Variables represent values that can be changed within a procedure or function. Local scope variables are placeholders that reside within a function- or a script-body.

Prefixes for Variable Data Types

Data Type

 The values of global variables can be used and changed all over the project within all scripts and libraries.

Syntax: "g" + [Prefix]+[ShortDescription] 

Eg: gstrName

Thursday, 7 June 2012

Relative Path Usage in QTP

Relative Path:

There can be two types of path in your file System, absolute and relative. A full path or absolute path is a path that points to the same location on one file system regardless of the working directory.
Example of a full path: C:\Program Files\HP\QuickTest Professional\Tests, while a relative path is a path relative to the current working directory, so the full absolute path may not need to be given.

Example of a relative path: If your current working directory is Quick Test Professional as shown above so the relative path for the folder HP which is one level up would be ..\..\HP similarly folder which is on same level can be referenced by ..\Some Folder

Friday, 27 April 2012

Child Objects Use in QTP

This script is to check checkbox in a page

Set obj=Description.Create
obj("html tag").value="INPUT"

set ChkObj=Browser("name:=Email").Page("title:=q").ChildObjects(obj)
ChkObj (0).set"ON"

Wednesday, 25 April 2012

Basic QTP Knowledge(Questions)

1. How do you hide the Add-In Manager so that it will not be displayed while launching QTP?

Answer: a) Uncheck “Show on Startup” checkbox in the Add-In Manager

b) Uncheck “Display Add-In Manager on Startup” in the General tab of Options dialog box.

2. How do you display the DataTable or Active screen if they are not shown by default?

Answer: In Menu choose View → Active Screen or View → Data Table.

3. What are the default add ins provided by QTP?

Answer: ActiveX, Visual Basic, Web.

4. What is the default location of DataTable for any QTP script?

Answer: Script Folder Test Folder (folder with the name of the test where all test files are stored)

5. What is QTP workflow Phases: Create, Display, Verify and Enhance, Integrate.??????

Alternative answer: Create test suite, Create an engine, Automate test cases, Debug the script, Deploy the script to QA team.

6. Low level Recording is used to record?

Answer: To record actual keyword objects or ignore Object identification capabilities

Answer: To record your clicks and keyboard input based on coordinates.

7. What are the conditional statements provided in QTP?

Answer: For..Next, While….wend, For……loop, Do….. While, If… Else…. End If, Select…. Case.

Answer: If… Else…. End If, Select…. Case.

8. What is the first step to change the logical name of the object recorded by Quick Test?

Answer: Identify the instances of the object in the script. {S1, S2…S10 – OR}

Alternative answer: Identify the instances of the object in the Object Repository{S_1, S_2…S_10}.

9. Where can you find the result of an output parameter?

Answer: Runtime Datasheet in Results

10. Where do you set action iterations for a specified action?

Answer: Action call Properties in Action0 Script

11. Which of the following is created by default with new action?

Answer: Action Properties, LocalSheet of Data Table

12. Which source property specifies that data is retrieved from database?

Answer: Output type

13. Local object Repository is used for Single action tests. TRUE/FALSE

Answer: TRUE

14. Shared object Repository is created in Object Repository Manager.

Answer: Question looks like an answer itself

15. Which tool is used to merge two shared object repositories?

Answer: Merge Tool in Object Repository Manager.

16. Virtual objects are stored in?

Answer: dat folder of QTP Installation

17. How do you create a Template for every Actions?

Answer: Write the template script as “ActionTemplate.mst” in DAT folder of QTP Installation

18. Bitmap checkpoint takes into consideration

Answer: Image size and pixel match

19. Breakpoint is used for?

Answer: Pauses the test execution at Current Step and then proceed to next step when instructed.

20. When using recovery scenario wizard, the first phase is to specify?

Answer: Triggered Events

21. What all the types of Triggred Events :

Answer: popup window, object state, test run error, application crash

22. GetTOProperty is used to?

Answer: Getting the test object properties i.e property from Repository.

Answer: Returns the value of the specified property from the test object description.

23. Give me 2 examples of ADODB objects?

Answer: QuickTest?, Recordset and Connection.

24. Close method is used to close the database session. –

It is unclear what they mean because the question was altered: Close can be used to close a window or dialog too.

25. Exportsheet is used for?

Answer: Exports a specified sheet of the run-time Data Table to the specified file.

26. Recovery scenario: is used to handle exceptions i.e. unpredictable actions/Errors.

Answer: Question looks like an answer itself

27. Step Generator is used for?

Answer: Adding Steps to scripts without recording using the Repository/Utility Objects etc.

28. Information pane and missing resource used for?

Answer: The Information pane provides a list of syntax errors in your test or function library scripts.

The Missing Resources pane provides a list of the resources that are specified in your test but cannot be found, such as missing calls to actions, unmapped shared object repositories, and parameters that are connected to shared object repositories.

29. Where do you enable smart identification?

Answer: Object Identification.

Answer: Check box in the Run tab of Test Settings dialog box.

30. What are the environment variable types?

Answer: User defined and built-in.

31. One more area to look into is Menu options i.e., where to look to enable or disable different features of QTP .There are around 4 to 5 questions covering the same.

Answer: can’t be given

32. By which type, procedure parameters passes the values to script?

Answer: ByRef

Answer: String, Boolean, Date, Number, Password, Any.

33. If we create a procedure under any test/script, Where we can use it?

Answer: Procedure can be used only in the Test/script in which it is created, not callable from other test

Answer: If Action containing a procedure is reusable, it may me used in another tests.

34. If we create a procedure under function library, how does it save with which extension:
Answer: .QFL/VBS/TXT

35. What is the difference between function and subroutine?

Answer: function can return a value, where as subroutine cannot.

36. What are the different STEP commands?

Answer: Step Into, Step Out, Step Over

37. Which keyword is used for counter increment Under For…Next loop?

Answer: Step

38. In Do Loop, at which point the condition is checked to proceed for next iteration?

Answer: End of the loop, minimum one iteration will execute

39. What is the first step to use the low level recording mode?

Answer: Open in Normal mode

Answer: Normally start recording.

40. How do register a procedure/function to a test object :

Answer: RegisterUserFunc statement

41. How do you bypass the object repository?

Answer: Descriptive Programming or Programming Desc

42. Where do you set the action as reusable action?

Answer: Action Properties

43. Global Data sheet is having one record and Local Data sheet is having two records, how many times the test executes by default?

Answer: One time

Answer: It also depends on record and run settings: in this question they assume “Run on all rows” radiobutton selected.

44. Test -->Settings --> Run tab belongs to which sheet:

Answer: Global

45. Global Data sheet is having no records and Local Data sheet is having two records, how many times the test executes?

Answer: One time

46. How do you find the number of columns in database table?

Answer: Fields.Count or Get the array size of the Record Set object. i.e upper limit.

Answer: Use GetParameterCount method of DTSheet object

47. What will return for ChildObjects method?

Answer: Returns the collection of child objects contained within the object.

48. Where can you set the smart identification "ON":

Answer: Check “Enable Smart Identification in the Object Identification dialog.

49. How can we release the database after its use?

Answer: Close the connection and Recordset objects; then set the object of "ADODB.Connection" type to “Nothing”

50. How can u link individual actions to shared repository?

Answer: Resources>Associate repositories

51. Which object properties are shown in object identification box?

Answer: Mandatory and Assistive

52. Where can we disable the virtual object recognition?

Answer: Toolsà Options à General à check “Disable Virtual Object Recognition” checkbox

53. How to associate a procedure to a test object class?

Answer: Use RegisterUserFunc statement.

54. Which object is used in sending information to the test results?

Answer: Reporter

55. What is default identifier type for web objects?

Answer: Index

Answer: CreationTime

56. Test object properties are:
Answer: those mentioned in object identification box and in object repository

57. Which object is used to read from text file?

Answer: “Scripting.FileSystemObject”

58. A dot followed by object in expert view displays?

Answer: Child objects and methods

59. While merging the two object repositories, what are the filter options available for target object repository?

Answer: Show all objects & show only objects with conflicting descriptions

60. How to declare a constant?

Answer: Const name = value

61. The method used to retrieve data from the weblist object is?

Answer: GetItem method

62. What is the method used to get the object name from a Web table cell?

Answer: ChildItem

63. How do you know the no of links in a web page?

Answer: Page Check point,

Answer: a set of statements:

Set PageDesc = Description.Create

PageDesc(“Class Name”).Value = “Link”

Set Pages = Browser("Mercury Interactive").Page("Mercury Interactive").ChildObjects(PageDesc)

Number_of_pages = Pages.Count

If Number_of_pages = 0 Then

Reporter.ReportEvent micDone, “ There are No links was found in the web page, “

End If

64. What will change using update run mode?

Answer: The test updates the test object descriptions, the expected results of check pts and Active screen images and values.

65. If virtual objects are available at your machine, but you don't want to consider the virtual objects what you will do?

Answer: In Tools Options General, we will configure to ignore the Virtual Objects by changing “Disable recognition of virtual objects while recording”.

66. What is the default “Ordinal Identifier”?

Answer: Location

67. What is the default property of ordinal identifier when using smart identification?

Answer: Mandatory and assistive properties.

Answer: Properties displayed in the Base Filter Properties list.

68. How to declare constant variables?

Answer: Const Name = [value]

69. How did you find whether script used the smart Identification or not?

Answer: It will show in the test result pane as a Warning

70. What is the first step in editing an object in the object repository?

Answer: Enable Editing

Tuesday, 24 April 2012

Function to Select Multiple Items in the Listbox

Function SelectItems(Obj, items)
    Dim idx, item
    If (StrComp(obj.GetROProperty("type"), "select-multiple", 1) = 0) Then
        For Each item In items
    End If
End Function

Right Clicking Objects Using Device Replay

The function DeviceReplay object to perform a right-click operation on any object by retrieving the coordinates of the object.

Sub RightClickObj(Obj, Offset_x, Offset_y)
       x_coord = Obj.GetROProperty("abs_x")
       y_coord = Obj.GetROProperty("abs_y")
       Set dr = CreateObject("Mercury.DeviceReplay")
       dr.MouseClick x_coord + Offset_x, y_coord + Offset_y, 2
End Sub

Monday, 16 April 2012

Input/Output Action Parameter Use in QTP

Input/Output Action Parameter:
Passing Action Input parameter & returning back output value
Action 1(Code)
Dim inputvar
Dim outputvar
RunAction “Action2″, oneiteration, inputvar,outputvar
1. Set Input parameter of action2->ActionProperties with inputvar parameter name
2. Set Output parameter of action2->ActionProperties with output parameter name
Write this below code in Action2
Dim var

Monday, 9 April 2012

Dictionary Object

Object that stores data key, item pairs.
A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array
Dim d   ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Atlas"   ' Add some keys and items.
d.Add "b", "Board"
d.Add "c", "Chart"
CompareMode Property
Sets and returns the comparison mode for comparing string keys in a Dictionary object.
Optional. If provided, compare is a value representing the comparison mode. Acceptable values are 0 (Binary), 1 (Text), 2 (Database). Values greater than 2 can be used to refer to comparisons using specific Locale IDs (LCID).
Dim d
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare
d.Add "a", "Atlas"   ' Add some keys and items.
d.Add "b", "Board"
d.Add "c", "Chart"
d.Add "B", "Ball"   ' Add method fails on this line because the 
                         ' letter b already exists in the Dictionary.
Item Property (Script Runtime)
Sets or returns an item for a specified key in a Dictionary object. For collections, returns an item based on the specified key. Read/write.
Function ItemDemo
   Dim d   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Atlas"   ' Add some keys and items.
   d.Add "b", "Board"
   d.Add "c", "Chart"
   ItemDemo = d.Item("c")   ' Get the item.
End Function
Key Property
Sets a key in a Dictionary object.
Function DicDemo
   Dim d   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Atlas"   ' Add some keys and items.
   d.Add "b", "Board"
   d.Add "c", "Chart"
   d.Key("c") = "d"   ' Set key for "c" to "d".
   DicDemo = d.Item("d")   ' Return associate item.
End Function
Add Method (Script Runtime)
Adds a key and item pair to a Dictionary object.
Dim d   ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Atlas"   ' Add some keys and items.
d.Add "b", "Board"
d.Add "c", "Chart"
Exists Method (Script Runtime)
Returns true if a specified key exists in the Dictionary object, false if it does not.
Function KeyExistsDemo
   Dim d, msg   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Atlas"   ' Add some   keys and items.
   d.Add "b", "Board"
   d.Add "c", "Chart"
   If d.Exists("c") Then
      msg = "Specified key exists."
      msg = "Specified key doesn't exist."
   End If
   KeyExistsDemo = msg
End Function
Items Method
Returns an array containing all the items in a Dictionary object.
Function DicDemo
   Dim a, d, i, s   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Atlas"   ' Add some keys and items.
   d.Add "b", "Board"
   d.Add "c", "Chart"
   a = d.Items   ' Get the items.
   For i = 0 To d.Count -1 ' Iterate the array.
      s = s & a(i) & "<br>" ' Create return string.
   DicDemo = s
End Function
Keys Method
Returns an array containing all existing keys in a Dictionary object.
Function DicDemo
   Dim a, d, i   ' Create some variables.
   Set d = CreateObject("Scripting.Dictionary")
   d.Add "a", "Atlas"   ' Add some keys and items.
   d.Add "b", "Board"
   d.Add "c", "Chart"
   a = d.Keys   ' Get the keys.
   For i = 0 To d.Count -1 ' Iterate the array.
      s = s & a(i) & "<br>" ' Return results.
   DicDemo = s
End Function
Remove Method (Script Runtime)
Removes a key, item pair from a Dictionary object.
Dim a, d   ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Atlas"   ' Add some keys and items.
d.Add "b", "Board"
d.Add "c", "Chart"
d.Remove("b")   ' Remove second pair.
RemoveAll Methods
The RemoveAll method removes all key, item pairs from a Dictionary object.
Dim a, d, i   ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Atlas"   ' Add some keys and items.
d.Add "b", "Board"
d.Add "c", "Chart"
a = d.RemoveAll   ' Clear the dictionary.

Friday, 6 April 2012

Enter Text in to a WebElement

Function EnterWebElementText
set oDes=Browser("").Page("").Frame("Frame").WebElement("html tag:=BODY")
oDes.object.innerText="QTP is a functional tool"
End Function

Function to Page Scroll

Function Scroll()
Set oDoc=Browser("micclass:=Browser").Page("micclass:=Page").Object.Body
Set oDoc=Nothing
End Function

Recovery Scenario Function Call for List Item not found

Function Recovery_ListItemIsNotFound(Object, Method, Arguments, retVal)
Dim sAllItems, arrAllItems, intItem
With Object
'Retrieve all items from the Listbox
sAllItems = GetROProperty("all items")
'Split 'all items' using a delimiter ";" into an array
arrAllItems = Split(sAllItems, ";")
'Select a random number
intItem = RandomNumber.Value(LBound(arrAllItems), UBound(arrAllItems))
.Select "#" & intItem
Reporter.ReportEvent micInfo, "ListItemIsNotFound", "Item: " & .GetROProperty("value")
End With
End Function

Function to Execute Multiple QTP Scripts

Function LoadAndRun()
arrColl = Array("C:\filename1","C:\filename2","C:\filename3")
For each arrTest in arrColl
qtApp.Open arrTest
set qtTest = qtApp.Test
set objResultsOptions = CreateObject("QuickTest.RunResultsOptions")
objResultsOptions.ResultsLocation = arrTest & "\Res1"
qtTest.Run objResultsOptions
End Function

RegisterUserFunc Example

' function : GetItemsCountFunction
' desc : Returns the number of items from a weblist

Function GetItemsCountFunction(objWebList)

If (objWebList = Nothing) Then
GetItemsCount = 0
GetItemsCount = objWebList.GetROProperty("Items Count")
End If

End Function

'add GetItemsCount as a method of the WebList class
RegisterUserFunc "WebList", "GetItemsCount", "GetItemsCountFunction"

Function Call to read a Text File

Function ReadTextFile(strFilePath)

' reading a file line by line

Const ForReading = 1

' create file system object
Set objFS = CreateObject("Scripting.FileSystemObject")

' first check that the file exists
If objFS.FileExists(strFilePath) Then

' open the text file for reading
Set objFile = objFS.OpenTextFile(strFilePath, ForReading, False)

' do until at end of file
Do Until objFile.AtEndOfStream

' store the value of the current line in the file
strLine = objFile.ReadLine

' show the line from the file
MsgBox strLine

Loop ' next line

' close the file

Set objFile = Nothing

Else ' file doesn't exist

' report a failure
Reporter.ReportEvent micFail, "Read File", "File not found"

End if ' file exists

' destroy the objects
Set objFS = Nothing

End Function

Function Call for write to a Text File

Function AppendtTextFile(strFileName, strLine)

Dim objFS
Const ForAppending = 8

' create the file system object
Set objFS = CreateObject("Scripting.FileSystemObject")

' open/create the text file
Set objFile = objFS.OpenTextFile(strFilename, ForAppending, True)

' write the line
objFile.WriteLine strLine

' close the file

End Function '


Thursday, 5 April 2012

Benefits of Automated Testing

Benefits of Automated Testing


QuickTest runs tests significantly faster than human users.


Tests perform precisely the same operations each time they are run, thereby eliminating human error.


You can test how the Web site or application reacts after repeated execution of the same operations.


You can program sophisticated tests that bring out hidden information.


You can build a suite of tests that covers every feature in your Web site or application.


You can reuse tests on different versions of a Web site or application, even if the user interfaces changes.

Built-in Environment Variables

Built-in Environment Variables:

QuickTest provides a set of built-in variables that enable you to use current information about the test and the QuickTest computer running your test. These can include the test name, the test path, the operating system type and version, and the local host name.

For example, you may want to perform different checks in your test based on the operating system being used by the computer that is running the test. To do this, you could include the OSVersion built-in environment variable in an If statement.

You can also select built-in environment variables when parameterizing values.

The following built-in environment variables are available:




The action iteration currently running.


The name of the controller's computer. This variable is relevant only when running as a GUI Vuser from the LoadRunner controller.


The name of the group in the running scenario. This variable is relevant only when running as a GUI Vuser from the LoadRunner controller.


The local host name.


The operating system.


The operating system version.


The folder path where the product is installed.


The product name.


The product version.


The path of the folder in which the current test results are located.

Note: You cannot use the ResultDir environment variable when running a test from Business Availability Center, LoadRunner, or the Silent Test Runner in QuickTest.


The identification number of the scenario. This variable is relevant only when running as a GUI Vuser from the LoadRunner controller.


The system temporary directory.


The path of the folder in which the test is located.


The test iteration currently running.


The name of the test.


Indicates whether the Active Screen images and values are being updated during the update run process. For more information, see Updating a Test Using the Update Run Mode Option.


Indicates whether checkpoints are being updated during the update run process. For more information, see Updating a Test Using the Update Run Mode Option.


Indicates whether the set of properties used to identify test objects are being updated during the update run process. For more information, see Updating a Test Using the Update Run Mode Option.


The Windows login user name.


The Vuser identification under load. This variable is relevant only when running as a GUI VUser from the LoadRunner controller.