← ClaudeAtlas

testdriverreusable-codelisted

Build maintainable test suites with reusable code patterns
testdriverai/testdriverai · ★ 242 · Testing & QA · score 73
Install: claude install-skill testdriverai/testdriverai
<!-- Generated from reusable-code.mdx. DO NOT EDIT. --> 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: ```javascript test/helpers/auth.js export async function login(testdriver, { email, password }) { const emailInput = await testdriver.find('email input'); await emailInput.click(); await testdriver.type(email); const passwordInput = await testdriver.find('password input'); await passwordInput.click(); await testdriver.type(password); const loginButton = await testdriver.find('login button'); await loginButton.click(); const result = await testdriver.assert('user is logged in'); return result; } export async function logout(testdriver) { const userMenu = await testdriver.find('user menu'); await userMenu.click(); const logoutButton = await testdriver.find('logout button'); await logoutButton.click(); } ``` <Warning> **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 test