Test data shared between tests
Pass values between the tests of a suite, such as a user one test registers or an order number another creates, and keep every test working on its own.
Tests in a suite often depend on each other. Test 1 registers a user, test 2 creates an order, test 3 checks the order list, and test 4 signs in as the new user. Test data passes those values between the tests of a suite run.
Test data is on for new workspaces. If you don't see the button in the step editor or a Test data section on your suites, ask us to turn it on for your workspace.
The rule
A suite has its own test data. Every test in one run of the suite sees the same values. A test played on its own uses its own defaults.
When a step needs a value, it gets:
- the value saved by an earlier step in this run, from this test or an earlier test in the suite,
- otherwise the suite's value, set on the suite's Test data section,
- otherwise the test's own default.
ReplayQA suggests it for you
You usually don't need to set any of this up. When you review a test made from a video, a Suggestions list at the top offers it in plain words, one click each:
"Each run should use a new username." Your video registered
demo-user-3, and replaying it as-is would fail with "already exists". Apply makes each run typedemo-user-followed by a new random word, and keeps that value for the tests after it."'demo-user-3' is the username Register user creates. Use the one it creates in each run?" Apply makes this test use the value that test creates in each run. If Register user doesn't make a new one each run yet, it gets a new draft that does. Its approved version keeps running until you approve that draft.
"'48213' is the order number your app shows after 'Place order' in Create order." When the video of another test showed your app creating a number or code (an order number, a reference, an id in the address), Apply makes that test save it in each run and this test use it.
Nothing changes until you press Apply. Not now hides a suggestion for that test. Passwords are never suggested.
Use a value in a step
In the step editor, press next to what to type, a page address, an expected result, an element's wording, or a table row. Pick a value, or choose New value… and give it a name, such as username or order_no. The step then shows the value as a chip.
To act on the row of a record an earlier test created, for example the Edit button in that order's row, open the step's Advanced settings and press next to Only in the table row showing. The step then looks only in the row that shows that run's value. Checks have the same field under their ⚙.
The text the field held before, for example the name you typed in your video, becomes the value's default. Defaults are listed in the Test data panel above the steps. A default is needed for every value the test uses before one of its own steps saves it, so the test can still run on its own and be validated.
For a saved login, enter {{secret:NAME}} as the default, for example {{secret:USER_EMAIL}}. Logins are typed like passwords and never shown. They can only be typed into fields, not looked for on screen.
Save a value from a step
Open a step's Advanced settings and fill in Save a value from this step:
| From | Saves | Example |
|---|---|---|
| What it typed or chose | the value a Type or Choose option step entered | the new username |
| The element's text | the text of the step's element, after the step | "Order #48213 created" |
| The field's value | what a field contains | an automatically filled reference code |
| The page address | the address after the step | /orders/4821 |
| Text on the page | a value anywhere on the page after the step, picked out by a pattern | Order number\W+(\d+) keeps 48213 from "Order number: 48213" |
Only the part matching keeps just part of it, using a regular expression. #(\d+) keeps 48213 from "Order #48213 created", and /orders/(\d+) keeps 4821 from the address. To save the text of something on the page without clicking it, use a Wait for step on it.
Later steps of the same test, and later tests in the suite run, can use the saved value. Values from passwords and other sensitive fields can't be saved, because saved values are shown on the run page.
Suite values
Open a suite's Test data section to see every value its tests use or save: which test saves it, which tests use it, and warnings such as a value used before it's saved. You can also give the suite its own values:
- New each run, such as
user-{word}@test.com.{word}becomes a random word that's the same for every test in the run and new in each run. - Fixed text, such as a record that already exists on your test site.
- A saved login, such as
USER_EMAIL.
A value saved by a step still comes first. Tick If the test that saves this value fails, use this value instead to let the later tests carry on with the suite's value.
When the test that saves a value fails
If an earlier test should have saved a value but failed before it did, the tests that need the value are skipped, with a message naming the value and the test. Tests that don't need it still run. Retry failed re-runs the failed test and the skipped ones, in order.
Signing in as a user a test registered
Sign-in tests get the run's values too. To sign every test in as the user test 1 registers:
- In the registration test, type the email with a New each run value, or save it with What it typed or chose as
user_email. - In your sign-in test, use
{{data:user_email}}for the email, with your usual test account as the default, for example{{secret:EMAIL}}.
In the suite, every test that replays that sign-in signs in as the new user. Played on its own, it signs in with the default account. See Test logins and passwords.
On the run page
Each test's run lists the values it used and where each came from: saved by an earlier test, the suite's value, or its default. It also lists the values it saved for the tests after it.
Unique words still work
{{unique}} and {{unique:NAME}} work as before. The suite's Test data section lists {{unique:NAME}} words too, so you can see which tests share them. Test data adds what unique words can't do: values your app creates, such as order numbers and ids, defaults so tests run on their own, and signing in as a new user.