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 building a separate test for every variation, you build one test and supply a different set of input each time by using a DataTable.
In this tutorial, you build a data-driven test that validates Wikipedia search functionality in three languages:
- Design your test data
- Describe the test to the agent
- Review the generated test
- Run every scenario
- Next steps
Before you start
This tutorial assumes you've already created a test with the mabl agent. If you haven't, complete Getting started with browser tests first.
Design your test data
A data-driven test starts with the data, not the steps. Before you describe anything to the agent, decide which values change between runs and lay them out in a DataTable.
For this tutorial, the test validates the same Wikipedia search behavior in Spanish, English, and Japanese. Three values change with the language: the language code you pick from the search bar, the search header, and the placeholder text in the search field.
Go to Configuration > DataTables and click the + New DataTable button. Name the DataTable "Wikipedia languages" and enter the following data:
| Scenario | language_code | search | placeholder |
|---|---|---|---|
| Spanish | es | Buscar | Buscar en Wikipedia |
| English | en | Search | Search Wikipedia |
| Japanese | ja | 検索 | Wikipedia内を検索 |
Save the DataTable.
Scenarios and variables
A DataTable has two dimensions:
- Each column is a variable: a value your test refers to by name instead of hardcoding.
- Each row is a scenario: one complete set of values to run the test against.
The test you're about to build has one set of steps. Running it against this DataTable runs those steps three times, once per scenario.
Describe the test to the agent
Create a new browser test: click New test and choose the Start chatting option. In the prompt field, describe the test.
Visit https://www.wikipedia.org/ and test search in multiple languages. Use the "Wikipedia languages" DataTable to supply the language values.
- Use the DataTable variables for every language-specific value:
- Select the language with the code
{{@language_code}}from the language picker in the search bar.- Click the search button.
- Verify that the search header text equals
{{@search}}.- Verify that the placeholder text in the top search bar equals
{{@placeholder}}.
Submit the prompt. The agent generates a test outline, which you can refine in the chat until it matches what you want. Make sure the Test information box has the following values:
- URL: https://www.wikipedia.org
- DataTable: Wikipedia languages
For more guidance on prompting the agent, including how to reference associated DataTables and credentials, see how to write an effective browser test prompt.
Review the generated test
Go to Agents > Tasks to monitor the agent's progress. When the task status changes to Review, open the task details and review the generated test.
For a data-driven test, the important thing to check is that the steps are parameterized. Look at the three steps that handle language-specific values and confirm each one refers to a variable rather than a literal value. For example, if the test trained on the Spanish scenario:
- The language picker step should select
{{@language_code}}, not "es". - The header assertion should expect
{{@search}}, not "Buscar". - The placeholder assertion should expect
{{@placeholder}}, not "Buscar en Wikipedia".
These DataTable variables are what makes the test data-driven. When the scenario changes, the variable values change with it.
Run every scenario
To verify the test works across all scenarios, take the following steps:
- From the session details page, click the View test button to open test details.
- Click the Run test button in the top right corner.
- In the Cloud run tab, toggle on Run DataTable scenarios and select Run all scenarios.
- Click Start runs.
mabl runs the test three times in parallel, once per scenario, and reports a separate result for each. One set of steps, three languages validated.
Next steps
You've created your first data-driven test in mabl. What can you do next?
Expand on the example
Add more languages to the "Wikipedia languages" DataTable. You don't need to touch the test: any scenario you add is picked up the next time you run all scenarios. Adding coverage to a data-driven test means adding data.
Consider data-driven testing in your application
Now that you've seen how DataTables work, look for places in your own app where you're validating the same behavior against different input, such as user roles, account types, regions, or product configurations. Those are good DataTable candidates.
Learn more
- Building DataTables
- Creating DataTables, including uploading a CSV
- Associating a test with a DataTable
- Running tests with DataTable scenarios
- Agentic test authoring
- Parameterizing a test you've already built
- Create placeholder variables for data-driven tests, then convert them into a DataTable
- Training tests with DataTables in the mabl Trainer
- All data-driven testing documentation