Verify
The Verify element is used to verify an expression or to compare two data values – or two data structures. It has an expected value and an actual value. The result will be marked as having validation errors if they are not equal.
Syntax
The syntax of the Verify element is:
or
The execution of the test scenario will stop immediately if the Verify element validates to false and the haltExecution attribute is true. The state of the test scenario will always be Failed when a Verify element validates to false.
The first syntax requires an expression inside the Statement element. The expression must evaluate to true or false. It can be a good idea to place the expression in a CDATA element to preserve whitespaces. See the example below.
For the second syntax, the optional expression attributes at the Expected and Actual elements can be used to write a JavaScript expression to produce data. Child data items are ignored when the expression attribute is not empty.
The optional Rules element can be used to define one or several Rule elements specifying content that should not be compared. The Rule element can exclude or include a part of the record in the comparison. The Rules element can only be used when expected and actual values or expressions are used and when the resulting values are text based and not complex data structures. The Rule element specifies a start and end position of each line/record in the expected and actual data. The position is 0-based meaning that the first position in the record is 0. The when attribute can be used to only apply the rule if the value of the when attribute is equal the value of the text between start end and position of either the expected, the actual or any of them. The In attribute specifies where to compare with the when value.
The following rule scenarios are supported and are illustrated in the Examples section:
–Exclude text between start and end position in actual and expected values from comparison. The when and in attribute can setup conditions as well.
–Include only text between start and end position in actual and expected values. The when and in attribute can setup conditions as well.
–Exclude complete line/record when text between start and end position actual or expected value is equal the value of the when attribute.
–Exclude complete records based on their numbers.
Examples
An example for the first syntax is illustrated below. The expression will evaluate to true if a variable called data has a child element that contains the text ‘hello world’, otherwise it will be false. In this example the expression will return true.
Below is an example with a hardcoded expected value and actual value is a DataReference to a simple variable. This test scenario will always be successful.
Next example compares complex structures. The actual value points to all children to AA in the variable, while the expected value is a structure of data.
Finally, the Verify element can use other Replaceable elements for verification. For instance, the Expression element is useful for making string operations.
We now have an example where we want to check that a referenced value contains the word ‘world’, and casing should be ignored. We will use an Expression with JavaScript to make a value uppercase and then ensure that the index of WORLD is not -1. The expression will return a Boolean which we then compare to true in the expected value. This could also (more easily) be expressed with the first syntax described above.
The same can also be obtained using expressions on the actual and expected elements, which makes the syntax more compact:
And finally it could also be expressed as:
Example of writing compare rules can be seen below. First rule will exclude characters from position 5-7 in all records. Second rule will exclude from position 8-10, but only when the expected value contains aaa in position 8-10. Third rule will include position 12-14 in the comparison of all records and exclude the rest. Fourth rule excludes the complete record when the expected record contains a12 between position 2-4. Fifth rule excludes the second record.