Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Showing posts with label Datasheet handling in QTP. Show all posts
Showing posts with label Datasheet handling in QTP. Show all posts

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)

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



Datasheet Handling in Data driven Testing1 - QTP

Description

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 or properties:

  • DataTable.AddSheet  
  • DataTable.GetSheet
  • DataTable.GlobalSheet
  • DataTable.LocalSheet

    Notes:
    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.
    When working with scripted components, the name of the (single) Data Sheet is identical to the name of scripted component. If you save the scripted component with a new name, the name of the data sheet changes accordingly.

Associated Methods

  • AddParameter Method

  • DeleteParameter Method

  • GetCurrentRow Method

  • GetParameter Method

  • GetParameterCount Method

  • GetRowCount Method

  • SetCurrentRow Method

  • SetNextRow Method

  • SetPrevRow Method

Associated Properties

  • Name Property



DataTable.AddSheet(SheetName)


Argument

Type

Description

SheetName

String

Assigns a name to the new sheet.

Return Value

DTSheet Object.

Example

The following example uses the AddSheet method to create the new sheet, "MySheet" in the run-time Data Table and then adds a parameter to the new sheet.

Variable=DataTable.AddSheet ("MySheet").AddParameter("Time", "8:00") 


DataTable.GetSheet(SheetID)


Argument

Type

Description

SheetID

Variant

Identifies the sheet to be returned. The Sheet ID can be the sheet name or index. Index values begin with 1.

Return Value

DTSheet Object

Examples

The following example uses the GetSheet method to return the "MySheet" sheet of the run-time Data Table and add a parameter to it.

MyParam=DataTable.GetSheet ("MySheet").AddParameter("Time", "8:00")

You can also use this to add a parameter to the "MySheet" local sheet (note that no value is returned).

DataTable.GetSheet ("MySheet").AddParameter "Time", "8:00"

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

DataTable.GlobalSheet

Example

The following example uses the GlobalSheet property to return the global sheet of the run-time Data Table in order to add a parameter (column) to it.

ParamValue=DataTable.GlobalSheet.AddParameter("Time", "5:45")

You can also use this method to add a parameter to the global sheet (note that no value is returned).

DataTable.GlobalSheet.AddParameter "Time", "5:45"


DataTable.LocalSheet

Example

The following example uses the LocalSheet property to return the local sheet of the run-time Data Table in order to add a parameter (column) to it.