QTP Basics
Important Questions & Answers in QTP Interview
What is QTP?
Quick Test Professional (QTP) provides functional and regression test automation for software applications and environments.It is automation tool which provides IDE(Integrated Development Environment) for automation testing.
What is UFT?
Unified Functional Testing(UFT) formerly known as QTP can be used for enterprise quality assurance.It uses the Visual Basic Scripting Edition (VBScript) scripting language to specify a test procedure.
(QTP) supports 3 types of recording modes:
- Normal or Context Sensitive(Default Recording Mode)
- Analog
- Low Level
Context Sensitive Recording mode
- Normal recording mode is also called Context Sensitive Mode
- It is the default mode of recording which takes full advantage of Quick Test Professional's test object model.
- It recognizes objects in application regardless of their location on the screen.
- It records the objects in your application and the operations performed on them
Analog Recording Mode
- In analog recording mode, Quick Test Professional records and tracks every movement of the mouse as you drag the mouse around a screen or window.
- QTP's Analog recording is captured as Tracks and stored in the directory of your test
- It is useful for recording operations that cannot be recorded at the level of an object. Eg., A signature produced by dragging the mouse
- In Analog mode you can record
1. Record Relative to screen
2. Relative to window
- When your analog operation are confined to just one window , use relative to window
- When your analog operation involve multiple screens like dragging and dropping an object from one window to other use the screen option
Low Level Mode
- This mode enables you to record on any object in your application, irrespective of QTP recognizes the specific object or the specific operation.
- This mode records at the object level and records all run-time objects as either Window or WinObject test objects..
- It is used when the exact coordinates of the object are important for your tests. A good example would be hashmaps where clicking different sections of a picture takes you to different links
- Used when recording tests in an environment (or on an object) not recognized by QTP
- Low level mode records the x,y coordinates of any clicks
What is a Test in QTP?
A test in QTP is divided into actions which consists of test steps and all the validation as per the requirement.The extension of the test script in QTP is .mts(Mercury Test Script).
What are the default add-ins in QTP?
A test in QTP is divided into actions which consists of test steps and all the validation as per the requirement.The extension of the test script in QTP is .mts(Mercury Test Script).
What are the default add-ins in QTP?
- Visual Basic
- Activex
- Web
User interface’s in QTP:
Keyword View: The basic view in Normal understandable english without coding knowledge.
Expert View: IDE to develop code.
fig: Expert view in QTP
![]() |
Add caption |
· The scripting language commonly used in QTP is VBScript.
· A variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity or information referred to as a value.
How to declare a variable in VBScript?
Dim Keyword is used to declare a variable in VBScript.
E.g.,
Dim varcontact
Option Explicit
If the above keyword(Option Explicit) is declared in the library file or test then the variables used in the test or library should be declared and if the keyword is not present means, then the variable declartion is optional.
.mtr - Local Action Repository (this is a binary file)
.mts - Script files (contains the QTP code )
.bdb - Berkeley Data base, an oracle product
.usr - Load Runner File
.tsp - Its a binary file not sure about but most probably contains the QTP test settings
'Default Timeouts:
Browser Navigation timeout - 60 seconds
Checkpoint timeout - 20 seconds
Object synchonisation timeout - 20 seconds
Note: We can change the default timeouts in Test>Settings
What is AOM in QTP?
Automation object model is a set of objects, methods, and properties that helps testers to control the configuration settings and execute the scripts using the QTP interface. The Key Configurations/actions that can be controlled are listed below but not limited to,
- Loads all the required add-ins for a test
- Makes QTP visible while execution
- Opens the Test using the specified location
- Associates Function Libraries
- Specifies the Common Object Sync Time out
- Start and End Iteration
- Enable/Disable Smart Identification
- On Error Settings
- Data Table Path
- Recovery Scenario Settings
- Log Tracking Settings
QTP 11.5x provides an exclusive documentation on Automation Object model that can be referred by navigating to "Start" >> "All Programs" >> "HP Software" >> "HP Unified Functional Testing" >> "Documentation" >> "Unified Functional Testing Automation Reference"
Generate AOM Script:
Tester can generate AOM Script from QTP itself using "Generate Script" Option. Navigate to "Run" >> "Settings" >> "Properties" Tab >> "Generate Script" as shown below:
Example of AOM:
Dim App 'As Application
Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
App.Test.Settings.Launchers("Web").Active = False
App.Test.Settings.Launchers("Web").Browser = "IE"
App.Test.Settings.Launchers("Web").Address = "http://easycalculation.com/"
App.Test.Settings.Launchers("Web").CloseOnExit = True
Set App = Nothing
QTP Test Settings:
QTP - Test settings tabs:
For QTP test settings: File>Settings. This is one area where many questions are asked, what do you find in the parameters tab, which tab do you find "object synchronisation timeout" etc. I have provided the screenshots of the different tabs for you to prepare for the certification.
The images below are with respect to QTP version 10.0.
Tab1 - Properties:
Tab2 - Run:
Tab3 - Resources:
Tab4 - Parameters:
Tab5 - Environment:
Tab6 - XML Warehouse:
Tab7 - Web:
Tab8 - Recovery:
Tab9 - Local System Monitor:
How to run QTP scripts from QC?
1. Establish QC - QTP connection through QC client Addin.
2.In QTP, connect ALM(QC latest version) by providing QC server URL and Credentials.
3.Enable the checkbox present in Tools>Options>Run,
4.Associate the Qc test script in code by,
a) at run time using,
ExecuteFile "QC path"
b)by script(QCUtil object),
E.g., 'Validating If QC is connected properly:
If QCUtil.IsConnected then
msgbox “QC is connected”
Else
Msgbox “QC is not connected”
End If
'Connecting to QC through QTP:
Set qtApp = CreateObject ("QuickTest.Application")
If qtApp.launched <> True then
qtApp.Launch
End If
qtApp.Visible = "true"
If Not qtApp.TDConnection.IsConnected Then
qtApp.TDConnection.Connect QCurl, DomainName, ProjectName, UserName, Password, False
End If
' Adding Attachment to QC
Dim ObjCurrentTest,ObjAttch
Set ObjTest = QCUtil.CurrentTest.Attachments
Set ObjAttachFile = ObjTest.AddItem(Null)
ObjAttachFile.FileName = FileName
Set ObjAttachFile = ObjTest.AddItem(Null)
ObjAttachFile.FileName = FileName
‘ Provide path of the file that needs to be attached to QCObjAttachFile.Type = 1
ObjAttachFile.Post
ObjAttachFile.Refresh
ObjAttachFile.Post
ObjAttachFile.Refresh
'Adding a defect in QC using QCUtil Object:
Set QCConnection = QCUtil.QCConnection ‘Create instance of QCConnection
‘Create an instance of BugFactory
Set DefFactory = QCConnection.BugFactory
'Add a new defect
Set Bug = DefFactory.AddItem(Nothing)
‘Provide mandatory details for the defect
Bug.Status = “New”
Bug.Summary = “Module Detected new defect summary”
Bug.DetectedBy = “Auto”
Bug.AssignedTo = “001”
Bug.Post
Set DefFactory = nothing
Set QCConnection = nothing.
Ways to associate function libraries:
1) By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
2) By using Automation Object Model (AOM).
3) By using ExecuteFile method.
4) using LoadFunctionLibrary method.
Explanation:
1. Using ‘File > Settings > Resources > Associate Function Library ’ option from the Menu bar
This is the most common method used to associate a function library to a test case. To use this method, select File > Settings option from the Menu bar. This will display the ‘Test Settings’ window. Click on Resources from the left hand side pane. From the right hand side pane, click on the ‘+’ button and select the function library that needs to be associated with the test case.
2. Using AOM (Automation Object Model):
QTP AOM is a mechanism using which you can control various QTP operations from outside QTP. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.
Example:
Using the below code, you can open QTP, then open any test case and associate a required function library to that test case. To do so, copy paste the below code in a notepad and save it with a .vbs extension.
'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True
'Open a test and associate a function library to the test
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries
'If the library is not already associated with the test case, associate it..
If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added
objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case
End
3. Using ExecuteFile Method
ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file (function library) are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.
'Action begins
ExecuteFile "C:\YourFunctionLibrary.vbs"
4. Using LoadFunctionLibrary Method
LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs" 'Associate a single function library
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs" 'Associate more than 1 function libraries.
How to enable and disable smart identification using AOM?
Disable smart identification – AOM code:
Enable smart identification – AOM code:
CreateObject("QuickTest.Application").Test.Settings.Run.DisableSmartIdentification = False
Environment variables:
Environment variables are the global variables used to store and retrieve the value stored at run time.
Two Types of Environment variable:
1. Built in variables
E.g Msgbox Environment("OS")
2. User Defined variables
a.Internal
Environment.Value("Url")= "http:\\www.gmail.com"
URL=Environment.Value("Url")
Systemutil.Run "iexplore.exe",URL
User Defined variables
b. External
User defined External are the variables that we predefine in the active external environment variables file.These can be created using a list of variable-value pairs in an external file in .xml format.