Sunday, October 11, 2009

QTP Script: Checking if Datatable Parameter exists

In my previous article of Checking if a Data Table Sheet exists, I have shown a QTP script which checks if a sheet exists or not in your Datatable. Today, I am going to show you how to check if a parameter exists or not in your DataTable.

The algorithm goes here:

Step I : Use the On Error Resume Next statement to disable any error popups.
Step II : Use the DataTable's GetSheet method to return the specified sheet. Then add the GetParameter method to seach for the parameter. The following syntax should be used:
DataTable.GetSheet("Your Sheet").GetParameter(" Your Parameter")
Step III : Check for an error number using Err.Number. If case of no error, Err.Number should return 0.

With the above algorithm, our QTP Script goes here:

'Disable Error Reporting in QTP
On Error Resume Next

'Check for the existence of "Global" sheet inside QTP. Then search for "HPQTP" parameter inside "Global" sheet

If Err.Number<>0 Then
Msgbox "The specified parameter does not exists"
Msgbox "The specified parameter exists"
End If

'Enable Error Reporting in QTP
On Error Goto 0

Click here to see the script for Checking if Data table sheet exists