VIVIDUS provides a set of pre-defined expressions. Also plugins may define own expressions (they are documented in the corresponding plugins articles).
Note
|
The expression parameters marked with bold are mandatory. |
Generates random data from various domain areas.
#{generate(<expression>)}
-
$expression
- one of the data providers, its dot-separated method and space separated parameters wrapped into single quptes (for majority of cases parameters are not needed, their number and possible values depend on the chosen data provider method).
Below you can find a complete list of the supported expressions with results exmaples. Descriptions of the data providers and their parameters can be found in DataFaker documentation: click on the data provider name to find details.
Click here to view the complete list of the supported expressions
Let’s see the structure of the expression for the following example:
#{generate(Internet.password '5', '10', 'true')}
#{generate (1)
(Internet (2)
.password (3)
'5', (4)
'10', (4)
'true')} (4)
-
Generate expression itself.
-
Data provider from the list. In this case -
Internet
. Click on its name to see the methods it contains. -
One of the available methods within
Internet
data provider -password
. There are multiple choices, we picked the fourth one. -
Available parameters for the chosen method.
There are three of them:
-
int minimumLength - minimum number of symbols;
-
int maximumLength - maximum number of symbols;
-
boolean includeUppercase -
true
orfalse
for Uppercase usage;
-
In this way we created an expression that generates a password from 5 to 10 characters length including uppercase letters.
Possible output is 51gVj5aLZY
Replaces ?
symbols with latin letters.
#{generate(letterify '$input', '$isUpperCase')}
-
$input
- any string containing?
symbols to be replaced with letters -
$isUpperCase
- boolean, set it totrue
for uppercase option
Expression | Result |
---|---|
|
testnjmytest |
|
testXQBMtest |
Replaces #
symbols with numbers.
#{generate(numerify '$input')}
-
$input
- any string containing#
symbols to be replaced with numbers
Expression | Result |
---|---|
|
test5862test |
Combination of letterify and numerify.
#{generate(bothify '$input')}
-
$input
- any string containing#
and?
symbols to be replaced with numbers and letters accordingly
Expression | Result |
---|---|
|
test2o7v0g9test |
Replaces symbol mentioned in the second argument with one of the symbols mentioned after it.
#{generate(templatify '$input', '$whatToReplace', '$replacement1', '$replacement2', '$replacement3')}
-
$input
- any string to process -
$whatToReplace
- part of the string to be replaced -
$replacement
- replacement to use. Possible to use multiple options
Expression | Result |
---|---|
|
VPVPDUS |
VXVPDUS |
|
VPVXDUS |
|
VXVXDUS |
Replaces symbols by example: uppercase with uppercase, digit with digit, lowercase with lowercase.
#{generate(examplify '$input')}
-
$input
- any string to process
Expression | Result |
---|---|
|
R9Q7VTq |
Allows generating output based on regular expression.
#{generate(regexify '$regularExpression')}
-
$regularExpression
- regular expression that describes desired output
Expression | Result |
---|---|
|
409Y |
|
PQUlxdq66436 |
Returns any of provided items.
#{generate(options.option '$item1', '$item2', '$item3')}
-
$item
- option to choose from
Expression | Result |
---|---|
|
S |
Generates JSON based on key-value pairs input.
#{generate(json '$key1', '$value1', '$key2', '$value2')}
Expression | Result |
---|---|
|
{"first_name": "Bob", "last_name": "Dylan", "profession": "singer"} |
Generates comma-separated values based on input.
#{generate(csv, '$rowsNumber' '$columnName1', '$value1', '$columnName2', '$value2')}
-
$rowsNumber
- number of rows to fill in -
$columnName1
- name of the first column -
$value1
- data to enter the first column -
$columnName2
- name of the second column -
$value2
- data to enter the second column
Expression | Result |
---|---|
|
|
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 |
|
|
Rounds a number with an approximate value based on specific rounding definitions.
#{round($value, $maxFractionDigits, $roundingMode)}
-
$value
- any number to be processed -
$maxFractionDigits
- maximum number of digits after the decimal separator -
$roundingMode
- specifies a rounding behavior for numerical operations (more information here):Rouding Mode Readable Description UP
up
Rounds away from zero.
DOWN
down
Rounds towards zero.
CEILING
ceiling
Rounds towards positive infinity.
FLOOR
floor
Rounds towards negative infinity.
HALF_UP
half up
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round up.
HALF_DOWN
half down
Rounds towards "nearest neighbor" unless both neighbors are equidistant, in which case round down.
HALF_EVEN
half even
Rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
UNNECESSARY
unnecessary
Asserts that the requested operation has an exact result, hence no rounding is necessary.
Expression | Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Replaces the first / every substring of the input that matches the regular expression with the given replacement string.
Tip
|
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
Note
|
The expression parameters containing commas or empty values 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 |
|
|
Replace all whitespaces with commas |
|
|
Replace all whitespaces with commas |
|
|
Replace all commas with underscores |
|
|
Replace all commas with underscores |
|
|
Replace all commas with underscores |
|
|
Replace all commas with underscores |
|
|
Replace the first whitespace with comma |
|
|
Replace the first whitespace with comma |
|
|
Replace the first comma with underscore |
|
|
Replace the first comma with underscore |
|
|
Replace the first comma with underscore |
|
|
Replace the first comma with underscore |
|
|
Converts an input string to lower case.
#{toLowerCase($input)}
-
$input
- any string to be converted lower case
Expression | Result |
---|---|
|
|
Converts an input string to upper case.
#{toUpperCase($input)}
-
$input
- any string to be converted upper case
Expression | Result |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
Gets the substring before the first occurrence of a separator. The separator is not included in the result.
#{substringBefore($input, $separator)}
-
$input
- any string to get a substring from -
$separator
- the string to search for
Tip
|
Since the arguments of the expression are comma-separated, meaningful commas (in $input or/and $separator ) must be escaped with \
|
Expression | Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gets the substring after the first occurrence of a separator. The separator is not included in the result.
#{substringAfter($input, $separator)}
-
$input
- any string to get a substring from -
$separator
- the string to search for
Tip
|
Since the arguments of the expression are comma-separated, meaningful commas (in $input or/and $separator ) must be escaped with \
|
Expression | Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Encode the input string to Base64 format
#{encodeToBase64($input)}
-
$input
- any string to be encoded to Base64 format
Expression | Result |
---|---|
|
|
Decodes the input string from Base64 format to the regular string
#{decodeFromBase64($input)}
-
$input
- Base64 string to decode
Expression | Result |
---|---|
|
|
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 |
---|---|
|
|
Escapes reserved characters in HTML string
#{escapeHTML($input)}
-
$input
- any string to be escaped
Expression | Result |
---|---|
|
|
Escapes reserved JSON characters: converts any string into one that’s properly escaped for inclusion in JSON as a value.
#{escapeJSON($input)}
-
$input
- any string to be escaped
Expression | Result |
---|---|
|
|
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})}.*`
Calculates the hash using the specified hashing algorithm
#{calculateHash($algorithm, $input)}
Expression | Result |
---|---|
|
|
|
|
|
|
Calculates the resource or file hash using the specified hashing algorithm
#{calculateFileHash($algorithm, $resourceNameOrFilePath)}
Expression | Result |
---|---|
|
|
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
Given I initialize scenario variable `my-data` with value `#{loadResource(/data/body.txt)}`
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|
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
Given I initialize scenario variable `my-data` with value `#{resourceToBase64(/data/body.txt)}`
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')) |
Evaluates groovy script and converts result to a string.
#{evalGroovy($script)}
-
$script
- valid Groovy script to be evaluated
Tip
|
|
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('-'))}`
Represents null
(a.k.a. NULL
). In most case null
means no value (see NULL
in SQL and null
in JSON).
#{null}
Note
|
Null expression can only be evaluated separately. Strings or other expressions with the nested null expression will be completely ignored and not executed. |
null
valueGiven I initialize scenario variable `json` with value `
{
"persons": {
"nemo": null
}
}
`
Then JSON element value from `${json}` by JSON path `$.persons.nemo` is equal to `#{null}`