Wednesday, December 17, 2008

How to capture error screen-shot in Result Viewer

How to capture error screen-shot in Result Viewer

Dim path_error_file
path_error_file = "C:\Documents and Settings\Desktop\error.bmp"
Browser("Browser").CaptureBitmap path_error_file,True

Reporter.ReportEvent micFail, Object_snap,
"&"

How to capture a tool tip text of a link in QTP?

How to capture a tool tip text of a link in QTP?

This QTP tutorial shows and explains How to get tool tip in QuickTest Professional.

Actually, this is not a difficult task. The steps are:
1.Place mouse cursor over the link
2.Wait for tool tip
3.Get text of shown tool tip
This QTP script captures a text of a tool tip:
' Place mouse cursor over the link

Browser("Yahoo!").Page("Yahoo!").WebElement("text:=My Yahoo!").FireEvent "onmouseover"
wait 1
' Grab tooltip
ToolTip = Window("nativeclass:=tooltips_class32").GetROProperty("text")

Register User Function.

Register User Function

Suppose that the FindFlights Web page contained a Country edit box, and by default, the box contained the value USA. The following example registers the Set method to use the MySet function in order to report the default value of the edit box to the test results before the new value is entered. The UnRegisterUserFunc method is then used to return the Set functionality to the standard QuickTest functionality.
Function MySet (obj, x)
dim y
y = obj.GetROProperty("value")
Reporter.ReportEvent micDone, "previous value", y
MySet=obj.Set(x)
End Function
RegisterUserFunc "WebEdit", "Set", "MySet"
Browser("MercuryTours").Page("FindFlights").WebEdit("Country").Set "Canada"
UnRegisterUserFunc "WebEdit", "Set"

Automatically Add Resources to a QTP Test



Automatically Add Resources to a QTP Test


Working with external function libraries (e.g., vbs files) is a common practice among advanced QTP practitioners. This feature of QTP enables developers to encapsulate functionality that needs to be reused in the form of functions, subroutines, and even classes. It is even possible to set the currently loaded function libraries as default, and hence every new test would "inherit" these libraries as the project infrastructure. Building automated tests based upon such a robust infrastructure with such components is a highly recommended practice that makes the developer’s work highly efficient.


Nevertheless, QTP doesn’t provide a user friendly way to add such resources to a test. The Test Settings Resources Tab allows the user to add just one file at a time, hence making this a tedious task. Moreover, the list view of function libraries is cumbersome, requiring one to scroll up and down to verify the existence of a specific file, and if these disadvantages are not enough, it also does not support adding the contents of an entire folder. These shortcomings make the task of adding resources time-consuming. Because the projects I lead require the use of hundreds of such function library files, I decided to help-up my team members by automating this process. I had prepared a basic script more than a year ago for this purpose exploiting QTP automation object model (AOM.), but I wanted to improve the script to make it more generic and scalable.

To accomplish this feat I designed the process as follows:

1.Define the test you wish to configure;
2.Define the pathnames of the folders in which the function libraries are stored (can be relative paths);
3.Define whether the test resources should be emptied before adding the new ones;
4.Define whether you wish the test to run after configuration is done
5.Call the configuration script, which should do the following:
Launch QTP;
Open the required test;
Set the search folders in QTP options;
If required, remove function libraries from the test resources;
Add the function libraries located in the search folders to the test resources;
Save the test;
If required, run the test.

The mechanism is based on 4 files: QtpConfig.wsf, QtpConfig.ini, QtpConfig.bat and RunQtpConfig.bat. The mechanism assumes a standard folder structure which is, in any case, an advisable method to efficiently store the deliverables (function libraries, data files, etc.) of an automation project. The basic folder structure would be like avobe image.

Where AUT stands for Application Under Test, and the folder names are self-explanatory. This scheme enables us to store the QTP tests under the scripts folder and exploit the standard use of search folders by relative paths. In my projects I further use a similar folder structure for Common and Infra projects, which are used by all specific AUT projects. Note: QtpConfig.wsf and QtpConfig.bat are located in the Infra/scripts folder, and the attached files assume this fact for proper functioning. QtpConfig.ini just contains a variable to set the debug mode to true or false, and is located together with the previous two. RunQtpConfig.bat is located in the AUT/scripts folder.
I shall now explain the use of the three main files mentioned above (apart from the ini file which is obvious). QtpConfig.wsf is a Windows Script File written in VBScript; it does the actual QTP configuration work using QTP COM object. QtpConfig.bat is the batch file that calls QtpConfig.wsf while passing the relevant arguments. Finally, RunQtpConfig.bat is a batch file that calls QtpConfig.bat and passes the relevant arguments, which are: TestPathName, Folders, RemoveAllFirst and RunTest. These arguments instruct QtpConfig.wsf what to do and on which test, as described below:

TestPathName is the relative path of the QTP test to be configured.
Folders is a semicolon separated list of folders required to configure the search path of QTP and to find the relevant function libraries.
RemoveAllFirst is a boolean that indicates whether to remove all resources (libraries) before adding them anew.
RunTest is a boolean that indicates whether

How can i check if a parameter exists in DataTable or not?

How can i check if a parameter exists in DataTable or not?

Using the below code:

on error resume next
val=DataTable("ParamName",dtGlobalSheet)
if err.number<> 0 then
'Parameter does not exist
else
'Parameter exists
end if

How to add a constant number in a QTP datatable?

How to add a constant number in a QTP datatable?

Just append ' to the number
Ex: if you wish to enter 1234567 in datatable then write it as '1234567

A message box that will close automatically.

A message box that will close automatically.

You would just create a WScript Shell object and use the Popup method on it.

Set WshShell = CreateObject("Wscript.Shell")
WshShell.Popup "Wait 5 seconds", 5, "Title"