CompareWithObject Method

Applies to TestComplete 14.70, last modified on April 22, 2021

Description

Use the CompareWithObject method to compare the values stored in the Table project element that corresponds to the Table object with the values displayed by the specified control.

Using the CompareWithObject method you can also update the data stored in the Table element. TestComplete does this if the Update Table elements option is enabled. The method retrieves data from the specified object and saves them to the Table project element. See Modifying Table Elements.

Declaration

TableObj.CompareWithObject(ValueReportDifferenceMessageType)

TableObj An expression, variable or parameter that specifies a reference to a Table object
Value [in]    Required    A tested object    
ReportDifference [in]    Optional    Boolean Default value: True   
MessageType [in]    Optional    Variant Default value: lmWarning   
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Value

Specifies the scripting object representing the control that displays data in a tabular form and are supported by TestComplete. For information on supported controls, see About Tables Collection.

ReportDifference

Specifies whether the method should log each difference in the tables in case the comparison fails.

MessageType

The type of message to be posted to the test log in case the comparison fails and ReportDifference is True. Possible values:

Constant Value Description
lmNone 0 Do not post any message.
lmMessage 1 Post an informative message.
lmWarning 2 Post a warning message.
lmError 3 Post an error message.

Result Value

True, if the comparison is successful and False otherwise.

Also True if TestComplete has updated the stored Table element.

Remarks

The CompareWithObject method returns True or False and also posts a message to the test log indicating the comparison result. By default, the method logs each difference found during the comparison. If there are several differences, the method will post several log messages. To specify the message type - warning, error or informational message - use the MessageType parameter. To disable failure logging, set the method’s ReportDifference parameter to False.

For sample code and information about comparison specifics, see About Table Checkpoints.

Example

The following example demonstrates how to compare data stored in the Table element with data displayed by the specified control.

JavaScript, JScript

function Test()
{
  var Table, TestObject, ReportDifference, MessageType;
  // Obtains the Table object
  Table = Tables.OrdersTable;
  // Obtains the control that displays data in the tabular form
  TestObject = Aliases.Orders.MainForm.OrdersView;
  // Sets comparison properties
  ReportDifference = true;
  MessageType = lmError;
  // Compares data stored by the Table object with data displayed by the specified control
  Table.CompareWithObject(TestObject, ReportDifference, MessageType);
}

Python

def Test():
  # Obtains the Table object
  Table = Tables.OrdersTable
  # Obtains the control that displays data in the tabular form
  TestObject = Aliases.Orders.MainForm.OrdersView
  # Sets comparison properties
  ReportDifference = True
  MessageType = lmError
  # Compares data stored by the Table object with data displayed by the specified control
  Table.CompareWithObject(TestObject, ReportDifference, MessageType)

VBScript

Sub Test

  Dim Table, TestObject, ReportDifference, MessageType
  ' Obtains the Table object
  Set Table = Tables.OrdersTable
  ' Obtains the control that displays data in the tabular form
  Set TestObject = Aliases.Orders.MainForm.OrdersView
  ' Sets comparison properties
  ReportDifference = True
  MessageType = lmError
  ' Compares data stored by the Table object with data displayed by the specified control
  Call Table.CompareWithObject(TestObject, ReportDifference, MessageType)
End Sub

DelphiScript

procedure Test();
var Table, TestObject, ReportDifference, MessageType;
begin
  // Obtains the Table object
  Table := Tables.OrdersTable;
  // Obtains the control that displays data in the tabular form
  TestObject := Aliases.Orders.MainForm.OrdersView;
  // Sets comparison properties
  ReportDifference := true;
  MessageType := lmError;
  // Compares data stored by the Table object with data displayed by the specified control
  Table.CompareWithObject(TestObject, ReportDifference, MessageType);
end;

C++Script, C#Script

function Test()
{
  var Table, TestObject, ReportDifference, MessageType;
  // Obtains the Table object
  Table = Tables["OrdersTable"];
  // Obtains the control that displays data in the tabular form
  TestObject = Aliases["Orders"]["MainForm"]["OrdersView"];
  // Sets comparison properties
  ReportDifference = true;
  MessageType = lmError;
  // Compares data stored by the Table object with data displayed by the specified control
  Table["CompareWithObject"](TestObject, ReportDifference, MessageType);
}

See Also

About Table Checkpoints
Compare Method
Modifying Table Elements

Highlight search results