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, we assume one context per test. This is to be refined later in T227887: Phester: bind variables to session context.
Variables provide a mechanism for taking a value from a response and using it in a subsequent request. Variables may also provideaccess to configuration settings, see T228865: Phester: allow configuration to be loaded from a file.
Variables can be assigned a value in two ways:
- directly, in a variables stanza. The variable stanza is an object mapping keys (variable names) to values. Special tags are evaluated before assigning the value, e.g. p/uniq (see T228884).
- by "grabbing" a value in a response, using the p/grab tag followed by the variable name.
Variable values can be used as follows:
- raw, via the p/var tag followed by the variable name.
- (future) in an interpolation expression (ix), using the p/ix tag followed by a string. Eventually, that string should support a way to access variables (string interpolation). The specification and implementation of interpolation expressions is tracked in T228874.
Variable names follow the pattern /^[a-z][-_a-z0-9]*$/i. The characters /, \\, @, $, :, and . are reserved for use in variable expressions, e.g. as prefix separators or markers.
tests: - description: create and delete variables: - title: p/uniq: "Test_" # 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