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.
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.
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: New test > Browser test.
- In Basic information, give your test a name that distinguishes it from other tests in the workspace. For example: "Tutorial - data-driven test - <your-name>".
- In Core settings, associate the test with the "Wikipedia" application that you just created.
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:
- Click on the language picker in the search bar, select "Español", and click on the search button:
Selecting a language for search
- Assert that the header text equals "Buscar":
Asserting the text in the header
- Assert that the placeholder text in the top search bar equals "Buscar en Wikipedia":
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."
Opening the Variables modal
In the Variables modal, click on the Data driven variables button.
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"
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":
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":
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":
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.
Generating a new DataTable
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:
Scenario | language_code | placeholder | search |
---|---|---|---|
English | en | Search Wikipedia | Search |
Japanese | ja | Wikipedia内を検索 | 検索 |
Save the DataTable and return to the test you created for this tutorial.
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."
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. 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.