Writing Tests
Lifecycle Hooks
Use beforeAll, beforeEach, afterEach, and afterAll to manage setup without hiding test intent.
Use hooks carefully
Lifecycle hooks are useful for shared setup, but they can make test behavior harder to see. Use them for clear technical preparation such as creating temporary data, starting a test server, or cleaning artifacts.
beforeEach and afterEach
Use `beforeEach` for setup every test needs. Use `afterEach` for cleanup that must happen even after failure. Do not hide important user actions such as login unless the suite has a clear helper and the test name still communicates the state.
Run-level setup
`beforeAll` and `afterAll` should be reserved for expensive setup that can be shared safely. If shared state causes flakes, move it closer to the individual test.
const { beforeEach, afterEach, test } = require('orbittest');
beforeEach(async ({ orbit }) => {
await orbit.open('https://app.example.com');
});
afterEach(async ({ testInfo }) => {
console.log(testInfo.name, testInfo.status);
});
Practical checklist
- Keep the workflow readable enough that a QA engineer, developer, or product teammate can understand the intent without opening application source code.
- Prefer user-visible names, stable configuration, and clear evidence over hidden assumptions or brittle implementation details.
- Run the smallest useful check locally before adding it to CI, then verify that failures produce screenshots, logs, traces, or reports that explain what happened.
- Review this part of the suite regularly so outdated examples, stale setup, and obsolete workarounds do not reduce trust in the automation.
Common mistakes to avoid
- Do not add automation only to increase test count. Each page and test should protect a clear user journey, release risk, or debugging need.
- Do not hide important behavior inside helpers so deeply that the test no longer explains what the user is doing.
- Do not rely on fixed sleeps when the application can expose a meaningful ready state such as visible text, URL change, element availability, or completed evidence capture.
- Do not ignore failing artifacts. A report, screenshot, trace, or log entry should feed back into better product code, better waits, or clearer test data setup.
Was this page useful?
Your response is saved in this browser and helps shape the docs experience.