Category: QTP

Contains article related to qtp

Visual Studio 2010 Test Vs Quick Test Professional

In this post we are going to discuss one of the fastest emerging testing tool VSTS 2010 Test Vs the market leader in testing tool Quick Test Professional.

We know Quick Test Professional is unmatched with any testing tools(In some area), but from recent past the tool has many competitors like Selenium, Test Complete etc.

Microsoft in their Visual Studio 2008 release made their first testing feature available and made everyone surprise in their next version of Visual Studio 2010 Utimate/Test edition with mind blowing testing features. But still, many companies are not turning their focus on using Testing features of Visual studio rather in use for just development.

But for past 1 year, VSTS demand in market is just pickin-up !!!

Due to some of my blog readers request, I am writing a very brief comparison of VSTS Vs QTP.

Note:- This Comparison Sheet below is an ongoing comparison, please feel free to add comments or send me a mail, I will add them up to the chart. That will be really helpful.


Please leave your comments and rate this post !!!


Karthik K.K


Quick Test Professional Vs Selenium

In this post we are going to turn our attention towards comparison of the two most popular Functional Automation testing tools Quick Test Professional and Selenium.

Both the tools are currently gaining more popularity in industry and many budding test engineers are now in dilemma in choosing tools for their projects. The below comparison doesn’t give the complete detail on choosing the tool for their project, but will give a bird eye view of the tool comparison.

Many friends who are reading use to ask me question like “Which tool is best ?”, well I have a simple answer for them “Both” , since both the tools have their own pros and cons.


Share your thoughts !!!

The above comparison discussion has brought lot of controversy among automation testing community and as per their advice, I am adding further more comparison below, but here Selenium is the clear winner

Please leave your comments to make it grow further more and I will add them in comparison chart above.

Please leave your comments and rate the post !!!

Also please mail me @ if you find this post needs any changes.

QTP Object Recognition problem with .Net 4.0

We had a serious problem for past some days in .Net object recognition using QTP 11, application which was recognized by QTP 11 was started to get unrecognized. We uninstalled our application under test (AUT) and installed it once again, but the problem still persist. We did the same for QTP 11 also.

We then found that, recently our application migrated to support .Net 4.0, hence during application installation, the 4.0 framework will get updated automatically, and it turns out to be the culprit.

Because of the .Net 4.0 framework update, the QTP which suppose to recognize .Net object is not recognizing any of them.

I then found a very interesting article written by Joe Colantonio, but the problem to fix was not fruitful. In the article Joe mentioned to install the following DLL files

  • Mercury.QTP.Agent.dll
  • Mercury.QTP.WpfAgent.dll

I tried to install the same, but the problem is, both the DLL files didn’t install in your assembly folder under c:\windows\assembly, rather it gets installed under C:\Windows\Microsoft.NET\assembly\GAC_32 and C:\Windows\Microsoft.NET\assembly\GAC_MSIL respectively.

The problem with QTP 11 is, QTP will always point to .Net Assembly under c:\windows\assembly folder, whereas our DLL files are being registered under different location of GAC, hence the fix which Joe Colantonio mentioned is not working and the same is the problem with the fix which HP has provided.

Share your thoughts !!!

Please leave your comments and rate the post !!!

Also please mail me @ if you find this post needs any modification.

Calling DLL file using DotNetFactory

Last post we saw how to call DLL file using CreateObject, well we can also use another way to call the DLL file methods in QTP using DotNetFactory.

In this post we are going to see how to call DLL file in QTP instead of registering it via COM component as we did in the previous post. We need to use another way to register DLL by using GACUTIL.

You can find the information on installing the DLL using GACUTIL from here.

I have used the same code as used in the previous post to create the Class library files which you can find from here.

Now the code for QTP looks something like this.

That’s it !!!

Calling DLL files in QTP using CreateObject

There are situations where we might need more functionality for our test framework which our QTP and Vbscript might not able to be provide us.

We know the .Net really powerful and there are lot of in-build classes, methods and properties available which we use them in C# or VB.Net, if we need to use the same in QTP, we can do so by using our very know “CreateObject” method.

