Variables
A variable is named value which can be reused. There are 2 ways to define a variable, explicitly define a variable with value or capture a value from response into a variable.
The variables which defined in earlier step, no matter in setup or testcase or teardown, it will be reusable in later steps.
Defining a variable
A variable definition is written in a list item (ordered or unordered list) in the following syntax:
* variable_name:value
If the value is string, enclose it with double quote. Otherwise, it will be treated as a number. Anyway, if the value cannot be parsed into a number, it will be assumed to be a string.
Example
* id:3
* keyword:"value"
Defining a variable which has a duplicate name will replace the previous definition. The keyword
in the following example yield the value of "another value"
.
Example
* id:3
* keyword:"value"
* keyword:"another value"
Capturing a value into a variable
See Captures.
Using a variable
The variable can be used within the request code block by putting variable name enclosed with {{
and }}
.
Example
* username:"peter"
* password:"1234test"
```http
POST https://fakestoreapi.com/auth/login HTTP/1.1
Content-Type: application/json
Content-Length: 42
{"username":"{{username}}","password":"{{password}}"}
```
The actual request which sent to server will look like this:
POST https://fakestoreapi.com/auth/login HTTP/1.1
Content-Type: application/json
Content-Length: 42
{"username":"peter","password":"1234test"}