Datasheet Handling in Data driven Testing2 - QTP


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") 


The following example uses the DeleteParameter method to delete the parameter, "Arrival" from the "MySheet" sheet of the run-time Data Table.

DataTable.GetSheet("MySheet").DeleteParameter("Arrival")

Note that deleting a parameter from the sheet will cause the run to fail if a corresponding parameter exists in a step.

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")


The following example uses the GetCurrentRow method to retrieve the row currently being used by the run-time Data Table and writes it to the report.

row = DataTable.GetSheet("MySheet").GetCurrentRow

Reporter.ReportEvent 1, "Row Number", row 

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") 

The following example uses the GetParameterCount method to find the total number of parameters (columns) in the run-time Data Table sheet (MySheet) and writes it to the report.

paramcount = DataTable.GetSheet("MySheet").GetParameterCount

Reporter.ReportEvent 2, "There are " &paramcount, "columns in the data sheet."




The following example uses the GetRowCount method to find the total number of rows in the first column of the run-time Data Table sheet (MySheet) and writes it to the report.

rowcount = DataTable.GetSheet("MySheet").GetRowCount

Reporter.ReportEvent 2, "There are " &rowcount, "rows in the data sheet." 

The following example uses the SetCurrentRow method to change the active row to the second row in the MySheet run-time data sheet.

DataTable.GetSheet("MySheet").SetCurrentRow(2) 

The following example uses the SetNextRow method to change the active row to the next row in the run-time Data Table.

DataTable.GetSheet("MySheet").SetNextRow



The following example uses the SetPrevRow method to change the active row to the previous row in the run-time data sheet.

DataTable.GetSheet("MySheet").SetPrevRow


The following example uses the Name method to return the name of the active run-time data sheet and writes it in the report.

Sheetname = DataTable.LocalSheet.Name

Reporter.ReportEvent 1, "The Active Sheet is", Sheetname



Post a Comment

Previous Post Next Post