Data Driven Testing lets you define global parameters in your test and use it from any step. You can define multiple ordered Data Sets and have the test run against each Set separately using the Testim CLI.

Adding and using Test Data in your tests

  • Test Data is added from within a test, as a property of the Setup step using the JS editor.
  • A DataSet is defined by a JS Object literal.
  • Multiple ordered Data Sets are defined by a JS Array literal of objects.
  • Testim CLI custom run parameters override the value of a parameter defined in a DataSet that was previously defined in the Testim Editor.
  • When you run your test from Testim CLI, the test will run multiple times, in order, each time with a different DataSet.

Popular use cases for Data Driven Testing

  • Run a signup test with different data - when you want to test your signup page with different username and password, you can use Test Data and Conditions to build one test in Testim, that run several times with different username and password negative or positive.
  • Read\inject data from database - when you want to inject data into the database and then pass the data that was generated by the test. To generate the data you can use Testim CLI hooks and after injection of the data was successfully completed you can pass the data to your test.

How to use Data Driven Testing?

Test Data can be added to a test by choosing "Set dynamic data..." in the setup step's properties panel.

  

1. CREATE A TEST.

Our test is composed of:

  • Navigation to the login page
  • Set username
  • Set password
  • Click on login button
  • Validate message text

2. ADD TEST DATA BY CLICKING ON SETUP STEP AND OPENING THE PROPERTY PANEL.

3. CLICK "SET DYNAMIC DATA...." IN THE PROPERTIES PANEL.

JS Editor should be opened:

4. DEFINE THE DATA SET IN THE JS EDITOR

This is the DataSet we defined in the example:

return [{
  "username": "tomsmith",
  "password": "SuperSecretPassword!"
},{
  "username": "david",
  "password": "SecretPassword?"
}];

Note: The brackets must remain in the return line.

5. EDIT "SET USERNAME" AND "SET PASSWORD" STEPS

Once the DataSet was defined, go back to attach it to the relevant inputs: "Username" and "Password":

  • Edit step by clicking the "Set username" step and open its property panel.
  • Replace the text in "Text to assign" with username parameter.
  • Edit step by clicking the "Set password" step and open the property panel.
  • Replace the text in "Text to assign" with password parameter

6. RUN YOUR TEST:

The test run successfully with the first Data Set:

"username": "tomsmith","password": "SuperSecretPassword!"

Note: Running the test from the editor will only run the first data set. When you want to run all the data sets use CLI/scheduler.

Run test with Test Data via Testim CLI

  1. Install Testim CLI.
  2. Run test via Testim CLI
  3. Go to runs page and go to the suite that you just run.
  4. You can see the run result with the DataSet per test when you hover the "i" icon in the right side.

  

Test Data can be changed from the CLI for a specific run by using a Custom Run Parameters. The parameters object will be merged into the current DataSet replacing any previously defined parameter.

Setting Cookies

You can also define your cookies with using the reserved 'cookies' parameter. 

Read all about the setting cookies options here

Did this answer your question?