Variables Phrases
Variables Configures the Gherkin parser with phrases that support operations on variables
Item Index
Methods
- Assert Javascript
- Assert JSON path matches RegExp
- Assert JSON path matches RegExp
- Assert variable is truthy
- Assert variable matches a value exactly
- Assert variable matches RegExp
- Assert variable matches RegExp
- Assert variable value contains some string
- Clear Variables
- Execute Javascript
- Save Javascript to Variable
- Set Variable
- Set Variable from CSV
- Set Variable from JSON
Methods
Assert Javascript
-
javascript
Assert some Javascript returns true or trigger a fail if return is 'falsey'
Parameters:
-
javascriptString- inline javascript
Example:
GIVEN I am testing
THEN I assert this.name == "testing"
Assert JSON path matches RegExp
-
path -
varname -
regex
Assert that any array element in JSON path within a variable should match a regular expression (RegExp)
$.hello in $varname should match $regex
Parameters:
-
pathString- a valid JSON path
-
varnameString- scoped variable
-
regexString- regular expression
Example:
GIVEN I set variable my.hello to world
THEN any $.hello in my should match a-z
Assert JSON path matches RegExp
-
path- -
varname -
regex
Assert some JSON path within a complex variable should match a regular expression (RegExp)
$.hello in $varname should match $regex
Parameters:
-
path-StringJSON path
-
varnameString- scoped variable
-
regexString- regular expression
Example:
GIVEN I set variable my.hello to world
THEN $.hello in my should match a-z
Assert variable is truthy
-
varname
Assert some variable is assigned a value that is truthy
variable $varname should exist
Parameters:
-
varnameString- scoped variable
Example:
GIVEN I set variable hello to world
THEN variable hello should exist
Assert variable matches a value exactly
-
varname -
value
Assert some variable should match an exact value
variable $varname should be $value
$varname should be $value
$varname equals $value
$varname is $value
$varname = $value
Parameters:
-
varnameString- scoped variable
-
valueString- expected value
Example:
GIVEN I set variable hello to world
THEN variable hello should exist
Assert variable matches RegExp
-
varname -
regex
Assert some variable should match a regular expression (RegExp)
variable $varname should match $regex
Parameters:
-
varnameString- scoped variable
-
regexString- regular expression
Example:
GIVEN I set variable hello to world
THEN variable hello should match a-z
Assert variable matches RegExp
-
varname -
regex
Assert some JSON path should match a regular expression (RegExp)
variable $varname should match $regex
Parameters:
-
varnameString- scoped variable
-
regexString- regular expression
Example:
GIVEN I set variable hello to world
THEN variable hello should match a-z
Assert variable value contains some string
-
varname -
value
Assert some variable should contain a value
variable $varname should contain $value
Parameters:
-
varnameString- scoped variable
-
valueString- expected value
Example:
GIVEN I set variable hello to world
THEN variable hello should contain orl
Clear Variables
()
Remove all the scoped variables
I clear variables
I reset variables
Example:
GIVEN I reset variables
Execute Javascript
-
javascript
Execute Javascript - trigger a fail if return is falsey
Parameters:
-
javascriptString- inline javascript
Example:
WHEN I execute (3+4)
Save Javascript to Variable
-
javascript -
varname
Run Javscript and save result into a variable
Parameters:
-
javascriptString- inline javascript
-
varnameString- variable name
Example:
GIVEN I return 2+3 as my-answer
AND I return new Date().getTime() as now
Set Variable
-
variable -
value
Set the value of a scoped variable
I set $varname to $value
I set $varname = $value
I define $varname = $value
I define $varname is $value
Parameters:
-
variableString- variable name
-
valueObject- simple value (string | number | boolean)
Example:
GIVEN I set hello to world
AND I set yes to true
AND I set nope to false
AND I set answer to 42
Set Variable from CSV
-
name -
CSV
Sets the value of a scoped variable to inline CSV data structure
I set $varname to CSV:
-------------
$CSV
-------------
some $varname as CSV:
-------------
$CSV
-------------
Parameters:
-
nameString- variable name
-
CSVString- inline CSV text
Example:
GIVEN I set my-csv to CSV:
-------------
hello, goodbye
world, earth
-------------
or:
AND some CSV as my-csv:
-------------
hello, goodbye
world, earth
-------------
Set Variable from JSON
-
name -
JSON
Sets the value of a scoped variable to inline JSON data structure
Parameters:
-
nameString- variable name
-
JSONObject- inline JSON
Example:
GIVEN I set $varname to JSON:
-------------
{ "hello": "world" }
-------------
or:
AND some JSON as $varname:
-------------
{ "hello": "world" }
-------------
