QTP - Vbscript interview questions and answers
Q1 What are Virtual Objects?
Your application may contain objects that behave like standard objects but are not recognized by QTP. You can define these objects as virtual objects and map them to standard classes, such as a button or a check box. QTP emulates the user's action on the virtual object during the run session. In the test results, the virtual object is displayed as though it is a standard class object.
For example, suppose you want to record a test on a Web page containing a bitmap that the user clicks. The bitmap contains several different hyperlink areas, and each area opens a different destination page. When you record a test, the Web site matches the coordinates of the click on the bitmap and opens the destination page.
To enable QTP to click at the required coordinates during a run session, you can define a virtual object for an area of the bitmap, which includes those coordinates, and map it to the button class. When you run a test, QTP clicks the bitmap in the area defined as a virtual object so that the Web site opens the correct destination page.
Q2. How to find the length of string in QTP?
Answer -You can find the length of the string using one vb script function called len.
Suppose you want to find the length of "salunke" then you will have the below statement which will print the length of string .
print len("salunke")
Q3. How to find the current system time in QTP?
Answer - You can find the current system time using Time function in vbscript.
Print time
Q4. How to remove all spaces from given string in QTP?
Answer - We can use replace function in vbscript to remove all spaces in string.
e.g. newstring = replace(stringwithspaces," ","")
Q5. How to find the modulus of a number in QTP?
Answer - We can find the modulus of given number using MOD operator.
a = 10 mod 5
print a
Q6. How to find the size of array in QTP?
Answer - To find the size of array, we can use ubound function in QTP.
print ubound(arr) - 'prints upper bound of array.
Q7. What is the difference between byref and byval in QTP?
Answer - You can pass the parameters to function or procedure using byref or byval method.
byref will pass the address of variable but byval will pass the copy of variable. So when you want the passed value to change, you can pass the value using byref method. Otherwise you can pass it using byval method.
Q8. How to find the difference between 2 dates in QTP?
Answer - You can find the difference between 2 dates using datediff function. You can get the difference in terms of minutes, seconds, hours, months or years.
Q9. How to generate the random number in given range in QTP?
Answer:
Min = 1
Max = 10
Randomize
RandomNumber = (Int((max-min+1)*Rnd+min))
Q10. How to create an array of dictionaries in QTP?
Answer - We can create the array of dictionary like how we create array of scalar variables.
Syntax is shown below –
'Declare Array with 5 elements
Dim myArray(5)
'Make first element in array as a dictionary object
Set myArray(0) = createobject("scripting.dictionary")
'Once we have a dictionary object, We can use its methods like add, remove, removeall etc
myArray(0).Add"mykey","myvalue"
'display item value of mykey in dictionary myArray(0)
print myArray(0)("mykey")
myArray(0).removeall
Q 11. What are the types object Repositories in QTP.
QTP Supports 2 types of Object Repository
1) Shared Object Repository (also called Global)
2) Per-Action Object Repository, (also called Local)
Per-Action Object Repository is used by default. The extension for Per-Action repository is ".mtr" .
Shared Object Repository is preferable while dealing with dynamic objects which are called in multiple tests. The extension is ".tsr"
Can we call QTP test from another test using scripting. Suppose there are 4 tests and I want to call these tests in a main script. Is this possible in QTP?
Yes. You can call 4 or even more scripts in your tests.For this, first you will need to make the Actions in the corresponding scripts re-usable.Then from the destination script you can make calls to these re-usable actions.
Q 12) What is action split and the purpose of using this in QTP?
Action split is to divide an existing action into two parts.The purpose is to divide actions based on their functionality to improve code re-use.
Q 13) How will you handle Java tree in QTP ?
Foremost you will select Java Add - In and launch QTP. Next step record operations on the Java Tree. If you face an issue while recording, you can select Tools > Object Identification > Java, tree object and make changes in mandatory and assistive properties to enable identification.
Tip: You can base you answer on similar lines for any other object of any environment. For example : If the question is how will check SAP checkbox , You say , first I will select SAP Add in ... and so on.
Q 14) Explain how QTP identifies object ?
QTP identifies any GUI Object based on its corresponding properties. While recording, QTP will identify and store peculiar properties (as defined in the Object Identification settings) in the object repository of the GUI object . At run-time, QTP will compare the stored property values with the on-screen properties, to uniquely identify the GUI object.
Learn more about Object Identification
Q 15) How many types of recording modes in QTP? Which will be used when ?
QTP supports 3 types of recording modes
1. Normal mode also called Contextual
2. Low-level recording mode
3.Analog mode
Normal Mode: It is the default recording mode and takes full advantage of QTP's Test Object Model. It recognizes objects regardless of their position on -screen. This is the preferred mode of recoding and is used for most of the automation activities.
Low-level recording mode: This mode records the exact x,y co-ordinates of your mouse operations. It is helpful in testing hashmaps. It is useful for recording objects not identified by normal mode of QTP.
Analog mode: This mode records exact mouse and keyboard "movements" you perform in relation to the screen / application window. This mode is useful for the operation such as drawing a picture, recording signature., drag and drop operations.
Learn more about Recording Modes in QTP
Q 16) How will you call from one action to another action ?
We can call an action in 2 ways
1) Call to copy of Action. - In this ,the Action Object Repository , Script and Datable will be copied to the destination Test Script.
2) Call to Existing Action. - In this, Object Repository , Script and Datable will NOT be copied but a call (reference) would be made to the Action in the source script.