Skip to main content

XML Assertions

XML matchers perform a structural XML comparison (element order is irrelevant) with optional exclusion of specific elements. An XPath variant lets you pinpoint specific values.


Structural XML match : Then expected record from file based on XMLโ€‹

Fetches a record and compares its value as XML. Attribute order, whitespace, and element order are normalised before comparison.

Then expected record from file based on XML
| topicAlias | file | excludedElements | expectedRecordKey |
| orders-out | expected.xml | ns:CreationDateTime | |
ColumnTypeRequiredDescription
topicAliasstringโœ…Alias of a declared output topic
filestringโœ…Expected XML file path, relative to assets directory
excludedElementsstringโŒComma-separated list of XML element names or XPath expressions to ignore during comparison
expectedRecordKeystringโŒFilter: only accept records with this exact key
consumerReadTimeoutintegerโŒMax seconds to wait for a record
consumerDeltaTimeintegerโŒHow far back (seconds) to seek

Excluding elementsโ€‹

The excludedElements column accepts comma-separated element names (with or without namespace prefix):

| excludedElements |
| CreationDateTime,MessageId,ns2:Checksum |

Elements listed here are removed from both the expected and actual XML before comparison.


XPath match : Then expected record based on XML should have fields matching from fileโ€‹

Extracts one or more values from the record using XPath expressions and compares them against the corresponding expected file content line-by-line.

Then expected record based on XML should have fields matching from file
| topicAlias | file | xpathExpressions |
| orders-out | expected.xml | //Weight[@unit='KG']/text(),//Sender/ID/text() |
ColumnTypeRequiredDescription
topicAliasstringโœ…Alias of a declared output topic
filestringโœ…Expected values file โ€” one expected value per line matching the XPath order
xpathExpressionsstringโœ…Comma-separated XPath expressions

Expected file format for XPathโ€‹

When using multiple XPath expressions, the expected file contains one value per line, in the same order as the expressions:

assets/expected-xpath.txt
42.5
SENDER-001

Avro + XML

XML matchers are not available for Avro topics. Use Avro matchers โ†’ for Avro-serialised records.