Verify contents of XML resources

The standard Module Verify XML allows the entire XML resource content to be verified by using either XPath expressions or the dynamic expression CONTAINS. This Module is included in the Standard subset subset at TBox XEngines->XML.

Verifying XML resource contents by using XPath

Use the Module Verify XML to verify XML resource contents by using XPath expressions.

This Module is part of the Standard subset. You can find it under Standard modules->TBox XEngines->XML.

If you would like to apply XPath expressions to predefined nodes rather than an entire XML resource, please have a look at chapter "Selecting XML elements by using XPath expressions".

Please follow the steps below to apply XPath expressions to an entire XML resource:

  1. Create a TestStep out of the Module Verify XML.

  2. Define the required XML resource for the TestStepValue Resource.

  3. Enter the complete XPath expression into the TestStepValue XPath. Make sure to put the entire expression between quotation marks. The special character " must be prefixed by another " character.

  4. Specify the expected result in the TestStepValue Value and set the ActionMode to Verify.

  5. Optionally you can define namespaces which you can use in your XPath expression. Create a new TestStepValue under the TestStepValue Namespaces for each namespace. Enter the namespace name into the Name column and the URI into the Value column.

The example below loads the XML file books.xml into the resource myXML. The value poet at XPath->Value is compared to the result of the XPath expression "//book[@id=""bk002""]/author".

Verifying XML content using XPath

In this example, the engine searches the XML resource Add - Request 1 for the node AddResult by using XPath. Two namespaces are defined in the XML resource which are also used in the XPath expression. The TestStepValue Value verifies whether the result equals 98. The namespaces are defined in the Namespaces node by using the name and the URI.

Example: Verifying XML content using XPath and namespaces

How to verify an XML resource by using the dynamic expression XMLDIFF

The dynamic expression XMLDIFF enables you to specify full XML structures when you verify XPath results. In this, you can use parameters to define whether or not XML comments or prefixes should be considered by namespaces. This value is used in the standard Module Verify XML in the TestStepValue XPath->Value.

Syntax:

{XMLDIFF[<XML structure>][<Ignore XML comments>][<Ignore prefix>]}

Parameter

Description

XML structure

Complete XML structure which is compared to the result of the XPath expression.

Ignore XML comments

Optional parameter which uses the values True or False to indicate whether comments should be ignored in the XML structure or not. Comments will be considered if this parameter is not specified.

Ignore prefix

This uses the value True or False to indicate whether namespace prefixes may vary in the XML structure and the XPath result. Namespace URIs must be equal. If the parameter is not specified, prefixes must be equal.

In this example, the node describedby is found in the XML resource myXML by using XPath:

<describedby xmlns:cs="http://myService">

<!--comment to be ignored-->

<cs:value>Daniel Defoe</cs:value>

<name>Author</name>

</describedby>

This node should correspond to the following node:

<describedby xmlns:ab="http://myService">

<ab:value>Daniel Defoe</ab:value>

<name>Author</name>

</describedby>

Verification is done by using XMLDIFF. When parameters of the value True are transferred, the comments will be ignored in both nodes, and the namespace is compared by using the URI.

Example: Verifying XML content using XMLDIFF

Verifying XML resource contents by specifying values

Use the Module Verify XML to verify whether a specific text exists in an XML resource. You can either specify the entire XML, or enter a regular expression for the entire content or use the dynamic expression CONTAINS.

This example loads the XML file books.xml into the resource myXML. The first TestStepValue Content uses the dynamic expression CONTAINS to verify whether the XML resource contains the value bk002.

The second TestStepValue Content verifies whether the XML resource and the regular expression .*CDATA.* match.

Verifying XML content

How to verify strings by using the dynamic expression CONTAINS

Use the Module Verify XML along with the dynamic expression CONTAINS to verify whether a specific string exists in the specified XML resource. You can also use the parameter ignore case and set its value to either true or false to define whether case-sensitivity should be applied upon verification. If this parameter is not specified, the system uses the notation of the string.

Syntax:

{CONTAINS[<string>][<ignore case>]}

Parameter

Description

String

String to be searched for in the specified XML resource.

Ignore case

Optional parameter which uses the values True or False to indicate whether comments should be ignored in the XML structure or not. Comments will be considered if this parameter is not specified.

This example loads the XML file books.xml into the resource myXML.

The first TestStepValue Content uses the dynamic expression CONTAINS to verify whether the XML resource contains the value bk002.

The second TestStepValue Content verifies whether the value <title>The Poet's First Poem</title> exists.

The third TestStepValue verifies whether the resource contains the value poet, irrespective of whether case-sensitivity applies or not.

Verifying XML content using CONTAINS