Skip to main content

String Interpolation

Since v1.0.0

It 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

Interpolation by Substitution

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}"

Interpolation by Concatenation

Deprecated

The concatentation method has been deprecated in favor of substitition since Gwen 3 (dropped in v3.14.0)

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 will be " + my value
Then my proposition should be "By concatenation, my value will be " + my.property