Expressions available out of the box

Here one could find description of the expressions that are delivered with Vividus itself without any plugins required.

The expression parameters marked with bold are mandatory.

Data generation

randomInt

Generates a random integer value between the specified origin (minInclusive) and the specified bound (maxInclusive).

#{randomInt($minInclusive, $maxInclusive)}
  • $minInclusive - the least value

  • $maxInclusive - the upper bound

Table 1. Examples of the expressions generating random integer value
Expression Result

#{randomInt(1, 10)}

An integer between 1 and 10

#{randomInt(100, 999)}

An integer between 100 and 999

#{randomInt(-5, 5)}

An integer between -5 and 5

#{randomInt(-5, -2)}

An integer between -5 and -2

#{randomInt(1, 1)}

1

String manipulations

toLowerCase

Converts an input string to lower case.

#{toLowerCase($input)}
  • $input - any string to be converted lower case

Table 2. Examples of the expressions converting strings to lower case
Expression Result

#{toLowerCase(aBc)}

abc

toUpperCase

Converts an input string to upper case.

#{toUpperCase($input)}
  • $input - any string to be converted upper case

Table 3. Examples of the expressions converting strings to upper case
Expression Result

#{toUpperCase(aBc)}

ABC

capitalize

Capitalizes an input string, changing the first character to title case. No other characters are changed.

#{capitalize($input)}
  • $input - any string to be capitalized

Table 4. Examples of the expressions capitalizing strings
Expression Result

#{capitalize(aBc)}

ABc

uncapitalize

Uncapitalizes an input string, changing the first character to lower case. No other characters are changed.

#{uncapitalize($input)}
  • $input - any string to be uncapitalized

Table 5. Examples of the expressions uncapitalizing strings
Expression Result

#{uncapitalize(ABc)}

aBc

trim

Trims an input string (removes control characters (chars with code less than or equal to 32) from both ends).

#{trim($input)}
  • $input - any string to be trimmed

Table 6. Examples of the expressions trimming strings
Expression Result

#{trim( a b c )}

a b c

encodeToBase64

Encode the input string to Base64 format

#{encodeToBase64($input)}
  • $input - any string to be encoded to Base64 format

Table 7. Examples of the expressions encoding to Base64
Expression Result

#{encodeToBase64(vividus)}

dml2aWR1cw==

decodeFromBase64

Decodes the input string from Base64 format to the regular string

#{decodeFromBase64($input)}
  • $input - Base64 string to decode

Table 8. Examples of the expressions decoding Base64
Expression Result

#{decodeFromBase64(dml2aWR1cw==)}

vividus

toBase64Gzip

Compress the input string to GZip and encode compressed bytes to Base64 format

#{toBase64Gzip($input)}
  • $input - any string to be compressed and encoded

Table 9. Examples of the expressions compressing and encoding to Base64 GZip
Expression Result

#{toBase64Gzip(vividus)}

H4sIAAAAAAAAACvLLMtMKS0GANIHCdkHAAAA

Resources

loadResource

Loads the resource found at the provided path and replaces the expression with the content of the resource.

#{loadResource($pathToResource)}
  • $pathToResource - the path to the resource to load. It must be relative to the project, meaning src/main/resources is left out of it. Therefore, if the file is located at my-tests/src/main/resources/data/body.txt, then it’s required to put only relative resource part: /data/body.txt

Example 1. Load data from the project resource
When I initialize the scenario variable `my-data` with value `#{loadResource(/data/body.txt)}`

loadBinaryResource

Loads the resource found at the provided path as bytes. Could be useful for the steps that accepting raw binary data.

#{loadBinaryResource($pathToResource)}
  • $pathToResource - the path to the resource to load. It must be relative to the project, meaning src/main/resources is left out of it. Therefore, if the file is located at my-tests/src/main/resources/data/body.txt, then it’s required to put only relative resource part: /data/body.txt

Example 2. Load data from the project resource as bytes
When I mock HTTP responses with request URL which CONTAINS `frames.html` using response code `200`, content `#{loadBinaryResource(page.html)}` and headers:
|name        |value    |
|Content-Type|text/html|

resourceToBase64

Finds the resource at the provided path and replaces the expression with the content of the resource in Base64 format.

#{resourceToBase64($pathToResource)}
  • $pathToResource - the path to the resource to load. It must be relative to the project, meaning src/main/resources is left out of it. Therefore, if the file is located at my-tests/src/main/resources/data/body.txt, then it’s required to put only relative resource part: /data/body.txt

Example 3. Load data as Base64 from the project resource
When I initialize the scenario variable `my-data` with value `#{resourceToBase64(/data/body.txt)}`

Script evaluation

evalGroovy

Evaluates groovy script and converts result to a string.

#{evalGroovy($script)}
  • $script - valid Groovy script to be evaluated

  • Any Vividus variable is accessible in the groovy script by its name

  • One could use any of online groovy evaluators to verify the script. For example see: Evaluator

Example 4. Evaluate Groovy script
When I initialize Scenario variable `listOfMaps` with values:
|key|
|2  |
|1  |
|3  |
Then `1-2-3` is = `#{evalGroovy(return listOfMaps.collect{it['key']}.sort().join('-'))}`