Random variables in DataTables

In data-driven testing, you will typically want to test deterministic scenarios that verify the application under test always produces the same output given a specific set of inputs (e.g. 12 + 30 = 42). Nevertheless, there may also be situations in which you wish to test non-deterministic scenarios using random values. You can use random values with mabl datatables in the following way.

Your workflow

  1. Create a DataTable and use random string templates as variable values.
  2. Create a test and associate the DataTable with it
  3. Use the random variables with mabl Trainer just like any other variable in the DataTable
  4. Run the test from the mabl app to validate everything works as expected

DataTable with random string templates

In the following datatable example, we have two variables and seven scenarios for each variable. The randomString variable is assigned a string template value for each scenario while the staticString variable has just static values.


mabl datatable using random string templates

When you run a test using the randomString variable from that DataTable, mabl will assign a different random value to that variable according to the string template specified for the scenario.

Use the variables in the mabl Trainer

You can use random variables from a DataTable in the same way as using any other DataTable variable. Associate the DataTable with your test and use the mabl Trainer to enter the variable value into an input field in your application or assert against it.

If things are working correctly, mabl should input a random value generated based on the specified string template for the variable in the DataTable.

Note that only the first DataTable scenario variable values are used when replaying steps in the Trainer. Run the test as a part of a plan to see test results from all data-driven scenarios.


Running data-driven test scenarios as part of a plan.

To verify that everything works, review the test results for one of the scenarios in the plan. You should see the generated random values in the run results.


Test results showing the generated random value for the randomString variable

Did this page help you?