ColumnByName Property

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use the ColumnByName property to get a column of the table describing the test log data scheme by the column’s name. You can then use the resulting LogColumn object to learn the type of values the column stores.

You can also obtain the desired column by its index using the Column property. To get the total number of columns in the table, use the ColumnCount property.

Declaration

LogTableDataSchemeObj.ColumnByName(AName)

Read-Only Property A LogColumn object
LogTableDataSchemeObj An expression, variable or parameter that specifies a reference to a LogTableDataScheme object
AName [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

AName

The name of the desired column. This is the same string that you see in the column header of the test log.

Property Value

A LogColumn object corresponding to the desired table column.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the ColumnByName property in square brackets: ColumnByName[AName].

Example

The code below demonstrates how you can get information about a log column using the LogTableDataScheme object. The Main routine gets the first test log of the current project and calls the GetColumnData routine that checks the type of data the log’s Message column stores.

In order for the code to run successfully, there must be at least one test log in your project.

JavaScript, JScript

function Main()
{
  // Get a collection of project's logs
  var LogsCol = Project.Logs;

  if (LogsCol != null && LogsCol.LogItemsCount > 0)
  {
    // Get the first log item
    var LogItem = LogsCol.LogItem(0);

    // Obtain the first dataset
    // of the specified log item
    var LogData = LogItem.Data(0);

    // Obtain the scheme of the dataset
    var Sch = LogData.Scheme;

    // Obtain information about the "Message" column
    var columnName = "Message";
    GetColumnData(Sch, columnName);
  }
  else
  {
    Log.Message("The current project does not contain any test logs.");
  }

}

function GetColumnData(scheme, columnName)
{
  // Check if the data set scheme contains any columns
  if (scheme != null && scheme.ColumnCount > 0)
  {
    for(var i = 0; i < scheme.ColumnCount; i++)
    {
      // Check if the data scheme contains the column with the specified name
      if (scheme.Column(i).Name == columnName)
      {
        // Get the data type of the column with the specified name
        GetColumnDataType(scheme.ColumnByName(columnName));
        return;
      }

    }
    Log.Message("No column with the name " + columnName + " was found.");
  }
  else
  {
    Log.Message("No column was found");
  }
}

// Get the data type of the column with the specified name
function GetColumnDataType(aColumn)
{
  if (aColumn != null)
  {
    if (aColumn.DataType != null)
    {
      Log.Message("The " + aColumn.Name + " column contains the following data:");
      switch (aColumn.DataType)
      {
        case ctInteger:
        {
          Log.Message("integer numbers");
          break;
        }
        case ctString:
        {
          Log.Message("strings");
          break;
        }
        case ctFloat:
        {
          Log.Message("floating-point numbers");
          break;
        }
        case ctBoolean:
        {
          Log.Message("boolean values");
          break;
        }
        case ctImage:
        {
          Log.Message("images");
          break;
        }
        case ctHyperlink:
        {
          Log.Message("hyperlinks");
          break;
        }
        case ctDateTime:
        {
          Log.Message("date or time values");
          break;
        }
      }
    }
  }
}

Python

def Main():
  # Get a collection of project's logs
  LogsCol = Project.Logs
  
  if (LogsCol != None and LogsCol.LogItemsCount > 0):
    # Get the first log item
    LogItem = LogsCol.LogItem[0]
  
    # Obtains the first dataset
    # of the specified log item
    LogData = LogItem.Data[0]
  
    # Obtains the scheme of the dataset
    Sch = LogData.Scheme
 
    # Obtains information about the "Message" column
    columnName = "Message"
    GetColumnData(Sch, columnName)

  else:
   Log.Message("The current project does not contain any test logs.")
  
def GetColumnData(scheme, columnName):
 # Check if the data set scheme contains any columns
 if (scheme != None and scheme.ColumnCount > 0):
   for i in range (0, scheme.ColumnCount - 1):
     if (scheme.Column[i].Name == columnName):
        # Get the data type of the column with the specified name
        GetColumnDataType(scheme.ColumnByName[columnName])
        return
   Log.Message("No column with name " + columnName + " was found.")
 else:
   Log.Message("No column found");

# Get the data type of the column with the specified name
def GetColumnDataType(aColumn):
  if (aColumn != None):
    if (aColumn.DataType != None):
      Log.Message("The " + aColumn.Name + " column contains the following data:")
      if aColumn.DataType == ctInteger:
        Log.Message("integer numbers")
      elif aColumn.DataType == ctString:
        Log.Message("strings");
      elif aColumn.DataType == ctFloat:
       Log.Message("floating-point numbers");
      elif aColumn.DataType == ctBoolean:
       Log.Message("boolean values");
      elif aColumn.DataType == ctImage:
       Log.Message("images");
      elif aColumn.DataType == ctHyperlink:
       Log.Message("hyperlinks");
      elif aColumn.DataType == ctDateTime:
       Log.Message("date or time values");

VBScript

Sub Main
  ' Get a collection of project's logs
  Set LogsCol = Project.Logs

  If Not LogsCol Is Nothing And LogsCol.LogItemsCount > 0 Then
    ' Get the first log item
    Set LogItem = LogsCol.LogItem(0)

    ' Obtain the first dataset
    ' of the specified log item
    Set LogData = LogItem.Data(0)

    ' Obtain the scheme of the dataset
    Set Sch = LogData.Scheme

    ' Obtain information about the "Message" column
    columnName = "Message"
    Call GetColumnData(Sch, columnName)
  Else
    Log.Message("The current project does not contain any test logs.")
  End If

End Sub

Sub GetColumnData(scheme, columnName)
  ' Check if the data set scheme contains any columns
  If Not scheme Is Nothing And scheme.ColumnCount > 0 Then
    For i = 0 To scheme.ColumnCount - 1
      ' Check if the data scheme contains the column with the specified name
      If scheme.Column(i).Name = columnName Then
        ' Get the data type of the column with the specified name
        GetColumnDataType(scheme.ColumnByName(columnName))
        Exit Sub
      End If

    Next
    Log.Message("No column with the name " & columnName & " was found.")
  Else
    Log.Message("No column was found")
  End If
End Sub

' Get the data type of the column with the specified name
Sub GetColumnDataType(aColumn)
  If Not aColumn Is Nothing Then
    If Not aColumn.DataType = aqObject.EmptyVariant Then
      Log.Message("The " & aColumn.Name & " column contains the following data:")
      Select case aColumn.DataType
        case ctInteger: Log.Message("integer numbers")
        case ctString: Log.Message("strings")
        case ctFloat: Log.Message("floating-point numbers")
        case ctBoolean: Log.Message("boolean values")
        case ctImage: Log.Message("images")
        case ctHyperlink: Log.Message("hyperlinks")
        case ctDateTime: Log.Message("date or time values")
      End Select
    End If
  End If
End Sub

DelphiScript

// Get the data type of the column with the specified name
procedure GetColumnDataType(aColumn);
begin
  if aColumn <> nil then
  begin
    if aColumn.DataType <> nil then
    begin
      Log.Message('The ' + aColumn.Name + ' column contains the following data:');
      case aColumn.DataType of
        ctInteger: Log.Message('integer numbers');
        ctString: Log.Message('strings');
        ctFloat: Log.Message('floating-point numbers');
        ctBoolean: Log.Message('boolean values');
        ctImage: Log.Message('images');
        ctHyperlink: Log.Message('hyperlinks');
        ctDateTime: Log.Message('date or time values');
      end;
    end;
  end;
end;
procedure GetColumnData(scheme, columnName);
var i;
begin
  // Check if the data set scheme contains any columns
  if ((scheme <> nil) and (scheme.ColumnCount > 0)) then
  begin
    for i := 0 to scheme.ColumnCount - 1 do
    begin
      // Check if the data scheme contains the column with the specified name
      if scheme.Column(i).Name = columnName then
      begin
        // Get the data type of the column with the specified name
        GetColumnDataType(scheme.ColumnByName(columnName));
        exit;
      end;

    end;
    Log.Message('No column with the name ' + columnName + ' was found.');
  end
  else
    Log.Message('No column was found');
end;

procedure Main();
var LogsCol, LogItem, LogData, Sch, columnName;
begin  // Get a collection of project's logs
  LogsCol := Project.Logs;

  if ((LogsCol <> nil) and (LogsCol.LogItemsCount > 0)) then
  begin
    // Get the first log item
    LogItem := LogsCol.LogItem(0);

    // Obtain the first dataset
    // of the specified log item
    LogData := LogItem.Data(0);

    // Obtain the scheme of the dataset
    Sch := LogData.Scheme;

    // Obtain information about the 'Message' column
    columnName := 'Message';
    GetColumnData(Sch, columnName);
  end
  else
    Log.Message('The current project does not contain any test logs.');

end;

C++Script, C#Script

function Main()
{
  // Get a collection of project's logs
  var LogsCol = Project["Logs"];

  if (LogsCol != null && LogsCol["LogItemsCount"] > 0)
  {
    // Get the first log item
    var LogItem = LogsCol["LogItem"](0);

    // Obtain the first dataset
    // of the specified log item
    var LogData = LogItem["Data"](0);

    // Obtain the scheme of the dataset
    var Sch = LogData["Scheme"];

    // Obtain information about the "Message" column
    var columnName = "Message";
    GetColumnData(Sch, columnName);
  }
  else
  {
    Log["Message"]("The current project does not contain any test logs.");
  }

}

function GetColumnData(scheme, columnName)
{
  // Check if the data set scheme contains any columns
  if (scheme != null && scheme["ColumnCount"] > 0)
  {
    for(var i = 0; i > scheme["ColumnCount"]; i++)
    {
      // Check if the data scheme contains the column with the specified name
      if (scheme["Column"](i)["Name"] == columnName)
      {
        // Get the data type of the column with the specified name
        GetColumnDataType(scheme["ColumnByName"](columnName));
        return;
      }

    }
    Log["Message"]("No column with the name " + columnName + " was found.");
  }
  else
  {
    Log["Message"]("No column was found");
  }
}

// Get the data type of the column with the specified name
function GetColumnDataType(aColumn)
{
  if (aColumn != null)
  {
    if (aColumn["DataType"] != null)
    {
      Log.Message("The " + aColumn.Name + " column contains the following data:");
      switch (aColumn["DataType"])
      {
        case ctInteger:
        {
          Log["Message"]("integer numbers");
          break;
        }
        case ctString:
        {
          Log["Message"]("strings");
          break;
        }
        case ctFloat:
        {
          Log["Message"]("floating-point numbers");
          break;
        }
        case ctBoolean:
        {
          Log["Message"]("boolean values");
          break;
        }
        case ctImage:
        {
          Log["Message"]("images");
          break;
        }
        case ctHyperlink:
        {
          Log["Message"]("hyperlinks");
          break;
        }
        case ctDateTime:
        {
          Log["Message"]("date or time values");
          break;
        }
      }
    }
  }
}

See Also

Access Test Log Contents from Tests
Column Property
ColumnCount Property
LogColumn Object

Highlight search results