Variable assignment in YAML configuration
You can define variables within a YAML configuration file by using the CLI tool. These variables are used to configure various aspects of the tool.
- Using the same YAML file.
- Using environmental variables
- Using the external configuration YAML files.
"{{configs.base_url}}"
or "{{paths.basePath}}"
. These
placeholders, in the format of "{{...}}"
, are replaced with their corresponding
values from the source YAML file, environmental variables, or the external configuration file
depending on the precedence hierarchy.The precedence hierarchy for variable assignment is as follows:
- External configuration YAML file (highest precedence)
- Environmental variables
- Configuration set in the same YAML file (lowest precedence)
1. Configuration set in the same YAML file
You can assign values to variables from within the same YAML file. For this, you must structure your YAML file in the following manner:
configs:
basePath: ...paths:
- basePath: ...
Here, the configs
key is used to define variables such as
basePath
and paths
. These variables can be used throughout the
YAML file to configure the tool.
2. Environmental variables
You can override the values of variables that are configured in the YAML file by using environmental variables. When an environment variable shares the same name as a variable defined in the YAML file, the value of the YAML variable is replaced by the corresponding environment variable. This provides a way to customize configurations externally.
For example, if a variable named base_url
is defined in the YAML file as
"{{configs.base_url}}"
, and its value is replaced by an environment variable named
base_url
. The value of base_url
in the YAML file is overridden by
the value of the base_url
environment variable.
3. External configuration YAML file
The CLI tool supports the highest level of configuration precedence through external
configuration files. To use an external configuration file, you must specify its file path by using
the --config-file
or -c
flag when y the CLI tool. Any variables
that are defined in the external configuration file supersede those defined within the main YAML
file or through the environmental variables.
For example, consider an external configuration file config.yaml with the following content:
external_config:
base_url: https://example.comapi_key: your-api-key
When you run the CLI tool with the --config-file=config.yaml
flag, variables
that are defined in the config.yaml
file replaces the corresponding variables in
the main YAML file or the environmental variables.
For more information about how the test is defined as a YAML file, see Test definition syntax.