Datasheet Handling in Data driven Testing4 - QTP

QTP Datadriven testing : Parameter in Datasheet programming :

A parameter (column) in a sheet in the run-time Data Table. This object is not a built-in utility object, but can be accessed using one of the following methods:

    * DTSheet.AddParameter
    * DTSheet.GetParameter

      Note: All methods performed on this object apply to the run-time DataTable object only. Changes to the run-time DataTable object are reflected in the test results, but the design-time Data Table is not affected.

Associated Properties

    * Name Property
    * RawValue Property
    * Value Property
    * ValueByRow Property

Example:AddParameter

The following example uses the AddParameter method to create the new Parameter, "Arrival" within the new sheet, MySheet of the run-time Data Table, and sets the first cell in the column as "New York". Because the method also returns the newly created parameter, it is possible to use methods or check properties of the new sheet within the same statement.

ParamName=DataTable.AddSheet("MySheet").AddParameter("Arrival", "New York").Name

Note that if a parameter with the name "Arrival" already exists in the sheet, the example above will return "Arrival1" as the actual name assigned to the new parameter.

The example below performs the equivalent of renaming a column (parameter) in the DataTable by copying the data from one column to a new column with a new name, and then deleting the old column.

'add a new column
DataTable.GetSheet("dtGlobalSheet").AddParameter "NewColumn","Row1Value"

'copy the cells from the old column into the new column
cnt=DataTable.GetRowCount
For i=1 to cnt
       DataTable.SetCurrentRow(i)
       OldVal=DataTable.Value("OldColumn","dtGlobalSheet")
       DataTable.Value("NewColumn","dtGlobalSheet")=OldVal
Next

'delete the old column
DataTable.GetSheet("dtGlobalSheet").DeleteParameter("OldColumn")

GetParameter  Example

The following example uses the GetParameter method to return the "Destination" parameter from the run-time Data Table sheet: MySheet.

DataTable.GetSheet("MySheet").GetParameter("Destination")

Name  Example

The following example uses the Name method to return the name of the newly created parameter in the run-time Data Table and writes it in the report.

Dim paramname

paramname = DataTable.LocalSheet.AddParameter("Food", "pizza").Name

Reporter.ReportEvent 1, "The New Parameter name is", paramname

RawValue  Example

The following example uses the RawValue property to find the formula used in the current row of the Date column in the ActionA sheet of the run-time Data Table. The statement below returns the value: =NOW()

FormulaVal=DataTable.GetSheet("ActionA").GetParameter("Date").RawValue

Value Example

The following example uses the Value property to set the value in the current row of the Destination parameter (column) in the "ActionA" sheet of the run-time Data Table.

DataTable.GetSheet("ActionA").GetParameter("Destination").Value="New York"

Note: You could omit the word Value in the statement above, because Value is the default property for the DTParameter object.

Example ValueByRow

The following example uses the ValueByRow property to find the value in the 4th row of the Destination parameter (column) in the "ActionA" sheet of the run-time Data Table.

DataTable.GetSheet("ActionA").GetParameter("Destination").ValueByRow(4)

Post a Comment

Previous Post Next Post