Compare method to compare data stored in the XMLCheckpoint project element, to which the XMLCheckpoint object corresponds, with the data of an XML document.
Compare method you can also update the XML data stored in the XMLCheckpoint element. TestComplete does this if the Update XML data option is enabled. See Modifying Elements of the XML Collection.
XMLCheckpointObj.Compare(xmlSource, ReportDifference, MessageType)
|XMLCheckpointObj||An expression, variable or parameter that specifies a reference to an XMLCheckpoint object|
|ReportDifference||[in]||Optional||Boolean||Default value: True|
|MessageType||[in]||Optional||Variant||Default value: lmWarning|
The method is applied to the following object:
The method has the following parameters:
This parameter specifies the source of the compared XML data. It can be one of the following:
Specifies whether the method will build a detailed report on the found differences and post this report to the test log.
The type of message to be posted to the test log in case the comparison fails and ReportDifference is True. Possible values:
||Do not post any message.|
||Post an informative message.|
||Post a warning message.|
||Post an error message.|
True, if the comparison is successful and False otherwise.
Compare method returns True or False indicating the comparison result.
If the verification passes, the method posts a success message to the test log. If the verification fails, the method, by default, logs a detailed report on all differences found. For more information on what the report contains, see XML Comparison Results Log Page. To disable logging the difference report, pass False to the ReportDifference parameter when calling the method.
The method compares XML data according to the comparison settings specified in the XMLCheckpoint project element. Before calling the method, you can modify these options as well as the stored data. For more information on changing the settings and data, see Creating XML 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.
The following example demonstrates how you can compare the stored XML document with the external XML document specified by its full name and path.
def XMLCheckpointCompare(): # Specifies the external XML file. XMLFile = "D:\\Work Folder\\SampleXMLFile.xml" # Obtains the XMLCheckpoint object from script. XMLCheckpoint = XML.MyXMLCheckpoint # Compares the stored XML document with the external XML document. # Posts a detailed report if the comparison fails. if not XMLCheckpoint.Compare(XMLFile, True , lmNone): Log.Error("" + XMLFile + " differs from the stored XML document.")
The following example demonstrates how you can load XML data to the
IXMLDOMDocument object and compare this data with the stored XML data.
def XMLCheckpointCompare2(): # Creates an object implementing the IXMLDOMDocument interface. # If you have MSXML 4: XMLDoc = Sys.OleObject["Msxml2.DOMDocument.4.0"] # If you have MSXML 6: XMLDoc = Sys.OleObject["Msxml2.DOMDocument.6.0"] XMLDoc.async = False # Loads data from the XML document to the IXMLDOMDocument object. XMLDoc.load("D:\\Work Folder\\SampleXMLFile.xml") # Obtains the XMLCheckpoint object from script. XMLCheckpointObject = XML.MyXMLCheckpoint # Compares MyXMLCheckpoint with the IXMLDOMDocument object. # Posts an error message and a detailed report to the log if the comparison fails. XMLCheckpointObject.Compare(XMLDoc, True, lmError)