Friday, September 30, 2011

Input/Out put Parameters:

Input/Out put Parameters:

One can pass number of values in to the function while calling and a function can return only one value.

Example:

Function add(a,b) Main program
Res= a+b Add(10,20)
Add= res Msg box var
End function



Input/Output parameters concept is used for passing some values in to the action to return some values once the execution is finish
To do the same one has to declare the desired number of input parameters and out put parameters at the action, which is about to be called

Navigation:
• Activate the menu item test
• Select the option action properties
• Select the parameters tab
• Declare the desired number of input/output parameters
• Using the corresponding add buttons
• Click on OK

Exmaple:
vbwindow("Form1").VbEdit ("val1").set parameter ("a")
vbwindow("Form1").VbEdit("val2").Set parameter ("b")
vbwindow("Form1").VbButton("ADD").Click
var= vbwindow("Form1").VbEdit("res").GetROProperty "text"
parameter ("c")= var
vbwindow("Form1").Vbbutton("SUB").Click
var1=vbwindow("Form1").VbEdit("res").GetROProperty "textA"
parameter ("d")=var1
vbwindow("Form1").VbButton("CLEAR").Click

At the calling point one need to specify the input values in a sequence separated by commas and the variable names in a sequence in order to catch the return value

Example:Take the new test

Run action "action1[inout122]", one iteration,20,30,r1,r2
msg box r1
msg box r2

DataTable Methods

QTP is having a powerful utility that is DataTable.It is normally used to enter the test data into the QTP script during script execution.
The following are some data table methods and their descriprions with examples.

Data table methods:

Data table methods are used for performing the operations on the runtime data table

1. Add- sheet: It is used for adding the new sheet for the runtime data table
SYNTAX: Data table.add sheet ”sheet name”

2. Delete- sheet: It is used for deleting a specified sheet from the run time data table
SYNTAX: Data table.delete sheet”sheet name”

3. Import: It is used for importing the data present in all the sheets in an excel file to the runtime data table
SYNTAX: Data table.import ”path of the excel file”

4. Import Sheet: It is used for importing specified sheet of data from the excel file to the specified sheet in the runtime data table
SYNTAX: Data table. Import sheet “path of the excel file, source sheet id, destination sheet id”

5. Export: It is used for exporting the complete data present in the run time data table to a specified location
SYNTAX: Data table. export “Path of the location with a file name.xls extension”

6.Export Sheet: It is used for exporting the data present in a specified sheet in the run time data table to a specified location
SYNTAX: Data table .export sheet “path of the location with a file name.xls extension”, sheet id to be exported.

7. Set currant row: It is used for making the QTP focus on a specified row
SYNTAX: Data table. Set currant row (row number)

8. Set next row: It is used for making the QTP focused on the next of the currently focused row
SYNTAX: Data table. Set next row

9.Set Prev Row: It is used for making the QTP focus on the previous row of the currently focused tow
SYNTAX: Data table. Set prev row

10. Value Method: It is used for getting a value from a specified sheet, specified column and currently focused row.
SYNTAX: Variable= Data Table. Value ( “column name”, sheet id)

11. Get Sheet: It is used for making the QTP to focus on a specified sheet
SYNTAX: Data table. Get sheet (sheet id)

12 Get Row Count: It is used for getting the row count of a global sheet
If at all one wants to get the row count of a specified sheet first of all they need to make the QTP to focus on a specified sheet and then get the row count
SYNTAX 1: Variable= Data Table. Get row count
SYNTAX 2: Variable= Data Table. Get sheet (“sheet id”). Get row count

Example:
DataTable.Addsheet “Alok”
DataTable.Importsheet “e:\Alok\td122.xls,1,3
N=Datatable.Getsheet( 3).getrowcount
For i= 1 to n
Data table. Setcurrantrow( i )
Vbwindow(“form1”).vbedit(“val1”).set datatable(“v1”,3)
Vbwindow(“form1).vbedit(‘val2’).set datatable(“v2”,3)
Vbwindow(”form1”).vbbutton(“add”).click
Expval= Datatable.value(“ev”,3)
Actval= vbwindow(“form1”).vbedit(“res”).getroproperty(“text”)
If (Expval= Actval) then
Datatable (“res”,3)= “pass”
Else
Datatable (“res”,3)= “fail”
End if
Next
Datatable.Export sheet “D;\fl_automation\log\file2.xls”,3
Datatable.Delete “Alok”