There are lot of DLL files available in .Net framework once you install, you can see them of course from your assembly folder under Windows directory, which we call as GAC (Global Assembly Cache).

We can almost use all of them, if we really need them and provided we know the exact functions and parameters to pass with the function.

In this demonstration, I am going to create a simple DLL file using “Class Library” project in Visual Studio and then going to use the same DLL in QTP.

So lets get started.

Step 1

As I was saying, first we need to create a DLL file, which you can do so by using Visual Studio Class library project.

Step 2

Next create a Class say “Libs” and create a very simple  functions as shown below

Step 3

Before deploying the DLL file, all we need to do is make the DLL accessible from your QTP. This we can do so by following simple procedure.

Click on the project properties and Click on the Assembly Information from from Application Tab

Make sure that you Check the “Make assembly COM-Visible

Next go to “Build” tab and Check the “Register for COM interop” as shown

Step 4

Now build the complete project and now as you know your DLL file should have generated at your \bin\debug folder.

Step 5

The final step is to call the DLL file from QTP, all you need to write a simple code as shown below


Once you run the script, you will get the output

That’s it !!!

Please leave your comments and rate the post !!!

Also please mail me @ if you find this post needs any modification.

QTP Code Snippet

1. How to get a property of object in QTP?

Ans: There are two types of methods by which one can get the property of an object

  • GetROproperty
  • GetTOproperty

E.g. In our famous search engine you can see the search button as one shown below.

In order to know the button type, we will use the GetROproperty of the object as one shown below the code.

The type of button is “Submit”. Hence we can uniquely identify the object in a web page.

2. How does run time property can be set to an object?

Ans: There are many situations where the object changes dynamically in Applications (Web site mainly) and hence the object stored in Object repository will be different to the object available in Application.

In order to set the property for the Object during run-time we use a fascinating method available in QTP, which is SetTOProperty.

Say for Example if we are in a situation to change the Type of the above shown Google button as “Submit2” from “Submit” then we can use the code snippet as one shown.

3. How to get a particular value of text using VB Script?

Ans: For this we can use many inbuilt Functions available in VB Script, one which is most popularly used is Mid () Function.


Returns a specified number of characters from a string.



The Mid function syntax has these arguments:

Part Description
String String expression from which characters are returned. If string contains Null, Null is returned.
Start Character position in string at which the part to be taken begins. If start is greater than the number of characters in string, Mid returns a zero-length string (“”).
Length Number of characters to return. If omitted or if there are fewer than length characters in the text (including the character at start), all characters from the start position to the end of the string are returned.

E.g. If we have a web page with the Screen showing the text as 1-10 of 20

Happens mostly in list screen. If we would like to get the count of the list screen (Here its 20). Then we can use the Mid function to get the count.

Now this will return 20 as the Value. By this way we can get particular value of text.

4.How to format the date and time value?

There are many situations while we struck with formatting our Date and Time, in order to get rid of this issue; we have a common function called FormatDateTime () Function.


Returns an expression formatted as a date or time.



The FormatDateTime function syntax has these parts:

Part Description
Date Required. Date expression to be formatted.
NamedFormat Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate is used.


The NamedFormat argument has the following settings:

Constant Value Description
vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed.
vbLongDate 1 Display a date using the long date format specified in your computer’s regional settings.
vbShortDate 2 Display a date using the short date format specified in your computer’s regional settings.
vbLongTime 3 Display a time using the time format specified in your computer’s regional settings.
vbShortTime 4 Display a time using the 24-hour format (hh:mm).

E.g. If the Application returns both date and time and we needs only date not time with particular format then we can use the following function as one shown.

5. How to use Regular Expression?

Ans: Regular Expression is a wide Topic and which is out of scope for this blog, but you can find more information from site In QTP we use Regular Expression widely to identify a dynamically changing objects.

There are Totally 11 special characters used Regular Expressions, they are the opening square bracket [, the backslash , the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ). These special characters are often called “metacharacters”.


If there is any word say 1+1=2, then you can use it as in regular Expression as

1+1=2. Meaning “+” has special meaning, in order to skip the meaning we use “”

d matches a single character that is a digit,

