Validating message fields

For fields that are of the type Message, the contents of the validate tab changes. The new options let users validate the structure of a message (or its child elements) rather than its individual attributes.
Field Editor
Note: Some of the same validations that are available for scalar fields can be used on Message fields. These validations are Is Null , Not Null, and Assert using Function.


The new validation actions available for Message fields are described in the following topics:

Validating element children


If you want to validate the children of the selected field, select the Validate Element Children option. This is available only for XML messages.

Validate Element Children
Select the additional options, as follows:

Accept fields in any order HCL OneTest™ API ignores the order in which message fields are received. This option can be useful since messages sent on certain transports can undergo field-reordering.
Ignore missing fields in received message When enabled, any fields present in the expected message structure but absent in the message that is received do not cause invalidation.
Ignore additional fields in received message When enabled, any fields present in the received message but absent in the expected message structure do not cause invalidation.

Validating message children


If you want to validate the children of a message element, select the Validate Message Children option.

Validate Message Children
Configure the General settings as follows:

Accept fields in any order HCL OneTest API ignores the order in which message fields are received. This option can be useful since messages sent on certain transports can undergo field-reordering.
Ignore missing fields in received message When enabled, any fields present in the expected message structure but absent in the message that is received do not cause invalidation.
Ignore additional fields in received message When enabled, any fields present in the received message but absent in the expected message structure do not cause invalidation.

Ignoring the descendent nodes and its following siblings

When you keep adding extra fields to a schema, the messages change; consequently, the validation fails. Select Ignore any descendant node and its following siblings that match the following fields check box to ignore any descendent nodes or siblings to the messages added after the node indicated by the following parameters:
  • Namespace URI (optional): Enter the namespace URI that you have created for the fields to be ignored.
  • Name: Enter the name of the field.

Validating by using a tag

To compare a received value against a message or submessage that was previously tagged, select the Validate Using Tag option.

Validate Using Tag

Select the existing tag against which the comparison is to occur from the Validate against tag menu. If there are any fields that are to be ignored in the comparison, you can enter an XPath representation of them under Exceptions.

Validating by using a message from file

It is possible to validate a message against a previously saved version of the message.

In the following example, we created a two-step test where the first step publishes data from a file and the second step subscribes to the published data and compares the data to messages that were previously saved. The publish step provides us with the tagged data that allows us to specify the name of the file we want to compare the data with in the subscribe step.

To enable validation against a saved message file, edit the message in the subscribe step and double-click the top (Message) node of the message. Next, select the Validate Using Message from File action type.

Validate using message from file

Click Select to choose a message resource file. Select the wanted message from the Select Resource dialog and click OK when finished.

Select resource

The message location is displayed as a path in the field editor (for example, /Test Data/Output Data/myMessage.)

It is possible to make the file name dynamic (that is, generated from data that are received in the incoming messages) by substituting a tag for a portion of the message path. In the example that is shown, only the message folder name is being substituted.

Insert Tag

You are now ready to run the test. For each message to which the test subscribes, a comparison is made to the message in the file that matches the resource file name that is constructed by the published tag.

If you are not interested in comparing some of the fields (for example, date fields, which are likely to change), validation exceptions can be added. Paths to fields that are not to be included in the validation must be entered in the Exceptions field.

Validate Using Message from File

In the example that is shown, validation is not carried out against the ReviewDate attribute or against any of the rating elements for each of the songs.

Assert by using function

You can access the received value of the field within the message by using the FIELD/VALUE tag.

Feedback