Condition in a template
It can be useful to specify that a few xml fragments should be rendered in some specific cases and not in other cases. To achieve this, NBi uses the syntax and features provided by the external library StringTemplate and detailed there.
NBi will not assign a value to a variable in two cases:
- The value provided for this variable in the test-case is “(none)”
- The value provided as a length of 0 characters (an empty string).
Conditional rendering of an “ignore” element
Suppose that in your test-cases you’ve a column named ignoreReason and you want to add an xml element *
Your test-cases are defined in a CSV file as:
and you’re expecting the following result after the execution of the generation (note that the ignore tags are available in the second test but not on the first!):
To achieve this, you’ll need to make usage of the if statement provided by StringTemplate. To specify that a part of a template must be rendered only if a value is assigned to a variable simply write:
Take care of following details:
- if and endif are surrounded by $ symbols
- in the if statement, the name of the variable is not surrounded by $ symbols
- there is no comparison in the the if statement, just the name of the variable. The if statement check if the provided variable is assigned or not.
The following template should have been provided to successfully build the test-suite described above: