Previous Topic: Ensure Step Response TimeNext Topic: XML XPath Assertion


Graphical XML Side-by-Side Comparison

The Graphical XML Side-by-Side Comparison assertion lets you compare a test XML value received from a test with a control XML value. If the responses are the same or different, the assertion can return true. This assertion provides the flexibility to compare XML documents at various steps in a business process to ensure they match expected criteria. This approach is known as "exclusive" testing, where an entire response is compared except for a few values that are known to change.

The assertion editor works by comparing a left and right side of XML to each other. The left side is known as Control Content. The right side is known as Test Content. For example, Control Content is the expected XML returned from a web service in the application under test, while the Test Content is actual content. By default, Test Content is loaded from the last response of the test step that is associated with the assertion, signified by the empty property key. Otherwise, any valid property key can be used and the Test Content is loaded from it.

Alternatively, you can complete one of the following actions in test case authoring mode so that a quick graphical diff can be performed:

To perform the diff, click the Icon right arrow green arrow.

Graphical XML Side-by-Side Comparison assertion window before diff is performed

After a diff is executed, the results appear in the visualizer in the Diff Viewer tab in the assertion editor.

Graphical XML Side-by-Side Comparison assertion window after diff is performed

 

Output During Execution

When an assertion is executed, DevTest logs the diff results as test events.

An Info message EventID containing the XML diff results is always logged.

If the assertion fires, an Assertion fired EventID containing the XML diff results is logged.

The diff results are reported in a format resembling the original UNIX diff utility. An example of a text diff report is:

Assert [Assert1] fired false of type Graphical XML Diff Assertion
XML is [Different]
=====
1,2[ELEMENT_NAME_CHANGED]1,2
<! <test2>
<! </test2>
---
>! <test>
>! </test>

Each difference is displayed with a heading of the format:

<First Start Line>, <First End Line>'['<Diff Type>']'<Second Start Line>,<Second End Line>

Then the difference in the first content is displayed, followed by the separator '---', followed by the difference in the second content.

The + character indicates addition, the - character indicates a deletion, and the ! character indicates a change. When these characters are present, they indicate that an actual change occurred on the line of content (instead of to a context line).

XML Compare Options

The following comparison options are available for use by the diff engine:

General
Case sensitive

Whether case sensitivity is used during the comparison (enabled by default).

Whitespace
Trim whitespace

During a comparison, all leading and trailing whitespace is removed from element text and attribute values (enabled by default).

Collapse whitespace

In addition to trimming whitespace, any sequence of one or more whitespace characters inside text is converted to a single space character.

Normalize whitespace

Any sequence of one or more whitespace characters is converted to a single space character.

Ignore all whitespace

All whitespace is ignored during the comparison.

Namespaces
Ignore namespaces

The namespace value of an element or attribute is ignored.

Ignore namespace prefixes

The namespace prefix of an element or attribute is ignored (enabled by default).

Ordering
Ignore child element ordering

Ignore the order of child elements in the XML document.

Ignore attribute ordering

Ignore the order of attributes in the XML document (enabled by default).

Node Types
Ignore element text

Ignore all element text.

Ignore attribute values

Compare attribute names but ignore attribute values.

Ignore attributes

Ignore attribute names and values.

Ignored Nodes

Ignored nodes are created from a list of XPaths that are run against the left and right documents. Each evaluated XPath that returns a node set is aggregated. When the diff occurs, any node that is found in the aggregate set is ignored.

Ignored node XPaths can be any arbitrary query that returns a node set. For example, the XPath //* excludes all nodes in an XML document. /example/text() excludes the first text node child of the example element in an XML document. /example/@myattr is the XPath to ignore the myattr attribute, including the attribute text value, belonging to the example element in an XML document.

Graphical XML Side-by-Side Comparison assertion window Ignored Nodes tab

A right-click menu item also lets a node be selected directly inside an XML document and its XPath is added to the Ignored Nodes list.

Graphical XML Side-by-Side Comparison assertion window Ignored Nodes tab, Right-click menu