Skip to main content
As your test suite grows, you’ll want to extract common patterns into reusable code. This keeps tests DRY, readable, and easy to maintain.

Helper Functions

The simplest approach is extracting common actions into helper functions. Create a helpers/ directory for shared utilities:
test/helpers/auth.js
Avoid hardcoding dynamic values in element descriptions. Element selectors should describe the type of element, not specific content that might 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.