w matches a “word character” (alphanumeric characters plus underscore), and

s matches a white space character (includes tabs and line breaks).

The actual characters matched by the shorthand depend on the software you’re using. Usually, non-English letters and numbers are included.

Real time Example

As discussed in our Question 4, the list screen Value 1-10 of 20, Which will be recognized by QTP until the value in Object Repository exactly matches with AUT (Application Under Test).

But here is the Situation were you are adding some data and the Application list screen count changes from 20 to 21, and try to run the same script, OOPs !!!!. The QTP throws Error saying, “No object found in Object repository.” Try to run in Maintenance mode!.

Hence we can change the Already recorded value of 1-10 of 20, in Object Repository with Regular Expression, since here 20 is just a digit (Numeric) we can use /d


Now the Object Repository should look like one shown below.

How to compare difference in date?

Ans: We can use simple DateDiff Function of VBScript and do it right away.

DateDiff () Function


Returns the number of intervals between two dates.


DateDiff(interval, date1date2 [,firstdayofweek[, firstweekofyear]])

The DateDiff function syntax has these parts:

Part Description
interval Required. String expression that is the interval you want to use to calculate the differences between date1 and date2. See Settings section for values.
date1, date2 Required. Date expressions. Two dates you want to use in the calculation.
firstdayofweek Optional. Constant that specifies the day of the week. If not specified, Sunday is assumed. See Settings section for values.
firstweekofyear Optional. Constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. See Settings section for values.

The interval argument can have the following values:

Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second


Let take our previous question, question 5 for its FormatDateTime() function and lets check for the Difference in time. Here we are going to check Present date using QTP’s inbuilt method date (Returns Present date) and compare it with date passed in FormatDateTime function. It its true it shows present date else it shows that its not present date.


9. How to pass parameter from one Action to another?

Ans : Before passing a parameter from one action to another we should first create a input parameter for the Action which is going to accept a value as input from another Action.

Lets take Action 2 is going to get an value from Action 1 as a parameter, then we should first create a input parameter for the Action 2. This can be done by right clicking on the Action à Action Properties à Click on Properties Tab and Click the “+” sign to create a parameter.

Now lets say I am going to pass a integer variable from Action 1 to Action 2, hence I can create a Number parameter in the input parameter of Action2.

Now the code snippet will look one like this.



a = 10

b= 20

c= a+b

RunAction “Action2”, oneIteration,c



d = 10

result = Parameter(“c”)

e = result+d


Note: Set C as input Parameter in Action2

10.How to create a procedure and pass argument to it, also explain calling a procedure?

Ans: Procedure is a collection of functionality combined to perform a common action. This procedure can be called anywhere within an action and outside the action depending upon its type. A procedure can have an Argument or many argument or even no argument which all depends upon its requirement.

Lets create a simple Procedure.


Sub <Procedure Name> (Argument 1,…. <Argument N>)

Codings …

End Sub

Sub Add (a,b)

Dim c

c = a+b

Msgbox(“The value is :” c)

End Sub

Now to call a Procedure we can use


Call <Procedure_Name> (Value to pass to argument … )

Call Add(10,10)


The Value is: 20

10.How to create a file and passing data to it using VB Script?

Ans: Creating a file using VBScript is done simply by following a code snippet given below.

‘ Create the File System Object

12.How to get local working folder of the script in QTP?

Ans: Use the given simple code snippet

This will reveal the present working directory of the Script.

13.How to traverse from data table rows and columns once imported?

Ans: Use a For Loop statement and then use the following code snippet as one given below.

14.How to Create User defined Object for Windows Application and storing it in Object Repository?

Ans: Use the following code snippets.

Please let us know if readers require any new code snippets !!!

Karthik KK

QTP Now Supports Firefox 4,5,6,7,8

HP released the most awaited patch for QTP 11 with Firefox support, now QTP support almost latest version of Firefox till 8.0

But since there is a release for Firefox 9.0 happened, HP will still wait to release one more patch for Firefox 9 support, since Firefox will soon release 10 to 12 in next few months

Here is the QTP patch QTPWEB_00090.

You can download the same from ExecuteAutomation web site itself from here


Karthik KK