As described in the section on working with test data, by convention, OpenTest requires all data to be kept in a directory named
data, in the root of the test repository. However, in many test automation scenarios it is useful, or even necessary to be able to regularly switch between multiple sets of test data. In OpenTest, this can be achieved by creating multiple "execution environments".
Environments allow the tester to override one or more data files from the
data directory for the duration of a single test session.
To create a new environment, a subdirectory must be added in the
data-env directory of the test repository. For example, the test repository depicted below defines two environments:
C:\opentest\test-repo ├── data │ └── config.yaml ├── data-env │ ├── dev │ │ └── config.yaml │ └── prod │ └── config.yaml └── tests └── ...
The test repo described above contains three different versions of the
config.yaml data file. Whenever the
$data("config") syntax in encountered in a test, the
config.yaml data file being referenced will be different, depending on the environment selected when the test session was created:
If no environment was selected, the
test-repo\data\config.yamlfile will be used, as if there were no environments defined.
devenvironment was selected, the
test-repo\data-env\dev\config.yamlfile will be used.
prodenvironment was selected, the
test-repo\data-env\prod\config.yamlfile will be used.
Selecting an environment
Once you have your environment directories created, you can select what environment you want to run against each time you start a new test session. The execution environment can be selected in one of three ways:
The easiest and most common way is to pick the environment from the drop-down in the Create session dialog box, when starting a test session from the OpenTest web UI.
You can create a test session template which has the
environmentproperty populated with the name of the desired environment. Then, start a session based on this template, either from the web UI or through the OpenTest server API.
Create a test session programmatically by calling the OpenTest server API, and populate the
environmentproperty in the JSON payload.