Skip to main content

String Interpolation

Since v1.0.0

String interpolation is often useful to reference settings, captured values and other text throughout your feature and meta files. To support this, Gwen provides a placholder substitution mechanism.

Placeholder Syntax

Placeholders are declared using the ${placholder} syntax and can include:

  • An environment variable name (since gwen-web 2.36.0)
    • example: ${env.USER} for the USER variable
  • A system property name
  • A Gwen setting name
  • A named binding in the currently accessible scope
  • JS arrow functions

Examples

Substitution involves replacing named 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 will be ${my value}"
Then my proposition should be "By substitution, my value will be ${my.property}"

Elvis Operator

Since v4.4.0

The elvis ?: syntax can be used to define default values for references which may not exist

Examples

 Given a is "${some.string :? 'default'}"
And b is "${some.string :? '${some.other.string}'}"
And c is "${some.string :? blank}"
And d is "${some.boolean :? false}"
And e is "${some.string1 :? '${some.string2 ?: blank}'}"
  • Set a to value bound to some.string or to default string value if undefined
  • Set b to value bound to some.string or to value bound to some.other.string if undefined
  • Set c to value bound to some.string or to a blank string value if undefined:
  • Set d to value bound to some.string or to a false Boolean value if undefined:
  • Set e to value bound to some.string1 or value bound to some.string2 if undefined, or to a blank string value if both are undefined: