Testim Documentation

Welcome to the Testim documentation. You'll find comprehensive guides to help you get started quickly, example code snippets, and tips for being more productive. You will also find details about advanced features that allow you to customize Testim to fit your environment or special testing conditions. Don't worry, we'll support you if you get stuck. Let's jump right in!

Guides    Changelog

Data-driven from CSV & other resources

Learn how to use CSV, DB or other sources to pass test data

Test data from external sources (e.g CSV, DB etc.) can be passed to one or multiple tests with CLI using the config file.

  1. Add a JavaScript function that loads data from an external source into Json objects. Add this function in the beginning of the config file.
  2. Use overrideTestData in the beforeSuite to pass test names and their data sets.
  3. Install the npm package csvtojson in order to use this functionality. See more details here: https://www.npmjs.com/package/csvtojson

Here is an example :

// JS function that loads data from CSV into Json objects

const csvtojson = require("csvtojson");
function loadCsvFile(path) {
    return new Promise((resolve) => {
        return csvtojson()
            .fromFile(path)
            .then(resolve, err => {
                console.error("failed to read csv file", err.message);
                resolve([]);
            });
    });
}

beforeSuite: function () {
    return Promise.all([loadCsvFile('./data.csv'),
    loadCsvFile('./data2.csv'), loadCsvFile('./data3.csv')])
        .then(([jsonObj, jsonObj2, jsonObj3]) => {
            return {
                BEFORE_SUITE: "BEFORE_SUITE",
                overrideTestData: {
                "Test 3": jsonObj,
                "Test 4": jsonObj2,                        
                "Test 5": jsonObj3,                         
                // You can also pass static datasets to tests 
                "Test 6": {name: "ryan"}                    
            }
        }
    });
} //add comma here if there are more functions after beforeSuite

Notes:

  • Test data provided in the beforeSuite() hook in the config file overrides test data provided in the UI.
  • In the csv file the first row (header row) will contain the data keys and will be used as parameter names, and each row afterwards will contain a dataset of values.

Updated 6 months ago

Data-driven from CSV & other resources


Learn how to use CSV, DB or other sources to pass test data

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.