Compare Method

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

Description

Use the Compare method to perform verification actions specified by properties of the WebAccessibility project element that corresponds to the WebAccessibility object. If all of the verifications pass, the method returns True and posts a success message to the test log. Otherwise, it returns False and, by default, logs the found differences. You can control the failure logging using the ReportDifference and MessageType parameters.

Declaration

WebAccessibilityObj.Compare(PageObjectReportDifferenceTimeoutMessageType)

WebAccessibilityObj An expression, variable or parameter that specifies a reference to a WebAccessibility object
PageObject [in]    Optional    A Page object Default value: The Page object that is specified in the corresponding Web Accessibility project element   
ReportDifference [in]    Optional    Boolean Default value: True   
Timeout [in]    Optional    Integer Default value: -1   
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:

PageObject

Specifies the Page object, over which verification operations will be performed. If this parameter is not specified, TestComplete uses the Page object that is specified in the corresponding Web Accessibility project element.

ReportDifference

If this parameter is True (default) and verification fails, the method posts warning messages about failed verifications to the test log (one message per failed verification). If this parameter is False, the method does not post any messages to the log.

Timeout

The Timeout parameter is ignored. It is reserved for future implementation.

MessageType

The type of message to be posted to the test log in case the verification 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 verification succeeds and False otherwise.

Remarks

The method verifies elements of the specified web page according to the properties of the appropriate Web Accessibility project element. For more information on these actions, see About Web Accessibility Checkpoints.

You can also use the Check method for comparison. This method has fewer parameters than the Compare method does, so it is easier to use.

Example

The following code obtains the web page stored as the Web Accessibility project element and verifies it. If the verification fails, it posts a warning message to the test log.

JavaScript, JScript

function WebAccessibilityCompare()
{

  var WebObject, Page;

  // Launches the browser and obtains the page you want to verify
  …

  // Obtains the WebAccessibility object
  WebObject = WebTesting.WebAccessibility1;

  // Checks the web page
  // If the verification fails, posts a warning message to the test log
  WebObject.Compare(Page, true, 1000, lmWarning);

  …

}

Python

def WebAccessibilityCompare():
  # Launches the browser and obtains the page you want to verify
  # ... 
  # Obtains the WebAccessibility object
  Page = Aliases.Browser.Page("*")
  WebObject = WebTesting.WebAccessibility1
  # Checks the web page
  # If the verification fails, posts a warning message to the test log
  WebObject.Compare(Page, True, 1000, lmWarning)
  # ...

VBScript

Sub WebAccessibilityCompare

  Dim WebObject, Page

  ' Launches the browser and obtains the page you want to verify
  …

  ' Obtains the WebAccessibility object
  Set WebObject = WebTesting.WebAccessibility1

  ' Checks the web page
  ' If the verification fails, posts a warning message to the test log
  Call WebObject.Compare(Page, True, 1000, lmWarning)

  …

End Sub

DelphiScript

procedure WebAccessibilityCompare();
var WebObject, Page;
begin

  // Launches the browser and obtains the page you want to verify
  …

  // Obtains the WebAccessibility object
  WebObject := WebTesting.WebAccessibility1;

  // Checks the web page
  // If the verification fails, posts a warning message to the test log
  WebObject.Compare(Page, true, 1000, lmWarning);

  …

end;

C++Script, C#Script

function WebAccessibilityCompare()
{

  var WebObject, Page;

  // Launches the browser and obtains the page you want to verify
  …

  // Obtains the WebAccessibility object
  WebObject = WebTesting["WebAccessibility1"];

  // Checks the web page
  // If the verification fails, posts a warning message to the test log
  WebObject["Compare"](Page, true, 1000, lmWarning);

  …

}

See Also

About Web Accessibility Checkpoints
Check Method

Highlight search results