- Helper functions wrap one flow, such as signing in.
- Page objects group every action for one screen in a class.
testdriver client as an argument, so they work in any test.
Write a helper function
Put the shared steps in a function that takes the client. This helper signs in to the TestDriver demo store:tests/helpers/auth.js
tests/cart.test.mjs
find(), so the cache can match them on every run.
Group actions with a page object
A page object is a class with one method per action on a screen. Use one when many tests work with the same screen.tests/pages/login-page.js
tests/login.test.mjs
Organize your files
A layout that keeps shared code apart from tests: By default, Vitest runs only files named*.test.* or *.spec.*, so helpers, page objects, and fixtures aren’t run as tests.
Next steps
Use variables and test data
Feed helpers with environment variables and fixtures.
Use secrets
Keep the credentials your helpers type out of logs.
Locate elements
Write descriptions that find the right element.
Click an icon example
A complete test that uses a login helper.

