Test data is kept apart from test logic. This guide says where each kind of value belongs and how tests stay independent of each other.
| Kind of value | Location | Example | Changes per environment? |
|---|---|---|---|
| Environment settings | config/environments/<env>.json |
baseUrl, readOnly |
yes |
| Application knowledge | src/data/*.js |
routes, expected menu items, expected messages | no |
| Credentials | environment variables (.env, CI secrets) |
E2E_USERNAME, E2E_PASSWORD |
yes |
| Per-run values | generated inside the test | unique record names | per run |
Rule of thumb: if the value would differ between environments, it belongs in the environment file or in an
environment variable. If it describes the application and is the same everywhere, it belongs in src/data.
Use the testData fixture, which returns the src/data module:
test(
"Verify main menu lists all modules",
{ tag: [TAGS.INTEGRATION, TAGS.PROD] },
async ({ dashboardPage, testData }) => {
await expect(dashboardPage.menuItems).toHaveText(testData.dashboard.menuItems);
}
);Read environment settings through the env fixture, and build URLs with env.url(route):
await expect(page).toHaveURL(env.url(testData.routes.adminUsers));Read credentials through the credentials fixture only in tests that need them. It fails with a clear message when they
are missing, so a test never runs with an empty password.
Independence means that any single test can run alone, in any order, and still pass.
- No shared mutable state. Do not store a value in a module variable and read it in another test.
- Each test sets up what it needs. Use a fixture, a
beforeEach, or the saved session. Do not assume an earlier test created a record. - Clean up what you create. If a test creates a record, it deletes that record in a
finallyblock or anafterEachhook. - Use unique names for created data. Include a run identifier so parallel runs do not collide, for example
`qa-${Date.now()}`. - Prefer existing data for reads. Searching for a known account is more stable than creating one for every run.
- Keep read-only tests read-only. The
@prodrule in tagging depends on it.
The sample suite runs against the public OrangeHRM demo. Its data is shared and reset periodically, so:
- Assertions use stable facts: the account
Adminexists, the menu has the same modules, the login page has the same fields. - Assertions avoid counts that change, such as the number of records. The search test checks that the first row contains the searched name.
- Nothing in the suite creates or deletes records yet. When a test needs to, follow rule 3 above.
- Static application value: add it to the matching object in
src/data/orangehrm.js, or create a new module insrc/data/for a new area of the application. - Environment value: add it to every file in
config/environments/. A key missing from one file fails validation. - Credential: add it to
.env.exampleas an empty variable with a comment. Never add a value.
src/data/a11y.js lists the accessibility rules that already fail on the login page. The accessibility test fails only
on a violation whose rule is not in that list. A regression is caught, and the existing debt stays visible in the file.
When a violation is fixed in the application, remove its entry, so it cannot come back unnoticed.
The framework has no data factories. Add one when a test needs to create records that many tests share. A factory belongs
in src/data/, returns unique values, and cleans up after itself.