Skip to main content

String Interpolation

It is often useful to reference provided properties, captured values, and string literals throughout your features. Gwen provides two interpolation mechanisms for doing this:

Interpolation occurs in the interpreter on every step in a feature before it is passed to Gwen for execution.

Named Values

For interpolation purposes, a named value can be any one of the following:

  • An environment variable (since gwen-web 2.36.0)
    • example: ${env.USER} for the USER variable
  • A system property
  • A Gwen setting
  • A launch property
  • A bound attribute
    • An attribute bound in the local, global, or current data scope

Examples

In the examples below..

  • my.property is a property
  • my mechanism is an attribute assigned to a literal

Interpolation by Substitution

This is the recommended interpolation approach

Substitution involves replacing named value placeholders with their values.

 Feature: String Interpolation

Scenario: By Substitution

Given my mechanism is "substitution"
And my value is "${my.property}"
And my proposition is "By ${my mechanism}, my value is ${my value}"
Then my proposition should be "By substitution, my value is ${my.property}"

Interpolation by Concatenation

Concatenation involves joining string literals and named values together.

 Feature: String Interpolation

Scenario: By Concatenation

Given my mechanism is "concatenation"
And my value is "" + my.property
And my proposition is "By " + my mechanism + ", my value is " + my value
Then my proposition should be "By concatenation, my value is " + my.property