Configuring Data-driven Tests Using the Config File
Test Data can be passed to one or multiple tests by editing the config file and then running the test with the CLI, while adding a flag to use the config file in this run.
The Config file code is processed by the CLI that runs the test on the Testim grid, so it is possible to run JS that is supported in Node and not on the browser.
To add test data to a config file:
- Create a config file or edit an existing one.
- Add tests names and data sets (data sets should be in JSON format), by adding them to the
overrideTestData
under thebeforeSuite
hook. All other parts of the config file should remain/be included.
Here is an example of a beforeSuite hook in the configuration file :
beforeSuite: function () {
return {
overrideTestData: {
"Test 1": {user: "dave", password : "123"},
"Test 2": {name: "ryan"}
}
}
} //add comma here if there are more functions after beforeSuite
Here is the same example with 2 datasets for the first test :
beforeSuite: function () {
return {
overrideTestData: {
"Test 1": [{user: "michelle", password : "belle"},
{user: "paul", password : "walrus"}]
"Test 2": {name: "john"}
}
}
} //add comma here if there are more functions after beforeSuite
If the one of the data set parameters is missing from a consequent data set, for example, if the second data set did not include the password (i.e. did not include password: walrus
), Testim will use the parameter data from the first data set (i.e. belle
).
To run a test using the config file:
After creating the config file, pass the config file to the Command Line (CLI) runner as a parameter, while making sure to indicate the path to the file if needed. When you run your test from Testim CLI, the test will run multiple times, in order, each time with a different Data Set.
testim -c "testimConfig.js"
If the test already included data (e.g. that was specified in the visual editor), this data will override the original test data, if the Config file includes the override function naming the specific test.
Updated about 1 year ago