Skip to content

String Interpolation

Branko Juric edited this page Jan 19, 2016 · 45 revisions

Gwen logo String Interpolation

It is often useful to reference named properties and reuse 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 the embedded engine for execution.

Named Values

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

  • A system property
    • Passed to Gwen through a -D JVM argument
  • A user setting
  • A runtime setting
  • A launch property
    • A property in a properties file passed to Gwen through the -p or --properties launch option
  • A bound attribute
    • An attribute bound in the local, global, or current data scope
    • For example, the my ??? attributes in the samples below are all bound attributes

Interpolation by Substitution

Substitution involves replacing named value placeholders in a single string with their resolved values.

 Feature: String Interpolation

Scenario: By Substitution
    
    Given my mechanism is "substitution"
      And my value is "${my.property}"
     When 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 resolved named values together to form a single string.

 Feature: String Interpolation

Scenario: By Concatenation
    
    Given my mechanism is "concatenation"
      And my value is "" + my.property
     When my proposition is "By " + my mechanism + " my value is " + my value
     Then my proposition should be "By concatenation my value is " + my.property
Clone this wiki locally