# Playwright Test Helpers This directory contains reusable helper functions for both Magnitude tests and Playwright MCP testing. ## Usage ### In Magnitude Tests ```typescript import { test } from 'magnitude-test'; import { navigateToApp, loginWithBluesky, startConversation, createNodeDraft, publishNode, completeNodePublishFlow, } from '../helpers/playwright-helpers'; test('User can publish a node', async (agent) => { const page = agent.page; // Get Playwright page from Magnitude agent await completeNodePublishFlow(page, 'My test conversation'); await agent.check('Node published successfully'); }); ``` ### In Playwright MCP Use the helper functions directly with the Playwright MCP page instance: ```typescript import { loginWithBluesky, startConversation } from './tests/helpers/playwright-helpers'; // In your MCP session await loginWithBluesky(page); await startConversation(page, 'Hello AI'); ``` ## Available Helpers ### Authentication - `loginWithBluesky(page, credentials?)` - Complete OAuth login flow - `logout(page)` - Logout from application - `isLoggedIn(page)` - Check if user is authenticated ### Navigation - `navigateToApp(page, baseUrl?)` - Go to app home page ### Conversation - `startConversation(page, message)` - Send first message in chat - `waitForAIResponse(page, timeout?)` - Wait for AI to finish responding ### Node Publishing - `createNodeDraft(page)` - Click "Create Node" button - `editNodeDraft(page, title?, content?)` - Modify draft before publishing - `publishNode(page)` - Click "Publish" and wait for success - `completeNodePublishFlow(page, message?, credentials?)` - Full end-to-end flow ## Environment Variables Set these in your `.env.test` file: ```env TEST_BLUESKY_USERNAME=your-test-user.bsky.social TEST_BLUESKY_PASSWORD=your-test-password ``` If not set, helpers will use default values (which will fail for real OAuth). ## Design Principles 1. **Reusability** - Each helper is atomic and can be composed 2. **Reliability** - Helpers wait for network and UI state before proceeding 3. **Flexibility** - Optional parameters allow customization 4. **Error Handling** - Helpers throw clear errors when expectations aren't met