Expressions
VIVIDUS provides a set of pre-defined expressions. Also plugins may define own expressions (they are documented in the corresponding plugins articles).
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
Expression | Result |
---|---|
|
An integer between 1 and 10 |
|
An integer between 100 and 999 |
|
An integer between -5 and 5 |
|
An integer between -5 and -2 |
|
|
String manipulations
replaceFirstByRegExp
/ replaceAllByRegExp
Replaces the first / every substring of the input that matches the regular expression with the given replacement string.
Online tools like RegexPlanet or Regex101 can be used to test and debug regular expressions |
#{replaceFirstByRegExp($regularExpression, $replacement, $input)}
#{replaceAllByRegExp($regularExpression, $replacement, $input)}
-
$regularExpression - the regular expression to match substring(s)
-
$replacement - the replacement string, it may contain references to captured substrings, e.g.
$1
is a reference to the first group -
$input - any string to be processed
The expression parameters containing commas must be surrounded with triple quotes: """
|
Description | Expression | Result |
---|---|---|
Extract ID from the string |
|
|
Extract ID and build new string with it |
|
|
Extract password from the string with comma |
|
|
Replace whitespaces with dashes |
|
|
Remove all numbers from the string |
|
|
toLowerCase
Converts an input string to lower case.
#{toLowerCase($input)}
-
$input
- any string to be converted lower case
Expression | Result |
---|---|
|
|
toUpperCase
Converts an input string to upper case.
#{toUpperCase($input)}
-
$input
- any string to be converted upper case
Expression | Result |
---|---|
|
|
capitalizeFirstWord
Capitalizes an input string, changing the first character to title case. No other characters are changed.
#{capitalizeFirstWord($input)}
-
$input
- any string to be capitalized
Expression | Result |
---|---|
|
|
capitalizeWords
Capitalizes all the whitespace separated words in the input string. Only the first character of each word is changed.
#{capitalizeWords($input)}
-
$input
- any string to be capitalized
Expression | Result |
---|---|
|
|
capitalizeWordsFully
Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.
#{capitalizeWordsFully($input)}
-
$input
- any string to be capitalized
Expression | Result |
---|---|
|
|
uncapitalizeFirstWord
Uncapitalizes an input string, changing the first character to title case. No other characters are changed.
#{uncapitalizeFirstWord($input)}
-
$input
- any string to be capitalized
Expression | Result |
---|---|
|
|
uncapitalizeWords
Uncapitalizes all the whitespace separated words in the input string. Only the first character of each word is changed.
#{uncapitalizeWords($input)}
-
$input
- any string to be capitalized
Expression | Result |
---|---|
|
|
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
Expression | Result |
---|---|
|
|
encodeToBase64
Encode the input string to Base64 format
#{encodeToBase64($input)}
-
$input
- any string to be encoded to Base64 format
Expression | Result |
---|---|
|
|
decodeFromBase64
Decodes the input string from Base64 format to the regular string
#{decodeFromBase64($input)}
-
$input
- Base64 string to decode
Expression | Result |
---|---|
|
|
toBase64Gzip
Compress the input string to GZip and encode compressed bytes to Base64 format
#{toBase64Gzip($input)}
-
$input
- any string to be compressed and encoded
Expression | Result |
---|---|
|
|
escapeHTML
Escapes reserved characters in HTML string
#{escapeHTML($input)}
-
$input
- any string to be escaped
Expression | Result |
---|---|
|
|
quoteRegExp
Quotes the input literal so that metacharacters or escape sequences in the input sequence will be given no special meaning in regular expression.
#{quoteRegExp($input)}
-
$input
- any string to be quoted
Expression | Result |
---|---|
|
|
Then `${frontEndData}` matches `#{quorePattern(${backEndData})}.*`
Hash calculations
calculateHash
Calculates the hash using the specified hashing algorithm
#{calculateHash($algorithm, $input)}
Expression | Result |
---|---|
|
|
calculateFileHash
Calculates the resource or file hash using the specified hashing algorithm
#{calculateFileHash($algorithm, $resourceNameOrFilePath)}
Expression | Result |
---|---|
|
|
Resources
loadResource
Loads the resource by its name and replaces the expression with the content of the resource.
#{loadResource($resourceName)}
-
$resourceName
- the name of the resource to load
When I initialize the scenario variable `my-data` with value `#{loadResource(/data/body.txt)}`
loadBinaryResource
Loads the resource by its name as bytes. It could be useful for the steps that accepting raw binary data.
#{loadBinaryResource($resourceName)}
-
$resourceName
- the name of the resource to load
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 by its name and replaces the expression with the content of the resource in Base64 format.
#{resourceToBase64($resourceName)}
-
$resourceName
- the name of the resource to load
When I initialize the scenario variable `my-data` with value `#{resourceToBase64(/data/body.txt)}`
Script evaluation
eval
Evaluates JEXL script and converts result to a string.
#{eval($script)}
-
$script
- valid JEXL script to be evaluated
-
Any Vividus variable is accessible in the JEXL script by its name
Scenario: Verify eval expression
Then `#{<expression>}` is = `<expected>`
Examples:
|expected |expression |
|null |eval(null) |
|28 |eval(16 + 2 * 6) |
|10 |eval(math:abs(-10)) |
|here |eval(stringUtils:substringAfterLast('namescpaces are %here', '%'))|
|108 |eval((16 + 2) * 6) |
|-6 |eval(100 / 5 - 16 * 2 + 6) |
|true |eval(`string\n1` == `string\n1`) |
|false |eval(`string\n1` == `string1`) |
|I Am FINE |eval(wordUtils:capitalize('i am FINE')) |
|i am fINE |eval(wordUtils:uncapitalize('I Am FINE')) |
|tHE DOG HAS A bone|eval(wordUtils:swapCase('The dog has a BONE')) |
|FRD |eval(wordUtils:initials('Fus Ro Dah')) |
evalGroovy
Evaluates groovy script and converts result to a string.
#{evalGroovy($script)}
-
$script
- valid Groovy script to be evaluated
|
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('-'))}`
Null value
null
Represents null
(a.k.a. NULL
). In most case null
means no value (see NULL
in SQL and null
in JSON).
#{null}
Null expression can only be evaluated separately. Strings or other expressions with the nested null expression will be completely ignored and not executed. |
null
valueWhen I initialize the scenario variable `json` with value `
{
"persons": {
"nemo": null
}
}
`
Then JSON element value from `${json}` by JSON path `$.persons.nemo` is equal to `#{null}`