Compare Method

Applies to TestComplete 15.63, last modified on April 10, 2024

Description

Use the Compare method to compare the values stored in the Table project element that corresponds to the Table object with the data that is displayed in the control whose name is stored in the element’s properties (this name is returned by the ObjectName property).

Using the Compare method you can also update the data stored in the Table element. TestComplete does this if the Update Table elements option is enabled. See Modifying Table Elements.

Declaration

TableObj.Compare(ReportDifference, MessageType)

TableObj An expression, variable or parameter that specifies a reference to a Table 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:

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 Compare 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.

To compare the stored values with data of any object (rather than with the data of the object, whose name is specified by the ObjectName property), use the CompareWithObject method.

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 of an object that displays information in the tabular form.

JavaScript, JScript

function Test()
{

  var Table, ReportDifference, MessageType;
  // Obtains the Table object
  Table = Tables.OrdersTable;
  // Specifies the comparison parameters
  ReportDifference = true;
  MessageType = lmError;
  // Compares the data stored in the Table element with the data displayed by the object
  Table.Compare(ReportDifference, MessageType);

}

Python

def Test():
  # Obtains the Table object
  Table = Tables.OrdersTable
  # Specifies the comparison parameters
  ReportDifference = True
  MessageType = lmError
  # Compares the data stored in the Table element with the data displayed by the object
  Table.Compare(ReportDifference, MessageType)

VBScript

Sub Test

  Dim Table, ReportDifference, MessageType
  ' Obtains the Table object
  Set Table = Tables.OrdersTable
  ' Specifies the comparison parameters
  ReportDifference = True
  MessageType = lmError
  ' Compares data stored in the Table element with data displayed by the object
  Call Table.Compare(ReportDifference, MessageType)

End Sub

DelphiScript

procedure Test();
var Table, ReportDifference, MessageType;
begin

  // Obtains the Table object
  Table := Tables.OrdersTable;
  // Specifies the comparison parameters
  ReportDifference := true;
  MessageType := lmError;
  // Compares data stored in the Table element with data displayed by the object
  Table.Compare(ReportDifference, MessageType);

end;

C++Script, C#Script

function Test()
{

  var Table, ReportDifference, MessageType;
  // Obtains the Table object
  Table = Tables["OrdersTable"];
  // Specifies the comparison parameters
  ReportDifference = true;
  MessageType = lmError;
  // Compares data stored in the Table element with data displayed by the object
  Table["Compare"](ReportDifference, MessageType);

}

See Also

About Table Checkpoints
CompareWithObject Method
ObjectName Property
Modifying Table Elements

Highlight search results