How to store metadata of environments in TFML
Testfully 1.179.0
introduced the support for file-based workspaces using Testfully Markup Language. This article demonstrates how to persist metadata for environments in TFML.
Defining environments in TFML
An environment in Testfully is more than just a set of variables and values. Environments can carry settings such as authorization scheme, SSL verification settings, timeout and more. File-based environments are part of a file-based workspace and are stored in the environments
folder within the workspace folder. Each environment is represented by a .toml
file, which can have any name you choose.
The .toml
file can contain the following fields:
Field | Type | Description |
---|---|---|
name | String | The name of the environment. |
variables | Key-Value Pairs | A list of environment variables and their corresponding values. |
timeout | Integer | Request timeout in seconds. |
redirects | Boolean, Integer | Whether to follow HTTP redirects. |
secure | Boolean | Verify SSL certificates. |
insecure | Boolean | Do not verify SSL certificates. |
history | String | Save request history when using this environment. |
name
field
The name
field is a string that defines the name of the environment. It is mandatory.
Example below defines an environment named "Development":
# Development.tomlname = "Development"
When an environment file does not have a name
field, the name of the environment will be derived from the file name. For example, a file named Staging.toml
will create an environment named "Staging", while a file named production.toml
will create an environment named "production".
variables
field
The variables
field is a key-value pair that defines the environment variables for the environment. Each variable must have a unique name.
Example below defines two environment variables, api_key
and base_url
:
# Development.toml[variables]api_key = "your_api_key"base_url = "https://api.example.com"
Disabling an environment variable
Say you want to temporarily disable the api_key
environment variable without removing it from the Development.toml
file. You can prefix the variable with a -
to disable it.
Example below disables the api_key
environment variable:
# Development.toml[variables]-api_key = "your_api_key"base_url = "https://api.example.com"
This will prevent the api_key
variable from being used in requests, while still allowing it to be easily re-enabled later by removing the -
prefix.
timeout
field
The timeout
field is an integer that defines the request timeout in seconds when using this environment. If not specified, the default timeout of 30 seconds will be used.
Example below sets the timeout to 60 seconds:
# Development.tomlname = "Development"timeout = 60
redirects
field
The redirects
field can be either a boolean or an integer. If set to true
, Testfully will follow HTTP redirects when using this environment. If set to an integer value, it defines the maximum number of redirects to follow. If not specified, the default behavior is to follow redirects up to 10 times.
Example below sets the maximum number of redirects to 5:
# Development.tomlname = "Development"redirects = 5 # follow up to 5 redirects but not more.
secure
field
The secure
field is a boolean that defines whether to verify SSL certificates when using this environment. If set to true
, SSL certificates will be verified. If not specified, the default behavior is to verify SSL certificates.
Example below enables SSL verification:
# Development.tomlname = "Development"secure = true
insecure
field
The insecure
field is a boolean that defines whether to skip SSL certificate verification when using this environment. If set to true
, SSL certificates will not be verified. If not specified, the default behavior is to verify SSL certificates.
Example below disables SSL verification:
# Development.tomlname = "Development"insecure = true
history
field
The history
field is a string that defines whether to save request history when using this environment. By default, request history is saved. You can provide one of the following values to control history saving:
"do_not_store"
: Do not save request history."store"
: Save request history (default behavior).