Skip to main content
When your test suite becomes larger, put the common patterns into reusable code. This keeps the tests short, easy to read, and easy to keep.

Helper Functions

The most simple method is to put the common actions into helper functions. Make a helpers/ directory for the shared utilities:
test/helpers/auth.js
Do not put dynamic values in element descriptions. An element selector must describe the type of the element. It must not describe specific content that can change.❌ Bad: await testdriver.find('profile name TestDriver in the top right')
✅ Good: await testdriver.find('user profile name in the top right')
Hardcoded values like usernames, product names, or prices will cause tests to fail when the data changes. Use generic descriptions that work regardless of the specific content displayed.
Now import and use these helpers in any test:
test/checkout.test.mjs

Page Objects

For larger test suites, the Page Object pattern encapsulates all interactions with a specific page or component:
test/pages/LoginPage.js
Use the page object in your tests:
test/auth.test.mjs

Shared Test Fixtures

Create reusable fixtures for common test setup scenarios:
test/fixtures/index.js
test/admin.test.mjs

Suggested Project Structure

Start simple with helper functions. Only introduce page objects when you find yourself duplicating the same element interactions across multiple tests.