Pass parameters to tests are similar to JavaScript parameters defined in a test scope. They are used to define dynamic values inside your test which vary by your test environment. e.g. set different login credentials (username and password) when you test locally and when testing in your CI.

How to pass parameters to a test

Parameters are passed to your test using the CLI. You can pass them globally for all the tests in a single run using a JSON file or using before hooks in the Config file.

JSON Parameters File

The JSON parameters file is defined locally in your CI and passed to the CLI as an argument. To use it do:

  1. Create your parameter JSON file.

JSON

{
  "username": "david",
  "password": "123"
}
  1. Pass it to Testim CLI as an argument:  --params-file

Shell

testim --label "<YOUR LABEL>" --token "<YOUR ACCESS TOKEN>" --project "<YOUR PROJECT ID>" --grid "<Your grid name>" 
--params-file <PARAM FILE NAME e.g. params-file.json>

Note:  For the grid name, read here how to set up your grid.

Configuration File - beforeSuite / beforeTest hooks

By returning an object from the beforeSuite/beforeTest functions inside the Configuration File you are defining a Suite/Test specific parameters

JavaScript

exports.config = {
  .....
  .....

  beforeSuite: function (suite) {
    console.log("beforeSuite", suite);

    return {
      "username": "David",
      "password": 123
    }
  },

  beforeTest: function (test) {
    console.log("beforeTest", test);
   
    return {
      "username": "David",
      "password": 123
    }
  }

  .....
  .....
};

How to use parameters inside your test

  1. Create or edit JavaScript Validation or Action
  2. The parameter will be available inside the Action/Validation scope.

For example:

JavaScript

// This validation will fail if passing parameter "username" will not be equal to "David".

return username === "David";
Did this answer your question?