String Interpolation in UI Steps¶
Interpolated Strings (also called Template Strings) contain Evaluation Groups, or eval
groups, whose content is interpreted. A Template String always results in a String. The main purpose for Template Strings is simpler formatting of output, although it can also be used to perform String arithmetics. Because Template Strings are common UI Steps Strings, they can be enclosed in double quotes (""
) or single quotes (''
).
String Interpolation Usage¶
Note:
-
Every String that is used within UI Steps can be a Template String.
-
An
eval
group starts with${
and ends with a curly bracket,}
.@{}
should not be used. -
Everything placed within an
eval
group is passed on to the interpreter for evaluation.
An eval
group may contain everything that is eligible for a right-hand side of an assignment. Therefore, variables and functions can be used. Additionally:
-
Multiple
eval
groups can be used in a Template String. -
Nesting
eval
groups should be avoided, as it can cause a parsing failure. -
Whenever a Template String does not contain any
eval
groups, it evaluates to a standard UI Steps String.
Configuration¶
The interpolateWebtestDefinitions
field of the Language
configuration interpolates Strings when set to true
. If set to false
, Strings will not be treated as Template Strings even if they contain eval
groups. The default for interpolateWebtestDefinitions
is false
to avoid any backward incompatibilities.
More details about the Language
configuration is available in String Escaping and Interpolation in Custom Languages.
Configuration Example
1 2 3 4 5 | Language { interpolateStrings = true interpretStringEscapes = true interpolateWebtestDefinitions = true } |
UI Steps View Example
1 2 3 4 5 6 7 | view SearchView(elementTitle) url "http://www.google.com" elem searchBox := "//input[@title='${elementTitle + 'SomeSuffix'}' and @class=\"b_searchbox\"]" action (searchBox) enter := type action (searchBox) search := click end |
The examples above contains the eval
group ${elementTitle + 'SomeSuffix'}
. It returns:
-
The title of the webpage result that is clicked upon
-
The suffix of the webpage