Compare Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Use the Compare method to compare the specified web page with the HTML document stored in the WebComparison project element that corresponds to the WebComparison object. If the verification passes, 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.

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

Declaration

WebComparisonObj.Compare(PageObject, ReportDifference, Timeout, MessageType)

WebComparisonObj An expression, variable or parameter that specifies a reference to a WebComparison object
PageObject [in]    Optional    A Page object Default value: The Page object that is specified in the corresponding Web Comparison 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 that corresponds to the web page to be compared. If this parameter is not specified, TestComplete uses the Page object that is specified in the corresponding Web Comparison project element.

ReportDifference

If this parameter is True (this is the default value) and the comparison fails, the method posts a warning message about the differences to the test log. If this parameter is False, the method does not post any messages to the log.

Timeout

The contents of some web pages are generated dynamically after the page is loaded in the browser. The Timeout parameter lets you specify the time, in milliseconds, to wait until the web page contents match the contents stored in the Web Comparison element.

By default, the Timeout is -1, which means that the waiting time is specified by the Auto-wait timeout project property. If Timeout is 0, the method does not wait and verifies PageObject immediately.

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 succeeds and False otherwise.

Also True if TestComplete has updated the given Web Comparison element.

Remarks

The method compares web pages according to the properties of the appropriate Web Comparison project element. For more information on these actions, see About Web Comparison Checkpoints.

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

Example

The following code obtains the web page and compares it with the HTML document stored in the WebTesting collection. If the comparison fails, the code posts a warning message to the test log.

JavaScript, JScript

function WebComparisonCompare()
{

  var Browser, Page, WebObject
  // Launches the browser
  …

  // Obtains the page with which you want to compare the stored document
  Page = Browser.Page("*");
  Page.ToURL("smartbear.com");

  // Obtains the WebComparison object
  WebObject = WebTesting.WebComparison1;

  // Compares the web page with the stored HTML document
  // If the comparison fails, posts a warning message to the test log
  WebObject.Compare(Page, true, 3000, lmWarning);

  …

}

Python

def WebComparisonCompare():
  # Launches the browser
  # ...
  # Obtains the page with which you want to compare the stored document
  Page = Aliases.Browser.Page("*")
  Page.ToURL("smartbear.com")
  # Obtains the WebComparison object
  WebObject = WebTesting.WebComparison1
  # Obtains the web page with the stored HTML document
  # If the comparison fails, posts a warning message to the test log
  WebObject.Compare(Page, True, 3000, lmWarning)
  # ...

VBScript

Sub WebComparisonCompare

  Dim Browser, Page, WebObject
  ' Launches the browser
  …

  ' Obtains the page with which you want to compare the stored document
  Set Page = Browser.Page("*")
  Call Page.ToURL("smartbear.com")

  ' Obtains the WebComparison object
  Set WebObject = WebTesting.WebComparison1

  ' Compares the web page with the stored HTML document
  ' If the comparison fails, posts a warning message to the test log
  Call WebObject.Compare(Page, True, 3000, lmWarning)

  …

End Sub

DelphiScript

procedure WebComparisonCompare();
var Browser, Page, WebObject;
begin

  // Launches the browser
  …

  // Obtains the page with which you want to compare the stored document
  Page := Browser.Page('*');
  Page.ToURL('smartbear.com');

  // Obtains the WebComparison object
  WebObject := WebTesting.WebComparison1;

  // Compares the web page with the stored HTML document
  // If the comparison fails, posts a warning message to the test log
  WebObject.Compare(Page, true, 3000, lmWarning);

  …

end;

C++Script, C#Script

function WebComparisonCompare()
{

  var Browser, Page, WebObject
  // Launches the browser
  …

  // Obtains the page with which you want to compare the stored document
  Page = Browser["Page"]("*");
  Page.ToURL("smartbear.com");

  // Obtains the WebComparison object
  WebObject = WebTesting["WebComparison1"];

  // Compares the web page with the stored HTML document
  // If the comparison fails, posts a warning message to the test log
  WebObject["Compare"](Page, true, 3000, lmWarning);

  …

}

See Also

About Web Comparison Checkpoints
Modifying WebTesting Elements

Highlight search results