Getting started with data-driven testing

Create a test with data-driven variables and generate a DataTable to reuse the test with different sets of input

If you need to test functionality in your app that uses multiple sets of data, such as localization, search validation, or shipping totals by location, data-driven testing can help save you time. Instead of manually testing every variation, you can create just one test and reuse it with a different set of input each time by using a DataTable.

This tutorial illustrates how to set up a data-driven test in mabl, from creating a test to building a DataTable to running the same test multiple times to achieve test coverage at scale.

📘

Before you start

If you haven't familiarized yourself with the mabl Trainer, we recommend completing the tutorial Getting started with browser tests before you complete this tutorial.

Test with data-driven variables

In this tutorial, you will create a test that validates search functionality in Wikipedia for different languages.

test output page for a data-driven test

Output from a data-driven test

Before you start the tutorial, go to Configuration > Applications to set up your workspace:

  • Create a new environment and give it the name "Demo." If you've already created a "Demo" environment for another tutorial, you can skip this step.
  • Create a new application named "Wikipedia" - https://www.wikipedia.org/ - and assign it to the "Demo" environment.

Create a new browser test

Create a new browser test, select "No plan", and associate the test with the new Wikipedia application that you just created.

👍

Naming conventions and labels

With your team, discuss what naming conventions and labels you can use to distinguish practice tests from other tests in your workspace. Consider the examples below:

  • Naming conventions: "Walkthrough - data-driven test - Your name"
  • Labels: "tutorial", "walkthrough", or "practice are good labels for distinguishing your practice tests.
new browser test form

Creating a new test

Click Create test to launch the mabl Trainer.

Train your test

With the record button on, record the following test steps to validate Wikipedia search functionality in Spanish:

  1. Click on the language picker in the search bar, select "Español", and click on the search button:
gif recording steps in Trainer

Selecting a language for search

  1. Assert that the header text equals "Buscar":
gif recording an assertion

Asserting the text in the header

  1. Assert that the placeholder text in the top search bar equals "Buscar en Wikipedia":
gif recording assertion on placeholder text

Asserting placeholder text

Create data-driven variables

The steps that you recorded validate attributes of Wikipedia search in Spanish. To validate search functionality for other languages, you need to create data-driven variables.

Click on the {x} button at the bottom of the Trainer window and select "Manage variables."

variables menu for selecting actions

Opening the Variables modal

In the Variables modal, click on the Data driven variables button.

arrow pointing to data driven variables button in the variables modal

Adding data-driven variables

In the data-driven variables modal, click on the + New variable button to create three new data-driven variables with default values in Spanish:

  • "language_code" - "es"
  • "search" - "Buscar"
  • "placeholder" - "Buscar en Wikipedia"
Data-driven variables modal with new variables

Creating data-driven variables

Click the Apply button to create the variables.

Update test steps

Now you can update your test steps to use data-driven variables instead of static values.

Instead of selecting "es" from the language picker, edit the step to select the value of the data-driven variable "language_code":

gif showing step edit

Editing the language picker

Instead of asserting that the header is "Buscar", edit the step to assert that the header's text equals the value of the data-driven variable "search":

gif showing step edit

Editing the header assertion

Instead of asserting that the placeholder text in the search bar equals "Buscar en Wikipedia", edit the step to assert that placeholder text equals with the value of the data-driven variable "placeholder":

gif showing step edit

Editing the placeholder text assertion

Play through the steps from the beginning to ensure the test still works as expected. Then save the test and close the Trainer.

Create a DataTable

On the Test Details page, open on the Data-driven variables panel to view the data-driven variables you just created. Click on the Generate DataTable button to create the DataTable.

arrow pointing to the generate datatables button

Generating a new DataTable

📘

Creating DataTables

In addition to generating a DataTable from existing data-driven variables, you may also create a DataTable by going to Configuration > DataTable and clicking on the + New table button.

On the Add New DataTable page, click on the Add scenarios button to add more languages. DataTables can handle up to 500 scenarios, but for this tutorial, it is sufficient to create three scenarios.

For example, to add English and Japanese scenarios, add in the values from the following table:

Scenariolanguage_codeplaceholdersearch
EnglishenSearch WikipediaSearch
JapanesejaWikipedia内を検索検索

Save the DataTable and return to the test you created for this tutorial.

datatable showing three scenarios

Adding scenarios to a new DataTable

Run DataTable scenarios

You trained the test and associated it with a DataTable. Now you're ready to run the scenarios!

Click on the Run test button in the top right corner. In the Cloud run tab, toggle on "Run DataTable scenarios" and "Run all scenarios."

arrow pointing to the start runs button in the ad hoc run panel

Running all scenarios in a DataTable

Click the Start runs button and watch your tests run in parallel with different data!

Next steps

You've just created your first data-driven test in mabl. :tada: What can you do next?

Expand on the example

What other languages could you add to the Wikipedia search DataTable?

Consider data-driven testing in your application

Based on what you learned about how DataTables work, what testing scenarios might be good candidates for a DataTable in your application?

Learn more

Check out our documentation on data-driven testing here.