Frontend Robot allows you to use variables which can be reused across your tests. These variables can have a static value or a value that is resolved at runtime using functions or simple expressions. Variables can also be pre-assigned at suite level.
To define a variable in a test, use the Assign Variable
instruction. The instruction takes as input the the following:
An assignment type, which can be one of the following:
An argument, which can be one of the following, depending on the assignment type selected:
Take a look at the following screenshot for an example:
You can use variables in most instruction arguments, including selectors. To do so, simply wrap the variable name within ${
and }
. For example a variable named todo
can be used with the string ${todo}
. The following screenshot shows you how a variable can be included in a Send keys
instruction:
And below you can see the results of the instruction:
Sometimes you may want to use some data that is defined at runtime. The most common use case is having a random string or the current date to be inserted into a form. You can achieve this by using a set of built-in functions.
The format of a function is almost the same of that of a variable with the addition of two parenthesis ()
used to specify a comma-separated list of arguments. For example to generate a random string you can use ${randomString()}
. To render the current date in the format 2018-01-30 you can use ${now('YYYY-MM-DD')}
. The screenshot below shows you an example:
And below is the result of the above instruction:
You can find here a reference of all the available functions
Frontend Robot allows you to use simple logical expressions inside the variable statement. Supported operators are the logical and &&
, or ||
and the ternary operator <condition> ? <then> : <else>
.
TIP: to use a default value in place of a missing variable you can use the expression
${variable || "default value"}
Sometimes it can be useful to use functions and other variables when defining a variable’s value. For example you can define a variable having value Last todo: ${randomSentence()}
.
Let’s show an example in the screenshot below:
This is what we did in the screenshot above:
randomSentence()
functionSend keys
instructionElement Exists
instructionYou can also pre-define a set of variables at suite level. This is explained in a separate article.