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 green arrow.
After a diff is executed, the results appear in the visualizer in the Diff Viewer tab in the assertion editor.
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:
Whether case sensitivity is used during the comparison (enabled by default).
During a comparison, all leading and trailing whitespace is removed from element text and attribute values (enabled by default).
In addition to trimming whitespace, any sequence of one or more whitespace characters inside text is converted to a single space character.
Any sequence of one or more whitespace characters is converted to a single space character.
All whitespace is ignored during the comparison.
The namespace value of an element or attribute is ignored.
The namespace prefix of an element or attribute is ignored (enabled by default).
Ignore the order of child elements in the XML document.
Ignore the order of attributes in the XML document (enabled by default).
Ignore all element text.
Compare attribute names but ignore attribute values.
Ignore attribute names and values.
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.
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.
Copyright © 2014 CA Technologies.
All rights reserved.
|
|