Implementing Support for Table Checkpoints and Output Values in the .NET DLL Custom Server

By adding table checkpoints to a test, UFT users can check the content and properties of tables displayed in their application. By adding table output value steps to a test, you can retrieve values from a table, store them, and then use them as input at a different stage in the run session.

With .NET Add-in Extensibility, you can enable UFT to support table checkpoints and output values for custom table (grid) controls.

To implement table checkpoint and output value support, add a verification class in your Custom Server that inherits from the VerificationServerBase class and override the necessary methods (for more information, see below). In the .NET Add-in Extensibility configuration file, map each custom table control to an SwfTable test object, and to the verification class in the relevant Custom Server. For information on the syntax of the verification class methods, see the API Reference.

Note: When creating a Custom Server using the UFT Custom Server Settings wizard, the source code created by the wizard does not include commented code for table checkpoint and output value support. Add the implementation manually.

To implement support for table checkpoints and output values on custom table objects:

  1. Map the custom table control to the SwfTable test object class. This instructs UFT to use an SwfTable test object to represent the custom table control in GUI tests or components.

    In the .NET Add-in Extensibility configuration file, <UFT Installation folder>\dat\SwfConfig.xml, create a Control element with a Type attribute set to the name of the custom table control, and the MappedTo attribute set to SwfTable.

    For more information on the SwfConfig.xml file, see Understanding How to Configure UFT Windows Forms Extensibility and the .NET Add-in Extensibility Configuration Schema Help.

  2. Specify table verification configuration information for the Custom Server of this custom table control.

    In the same SwfConfig.xml file, define a CustomVerify element. In this element, specify:

    • The run-time context, which for this element must always be AUT.

    • The name of the Custom Server (DLL) that contains the implementation of table checkpoint and output value support for this control.

    • The type name for the verification class within the Custom Server (DLL) including wrapping namespaces.

    A sample of the CustomVerify element is provided below:

    <Control Type="System.Windows.Forms.DataGridView"  MappedTo="SwfTable">
            <CustomRecord>
            ...
            ...
            </CustomRecord>
            <CustomReplay>
            ...
            ...
            </CustomReplay>
            <CustomVerify>
                 <Context>AUT</Context> 
                 <DllName>C:\MyProducts\Bin\\VfySrv.dll</DllName> 
                 <TypeName>VfySrv.DataGridCPSrv</TypeName> 
            </CustomVerify>
            <Settings>
    </Control>
    
  3. In the verification class, override the following protected methods so that UFT receives what it requires when supporting table checkpoints and output values.

    • GetTableData

      UFT calls this method to retrieve table data from the specified range of rows and returns the data as an array of objects.

      When working with a table checkpoint or output value, UFT calls the GetTableRowRange method before this method so that the first and last rows in the data range of the table are known to the GetTableData method.

    • GetTableRowRange

      UFT calls this method to retrieve the number and range of rows in the table that will be included in the checkpoint or output value.

      When working with a table checkpoint or output value, UFT calls this method before the GetTableData method. The GetTableRowRange method initializes the values of the first and last rows in the data range of the table, which the GetTableData method uses as input.

    • GetTableColNames

      UFT calls this method to retrieve the column names as an array of strings. UFT displays these column names in the Table Checkpoint Properties and Table Output Value Properties dialog boxes. If this method is not implemented, numbers appear instead of column names in these dialog boxes.

      The images below shows what the Table Checkpoint Properties dialog box looks like with and without GetTableColNames implementation:

The following sample (written in C#) demonstrates implementation of the GetTableData, GetTableColNames, and GetTableRowRange methods.

using System;
using System.Collections.Generic;
using System.Text;
using Mercury.QTP.CustomServer;
using System.Windows.Forms;
namespace VfySrv
{
   public class DataGridCPSrv : VerificationServerBase
    {
    /// GetTableData() is called by UFT to retrieve the data in a table.
    /// The following base class properties are used:
    ///    SourceControl - Reference to the grid (table) object
    ///    FirstRow - The (zero-based) row number of the start of 
    ///               the checkpoint or output value
    ///    LastRow - The (zero-based) row number of the end of 
    ///              the checkpoint or output value
    /// Returns a two-dimensional array of objects.
    protected override object[,] GetTableData()
     {
       DataGridView GridView = (DataGridView)(base.SourceControl);
       int TotalRows = GridView.Rows.Count;
       int TotalColumns = GridView.Columns.Count;
       int FirstRowN = base.FirstRow;
       int LastRowN = base.LastRow;
       TotalRows = LastRowN - FirstRown + 1;
       object[,] Data = new object[TotalRows, TotalColumns];
       DataGridViewRowCollection Rows = GridView.Rows;
         for (int i = FirstRowN; i <= LastRowN; i++)
          {
           DataGridViewRow Row = Rows[i];
           DataGridViewCellCollection Cells = Row.Cells;
           for (int k = 0; k < TotalColumns; k++)
            {
             Data[i - FirstRown, k] = Cells[k].Value;
            }
          }
         return Data;
      }

      /// GetTableColNames is called by UFT to 
      /// retrieve the column names of the table. 
      /// Returns an array of column names.
      protected override string[] GetTableColNames()
       {
         DataGridView GridView = (DataGridView)(this.SourceControl);
         int TotalColumns = GridView.Columns.Count;
         string[] ColNames = new string[TotalColumns];
         for (int i = 0; i < TotalColumns; i++)
          {
            ColNames[i] = GridView.Columns[i].HeaderText;
          }
         return ColNames;
       }

      /// GetTableRowRange is called by UFT to 
      /// obtain the number of rows in the table. 
      protected override void GetTableRowRange 
                (out int FirstVisible, out int LastVisible, out int Total)
       {
         DataGridView GridView = (DataGridView)(this.SourceControl);
         DataGridViewRowCollection Rows = GridView.Rows;
         FirstVisible = -1;
         LastVisible = Rows.Count -1;
         for (int i = 0; i < Rows.Count; i++)
          {
            if (Rows[i].Visible == false)
              continue;
            FirstVisible = i;
            break;
          }
         for (int i = FirstVisible + 1; i < Rows.Count; i++)
          {
            if (Rows[i].Visible)
               continue;
            LastVisible = i;
            break;
          }
         FirstVisible++;
         LastVisible++;
         Total = GridView.Rows.Count;
      }
   }
}