Вы находитесь на странице: 1из 6

QTP - Vbscript interview questions and answers

Hi friends - on this page you will find all interview questions on QTP and VB script

In QTP, vbscript is used as a scripting language. 80% of programming you do in QTP is based vbscript
concepts. So There is no doubt that you will face interview questions based upon vbscript.

Q1. 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")

Q2. How to find the current system time in QTP?

Answer - You can find the current system time using Time function in vbscript.

Print time

Q3. 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," ","")

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

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

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

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

Q8. How to generate the random number in given range in QTP?

Answer:
Min = 1
Max = 10
Randomize
RandomNumber = (Int((max-min+1)*Rnd+min))

Q 9. 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 10. How Can we store array variable in dictionary in QTP?

Answer -
Dim a
a = array(2,3,4,5)
Set d = createobject("Scripting.Dictionary")
d.Add "mykey", a
print d("mykey")(0)
Q 11. What is win32 API and how to use it in QTP?
Answer -
win32 API is an API that can be used to perform different administrative tasks. It has many WIN32
classes like Win32_Process etc.

Below Example used Win32 API in QTP to close the process by its name.

'Get the WMI object


Set WMI = GetObject("winmgmts:\\localhost\root\cimv2")
'Get collection of processes for with name pname
Set allp = WMI.ExecQuery("Select * from Win32_Process Where Name = '" & pname & "'")
'Loop through each process and terminate it
For Each p in allp
p.Terminate()
Next
This is how we can use win32 API in QTP.

Here is the list of more QTP-Vbscript Interview Question


How to get xml node value in QTP`
Code below can be used to read xml node value in qtp.

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")


objXMLDoc.async = False
objXMLDoc.load("books.xml")
Set parentel= objXMLDoc.documentElement

Set cList = parentel.getElementsByTagName("book")

For Each E In cList


print E.Text
Next

This example will print all xml node values in QTP.

Difference between Executefile and execute in QTP


Difference between execute and executefile – Same only difference is execute accepts string as
argument while executefile uses file as argument
23: What are the various events available in the Recovery Scenario Manager?

1) Application Crash: This event is useful in handling crashed applications at runtime.

2) Pop Up Window: This event is useful in managing various unwanted application windows,
which get built-up at runtime.

3) Test Run Error: This event is useful in handling VBScript statement errors at runtime.

4) Object State: This event is useful in handling object related errors at runtime.

Q. 24: What are the Elements of Recovery Scenario?

Steps to handle the exceptions are

1) Trigger Event: Is an unexpected event like appearance of a Pop-up window, object


state, test run error causing application crash or interruption in our running session.

2) Recovery Steps: Constitutes a series of steps required to be performed to enable QTP


to proceed further with the process of test after some trigger event has interrupted the run
session. Examples of a recovery operation can be 1) A keyboard or mouse Operation like a
Click over the “OK” button in the Pop-up window 2) Close Application Process 3) Function
Call 4) Restarting the OS etc.
3) Post-Recovery Test Run: Are a set of instructions designed to be provided to QTP on
proceeding further with the test after some recovery operation has been carried out.
Examples of Post Recovery actions can be repeating the complete test from the beginning
or
some steps may be skipped altogether & continuing with the remaining steps in the test.

Q. 28: What are the various ways to insert a Action in a test in QTP?

There are three ways to insert an Action in a test

1. Insert Call to New…

2. Insert Call to Copy…

3. Insert Call to Existing…

Q. 42: What is the concept of Test Object Model in QTP?

QTP tests our dynamically changing application by learning and identifying test objects and
their expected properties and values. To do this, QTP analyzes each object in our application
in much the same way that a person would look at a photograph and remember its details.

The test object model is a large set of object types or classes that QTP uses to represent the
objects in our application. Each test object class has a list of properties that can uniquely
identify objects of that class and a set of relevant methods that QuickTest can learn about
it.

A test object is an object that QTP creates in the test to represent the actual object in your
application. QTP stores information on the object that will help it identify and check the
object during the run session.

A run-time object is the actual object in our application on which methods are performed
during the run session

101: What is the process of capturing visible portion of an object in QTP?

QTP captures the visible part of the specified object as a bitmap and inserts a checkpoint in
the test. QTP does not capture any part of the screen which happens to be scrolled off the
screen. We can check an area of an application as a bitmap. While creating a test, we
specify the area you want to check by selecting an object. We can check an entire object or
any area within an object.

Q. 107: How can we compare the image files in the Image Checkpoint?

We can compare the image files in the Image Checkpoint by using the Compare image
content option in the Image Checkpoint Properties dialog box. It compares the expected
image source file with the graphic of the actual image source file. If the expected and actual
images are different, QTP displays them both in the Test Results. If the images are identical,
only one graphic is displayed.

. 109: How do we compare actual cell values with the expected cell values in
Tables in QTP?.

By using the Settings tab we can compare actual cell values with the expected cell values in
tables. By using Verification type option we can compare following types of cell contents.

1) String Content: It is the default setting. It treats the cell values as strings and checks
for the exact text, while ignoring spaces. For example, 2 and 2.00 are not recognized as the
same string.

2) Numeric Content: Evaluates the content of the cell according to numeric values. For
example, 2 and 2.00 are recognized as the same number.

3) Numeric Range: Compares the content of the cell against a numeric range, where the
minimum and maximum values are any real number that we specify.

Q. 110: How can we check the location of a cell to be checked in a Column of a


table?

By the use of Identify columns option available in Cell Identification tab. This specifies the
location of the column containing the cells with which we want to compare the expected
data. This is done in two ways:

1) By position: This is the Default option. It locates cells according to the column position.
A shift in the position of the columns within the table results in a mismatch.
2) By column name: It locates cells according to the column name. A shift in the position
of the columns within the table does not result in a mismatch. This option gets enabled only
when the table contains more than one column.
. 116: What is the maximum number of rows, which can be defined in a database
in QTP?

We can specify a maximum of 32,000 rows.

Q. 119: What are the various types of XML checkpoints in QTP?

We can create three types of XML checkpoints in QTP:

1) XML Web Page / Frame Checkpoint: This checks an XML document within a Web
page or frame.

2) XML File Checkpoint: This checks a specified XML file.

3) XML Test Object Checkpoint: This checks the XML data for an object or operation.