TBD: //update the description below to be only about variable extraction.Variables are parts of yaml structure (primitive values, objects, or lists) that can be accessed by name. The name is relative to a context. For now, The rest should be discussed in the context of sessions.//we assume one context per test. This is to be refined later in {T227887}.
Variables are referenced inside fixtures and test suites using a special syntax that is available only inside values of a special type identified by the //tempate// tag (TBD: figure out how exactly YAML tags work and how well they are supported by the tools we want to use). The syntax follows the form used in PHP strings: `"some{$xyz}thing"`provide a mechanism for taking a value from a response and using it in a subsequent request. This allows the variable's value to be combined with static textVariables may also provideaccess to configuration settings, as well as the use of multiple variables.
Variables are used to provide access to the following things:
# access to the environmentsee {T228865}.
#* the --environment <yaml-file> optionVariables can be used to loaassigned a yaml filvalue into the global context two ways:
# access to randomized values* directly, in a variables stanza.
#* A test suite (or fixture) can declare variables for the suite context that are pre-loaded with a fixed prefix and a randomized suffix* by "grabbing" a value in a response, see {T219883}.using the `p/grab` tag followed by the variable name.
Variable values can be used in two ways:
# access to values extracted from a response (in a previous request of the same test, from requests in the suit's setup* raw, or in a fixture)via the `p/var` tag followed by the variable name.
#* To extract a variable from a (JSON) response* in an interpolation expression (ix), using the `p/ix` tag followed by a string that uses mushache-like syntax, e.g. `"Hello {{foo}}"`. Interpolation expressions may also support simple function calls, like `"Hello {{#random:16}}"` or `"Hello {{#uppercase:$name}}"`.
Variable names follow the pattern `/^[a-z][-_a-z0-9]*$/i`. The characters `/`, `\\`, `@`, `$`, `:`, and `.` are reserved for use in variable expressions, a value with the //grab// tag is used,e.g. see {T219883}as prefix separators or markers.
Note that fixtures can export variables via their session context once {T227887} is done. To access such a variable, the name of the context (that is, the name of the fixture) is used as a prefix to the variable name.Example:
```
tests:
- description: create and delete
variables:
- title: p/ix: "Test_{{#random:16}}" # Interpolation expression with function call
interaction:
- request:
action: create
page: p/var: title # defined above
- response:
body:
create:
page-id: p/grab: page-id # grab the value from the response
- request:
use-session: Bob
action: delete
page-id: p/var: page-id # use the value grabbed above
```