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.

You can configure a YAML file in three ways:
  • Using the same YAML file.
  • Using environmental variables
  • Using the external configuration YAML files.
Note: Variables must be enclosed in double curly braces. For example, "{{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:

  1. External configuration YAML file (highest precedence)
  2. Environmental variables
  3. Configuration set in the same YAML file (lowest precedence)
If you configure a YAML file by using all the three methods, the variables that are assigned by using the external configuration YAML file is given priority.

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.