Modifying Table Elements

Applies to TestComplete 15.47, last modified on January 20, 2023

Elements of the Stores > Tables collection are used during the tests to verify data of controls that display information in a tabular form. Each collection item (the Table element) stores values and the full name of the object to be used for comparison. You can modify the element’s data by using the Table Element editor or by writing script code or keyword test.

Note: If you want to update all data stored in the Table element, you can update the element. For more information on this, see Updating Table Elements.

In the Editor

You can view and modify the element’s data using the Table Element editor.

To modify data in the editor, click the desired cell and then type a new value in the ensuing in-place editor. To confirm the change, press Enter. To discard the change, press Esc.

To specify an object, press the Edit button of the Table Element editor and use the resulting wizard.

To update data of the selected object, press Update.

For more information on working with the editor, see About Table Element Editor.

From Tests

To modify the data of Table elements from scripts or keyword tests, use methods and properties of the Table object. You can change both values and the stored object name by using them.

Note: The Table object provides scripting access to a copy of the stored data. That is, the changes that you make in tests will not be applied to values that are stored in the project and displayed in the Table Element editor. All changes will be lost after the test execution is over.

To modify the stored data, use the Table.Values property. The property uses two parameters that specify the row and of the desired cell. The following code demonstrates how you can use this property to modify the values:

JavaScript

Tables.Table1.$set("Values", 2, 0, "My new text");
Tables.Table1.$set("Values", 2, 1, 123.45);

JScript

Tables.Table1.Values(2, 0) = "My new text";
Tables.Table1.Values(2, 1) = 123.45;

Python

Tables.Table1.Values[2, 0] = "My new text"
Tables.Table1.Values[2, 1] = 123.45

VBScript

Tables.Table1.Values(2, 0) = "My new text"
Tables.Table1.Values(2, 1) = 123.45

DelphiScript

Tables.Table1.Values[2, 0] := 'My new text';
Tables.Table1.Values[2, 1] := 123.45;

C++Script, C#Script

Tables["Table1"]["Values"](2, 0) = "My new text";
Tables["Table1"]["Values"](2, 1) = 123.45;

The row and column indexes are zero-based. They coincide with the row’s and column’s position of the value in the Table Element editor. The row index is displayed in the left-most column in the editor.

The total number of stored rows is specified by the Table.RowCount property. To obtain the column index, you can also use the ColumnIndex property of the Table object. This property returns the desired column’s index by the column name.

You can specify whether a value will be used for comparison or not. To do this, use the Table.ValuesSelected property. Like Values, this property has two parameters that specify the row and column indexes of the desired value:

JavaScript

function Test()
{
  var Col1, Col2;

  // Get column indexes
  Col1 = Tables.Table1.ColumnIndex("Author");
  Col2 = Tables.Table1.ColumnIndex("Year Born");

  // Iterate through stored rows
  for(let i = 0; i < Tables.Table1.RowCount; i++)
  {
    if(Tables.Table1.Values(i, Col2) != "")
    {
      Tables.Table1.$set("ValuesSelected", i, Col1, false);
      Tables.Table1.$set("ValuesSelected", i, Col2, false);
    }
  }

  // Compare values
  if(Tables.Table1.Compare(false))
    Log.Message("OK !");
  else 
    Log.Error("Comparison failed.");
}

JScript

function Test()
{
  var Col1, Col2, i;

  // Get column indexes
  Col1 = Tables.Table1.ColumnIndex("Author");
  Col2 = Tables.Table1.ColumnIndex("Year Born");

  // Iterate through stored rows
  for(i = 0; i < Tables.Table1.RowCount; i++)
  {
    if(Tables.Table1.Values(i, Col2) != "")
    {
      Tables.Table1.ValuesSelected(i, Col1) = false 
      Tables.Table1.ValuesSelected(i, Col2) = false
    }
  }

  // Compare values
  if(Tables.Table1.Compare(false))
    Log.Message("OK !");
  else 
    Log.Error("Comparison failed.");
}

Python

def Test():
  # Get column indexes
  Col1 = Tables.Table1.ColumnIndex("Author")
  Col2 = Tables.Table1.ColumnIndex("Year Born")

  # Iterate through stored rows
  for i in range(0, Tables.Table1.RowCount):
    if Tables.Table1.Values[i, Col2] != "":
      Tables.Table1.ValuesSelected[i, Col1] = False 
      Tables.Table1.ValuesSelected[i, Col2] = False

  # Compare values
  if Tables.Table1.Compare(False):
    Log.Message("OK !")
  else:
    Log.Error("Comparison failed.")

VBScript

Sub Test
  ' Get column indexes
  Col1 = Tables.Table1.ColumnIndex("Author")
  Col2 = Tables.Table1.ColumnIndex("Year Born")

  ' Iterate through stored rows
  For i = 0 To Tables.Table1.RowCount - 1
    If Tables.Table1.Values(i, Col2) <> "" Then
      Tables.Table1.ValuesSelected(i, Col1) = False
      Tables.Table1.ValuesSelected(i, Col2) = False
    End If
  Next 

  ' Compare values
  If Tables.Table1.Compare(False) Then
    Call Log.Message("OK !")
  Else 
    Call Log.Error("Comparison failed.")
  End If
End Sub

DelphiScript

procedure Test;
var
  Col1, Col2, i : OleVariant;
begin
  // Get column indexes
  Col1 := Tables.Table1.ColumnIndex('Author');
  Col2 := Tables.Table1.ColumnIndex('Year Born');

  // Iterate through stored rows
  for i := 0 to Tables.Table1.RowCount - 1 do
  begin 
    if Tables.Table1.Values[i, Col2] <> '' then
    begin
      Tables.Table1.ValuesSelected[i, Col1] := False;
      Tables.Table1.ValuesSelected[i, Col2] := False;
    end;
  end;

  // Compare values
  if Tables.Table1.Compare(False) then
    Log.Message('OK !')
  else 
    Log.Error('Comparison failed.');
end;

C++Script, C#Script

function Test()
{
  var Col1, Col2, i;

  // Get column indexes
  Col1 = Tables["Table1"]["ColumnIndex"]("Author");
  Col2 = Tables["Table1"]["ColumnIndex"]("Year Born");

  // Iterate through stored rows
  for(i = 0; i < Tables["Table1"]["RowCount"]; i++)
  {
    if(Tables["Table1"]["Values"](i, Col2) != "")
    {
      Tables["Table1"]["ValuesSelected"](i, Col1) = false 
      Tables["Table1"]["ValuesSelected"](i, Col2) = false
    }
  }

  // Compare values
  if(Tables["Table1"]["Compare"](false))
    Log["Message"]("OK !");
  else 
    Log["Error"]("Comparison failed.");
}

You can also modify the name of the object, with which TestComplete compares the stored data. To do this, use the ObjectName property. Like changes made to values, the changes made to the object name exist only during the test run. They will not be saved to the project and displayed in the editor.

Note also that you can compare the stored values not only with the data of the object specified by the ObjectName property, but also with data of any other object. To perform this comparison, use the CompareWithObject method. For more information, see Table Checkpoints.

You can also modify the stored data from your keyword tests. To execute, for example, the code above, use the Call Object Method, Run Code Snippet or Run Script Routine operation.

See Also

About Tables Collection
About Table Checkpoints
Updating Table Elements

Highlight search results