Template Matching
Since v2.16.0
Template matching allow users to compare any source content with a target template that can either be specified as a text literal or text stored in a file, and perform capture, ignore, and inject operations at the same time.
Examples
The following examples assume that the following JSON value is bound to an attribute named my value
in the currently available scope:
{"id":42,"category":{"name":"pet"},"name":"tiger","status":"available"}
Templates can contain JSON, XML, HTML, or any type of text and can also have multiple lines. The examples below use single-line JSON only.
Match and Ignore
The following example will successfully match my value
and:
- Ignore the
id
value where@{*}
appears
Then my value should match template
"""
{"id":@{*},"category":{"name":"pet"},"name":"tiger","status":"available"}
"""
Match, Ignore, and Capture
The following example will successfully match my value
and:
- Ignore the
id
value where@{*}
appears - Capture the
tiger
value where@{pet name}
appears and bind it to the attribute namedpet name
in the feature scope
Then my value should match template
"""
{"id":@{*},"category":{"name":"pet"},"name":"@{pet name}","status":"available"}
"""
Subsequent steps can access the captured pet name
attribute like any other Gwen binding. For example, the following checks it's value:
And pet name should be "tiger"
Match, Ignore, Capture, and Inject
The following example will successfully match my value
and:
- Ignore the
id
value where@{*}
appears - Caputre the
tiger
value where@{pet name}
appears and bind it to the attribute namedpet name
in the feature scope - Inject the value bound to the
my status
attribute into the template where${my status}
appears.
Given my status is "available"
Then my value should match template
"""
{"id":@{*},"category":{"name":"pet"},"name":"@{pet name}","status":"${my status}"}
"""
And pet name should be "tiger"
Ignore Multiple Lines
Multiple lines can be ignored anywhere in a template by specifying @{**}