Variable assignment in YAML configuration

You can define variables within a YAML configuration file 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 "{{...}}", will be 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 using all the three methods, the variables assigned 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 utilized throughout the YAML file to configure the tool.

2. Environmental variables

You can override the values of variables configured in the YAML file 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 using the --config-file or -c flag when running the CLI tool. Any variables defined in the external configuration file will supersede those defined within the main YAML file or through the environmental variables.

For example, consider an external configuration file named 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 defined in theconfig.yaml file will replace 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.