String Interpolation

Branko Juric edited this page Jul 12, 2017 · 42 revisions

Gwen logo 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 the engine layer 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

Examples

In the examples below..

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

Interpolation by Substitution

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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.