Execution environments


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.

Creating environments

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: dev and prod.

├── 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.yaml file will be used, as if there were no environments defined.

  • If the dev environment was selected, the test-repo\data-env\dev\config.yaml file will be used.

  • If the prod environment was selected, the test-repo\data-env\prod\config.yaml file 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:

  1. 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.

  2. You can create a test session template which has the environment property 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.

  3. Create a test session programmatically by calling the OpenTest server API, and populate the environment property in the JSON payload.