Related Data Across Sheets
Give each row of a data-driven test the one matching row of another sheet or data set, for example each order's own user. A row without exactly one match is not run, and you see why.
Applies to: All editions (it follows data-driven testing; the kinds of data source you can use depend on your plan) · Release 2.0.96.276 or later · Web app / Desktop app
Overview
A data-driven test runs once for each row of its data. Often a row also needs data from somewhere else. An order has a USER_ID, and the request needs that user's email address, which is in the Users sheet.
Related data picks, for each row, the one row of another data set that matches. The order and the user always belong together. Explore the capability at related data across sheets.
Before you begin
- Set up data-driven testing on the test, so that it has its own rows (for example, Orders).
- Save the related data as a saved dataset or a saved data source.
- For an Excel workbook, each sheet is a separate data source. Add the workbook once for each sheet you need, with that sheet's name. Sheets in one workbook are not linked automatically.
- Check that the related data has a column with one distinct value in each row, such as
ID.
Step 1 — Add the related data
- Open the test and select the Data tab.
- On the Data-driven testing card, switch it On.
- In the Related data block, select + Add related data.
- Fill in the one line, which reads like a sentence:
Users where its column
IDequals this row'sUSER_IDasuser
| Part | What to enter |
|---|---|
| Choose the related data… | A dataset under Saved datasets, or a source under Saved data sources (CSV / Excel sheet / DB / API) |
| where its column | The column of the related data to match, such as ID |
| equals this row's | The column of this test's data that holds the key, such as USER_ID |
| as | The name you will use to refer to the matched row, such as user. Use letters, digits and _ only, and do not start with a digit |
A test can declare more than one relation. Each needs its own name.
Step 2 — Check the matches
Select Check matches before you run anything. You see one of these results:
- Every selected row has exactly one matching related row.
- N selected rows will not run: no single matching related row. The first five reasons are listed.
Fix the data, or the column names, and check again.
Step 3 — Use the values
Refer to a column of the matched row in either of these ways:
- Type
{{related.user.EMAIL}}in a path, query parameter, header, body or an assertion's expected value. - In a column binding, use the column name
related.user.EMAIL.
For example, with this data:
Orders: ORDER_ID | USER_ID |
|---|---|
| 9001 | 7 |
| 9002 | 42 |
Users: ID | EMAIL |
|---|---|
| 7 | ana@example.com |
The first row sends ana@example.com. The second row is not run, because no user has the ID 42.
How matching works
- Row selection happens first. The iteration mode and filters decide which rows run. Related rows are matched afterwards, so a relation never changes which rows are chosen.
- Keys are compared as text, with surrounding spaces removed. So
42matches"42". - A match is never guessed. If the key is empty, if no related row has it, or if more than one row has it, that row is not run. The run report gives the reason, for example USER_ID 42: no row of "Users" has ID 42. The other rows run as usual.
- The related data is read once for each run, in full. Keep it to the rows the test needs.
- Columns with names that suggest a secret, such as
passwordortoken, are masked in the run report. - A dataset used as related data appears in that dataset's usage list.
Workflows
A workflow's data can declare related data, but only through the API or the project assistant. The workflow editor has no Data section. Each step can then read {{related.user.EMAIL}}. A workflow in which a row was held back is reported as inconclusive, not passed.
The desktop Agent
On the desktop Agent, the runner reads the related data itself when it can read all the sources (JSON, CSV, XML and API data sets). Otherwise, the server reads both the test's data and the related data.
What is not included
- Each relation matches on one column. You cannot match on several columns together.
- Each row gets one related row. You cannot get all the orders of one user.
- A relation cannot take its key from another relation.
- Relationships between sheets are not detected automatically.
- This is not a database join, and it does not pass data from one test to another.
Troubleshooting
| Symptom | What to do |
|---|---|
| … is empty, so no row of … can be matched. | Fill in the key in that row of the test's data, or filter the row out. |
| … it must match exactly one. | Remove the duplicate keys from the related data, or match on a column with distinct values. |
| No row matches at all | Check the column names on both sides. Keys with different text, such as 007 and 7, do not match. |
| A name may use letters, digits and _ only | Change the name in the as box. |
| … could not be read | Open the dataset or data source and check that it loads. |
Related articles
Related articles
- Data-Driven Testing · Product documentation
- Data Sources · Product documentation
- Fill Tests From a Data Set · Product documentation
Next steps
- Getting started · Install + connect your spec
- Configuration fundamentals · Stabilize runs
- Initial configuration · Users, licensing, projects
- Release notes · Updates and fixes
Still stuck?
Tell us what you’re trying to accomplish and we’ll point you to the right setup—installation, auth, or CI/CD wiring.