Applies to TestComplete 14.60, last modified on September 18, 2020

If in your test you need to check whether an XML document stores appropriate data, but you cannot use XML checkpoints for some reason, you can take one of the following alternative approaches:

Create a Custom Verification Procedure

In your tests you can load XML files and work with them via Microsoft XML DOM objects. You create these objects via COM and then use them to get access to elements and attributes of the desired XML document. To perform verification actions over an XML document, follow the steps below:

  • Obtain the IXMLDOMDocument object that corresponds to the desired XML document (IXMLDOMDocument is an object of the Microsoft XML DOM library. It is used to work with XML documents. For more information on it, see the XML Core Services and Document Object Model article in the MSDN Library.

  • Write script code that will walk down the document node's and perform the desired verification operations.

    Note: To compare XML node values with expected values, you can use the if … then … else statement and various comparison operations like =, < or gt;.
  • Report the results.

For more information on using XML DOM objects and for sample code, see Working With XML Files From Scripts.

Writing custom verification code yourself lets you create more flexible procedures. However, this approach requires knowledge of XML.

Use XML.XMLElementName.Compare Scripting Method

In scripts, to verify the XML document contents, you can use the XML.XMLCheckpointElement.Compare method. The method compares the contents of the specified XML document with baseline data stored in the corresponding XMLCheckpoint element. To call the method in keyword tests, you can use the Call Object Method, Run Code Snippet or Run Script Routine operation.

The XML.XMLCheckpointName.Compare method is similar to the XML checkpoint, but it has additional MessageType and ReportDifference parameters. The ReportDifference parameter specifies whether the method should log notifications about differences found between compared XML documents. The MessageType parameter specifies what kind of message (an error, warning, informative message or no message at all) will be posted to the test log if the actual and the baseline XML documents are not equal.

The following example demonstrates using the method:

JavaScript, JScript

function Test()
{

  var xmlPath = "C:\\Work\\Data.xml";

  if (! XML.XmlCheckpoint1.Compare(xmlPath, true, lmNone))
    Log.Warning(xmlPath + " differs from the stored XML document.");

}

Python

def Test():

  xmlPath = "C:\\Work\\Data.xml"

  if not XML.XmlCheckpoint1.Compare(xmlPath, True, lmNone):
    Log.Warning(xmlPath + " differs from the stored XML document.")

VBScript

Sub Test

  xmlPath = "C:\Work\Data.xml"

  If Not XML.XmlCheckpoint1.Compare(xmlPath, true, lmNone) Then
    Log.Warning(xmlPath & " differs from the stored XML document.")
  End If

End Sub

DelphiScript

procedure Test();
var xmlPath;
begin

  xmlPath := 'C:\Work\Data.xml';

  if not XML.XmlCheckpoint1.Compare(xmlPath, true, lmNone) then
    Log.Warning(xmlPath + ' differs from the stored XML document.');

end;

C++Script, C#Script

function Test()
{

  var xmlPath = "C:\\Work\\Data.xml";

  if (! XML["XmlCheckpoint1"]["Compare"](xmlPath, true, lmNone))
    Log["Warning"](xmlPath + " differs from the stored XML document.");

}

Similar to the XML checkpoint, the method supports the XMLCheckpoint element data update. If the Update XML data option is enabled, the method updates the baseline data stored in the corresponding XMLCheckpoint element replacing it with the actual data retrieved from the specified XML document.

Use File Checkpoints

To verify the contents of an XML file by comparing it byte-to-byte with the baseline XML file, use a file checkpoint. In keyword tests, use the File Checkpoint operation to verify file contents. In scripts, use the Files.FileCheckpointName.Check method. For more information, see About File Checkpoints.

See Also

XML Checkpoints
XML Checkpoints
Working With XML Files From Scripts
Compare Method
About File Checkpoints

Highlight search results