π Frontend Tests Overview (Playwright)
LibreFolio's frontend tests use Playwright to drive a real browser and interact with the application exactly as a user would.
π§° Tools & Framework
| Tool | Role |
|---|---|
| Playwright | Browser automation engine (Chromium, headless by default) |
@playwright/test |
Test runner with test(), expect(), fixtures |
page |
Playwright's page fixture β represents a browser tab |
expect |
Assertion library with auto-retry and web-first semantics |
βοΈ How Tests Work
Each test file (.spec.ts) contains scenarios that:
- Navigate to a URL (
page.goto('/fx')) - Interact with elements (
page.click(),page.fill(),page.getByRole()) - Assert outcomes (
expect(page.getByText('EUR/USD')).toBeVisible())
Playwright automatically waits for elements and retries assertions, making tests resilient to timing issues.
// Example: verify broker creation
test('create a new broker', async ({ page }) => {
await page.goto('/brokers');
await page.getByRole('button', { name: 'New Broker' }).click();
await page.getByLabel('Name').fill('My Broker');
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByText('My Broker')).toBeVisible();
});
π€ Automated Setup
When you run a frontend test category, dev.py handles everything automatically:
- Builds the frontend β Runs
front buildto produce a production build - Starts the backend β Launches the FastAPI server in
--testmode (isolated test database atbackend/data/test/) - Serves the frontend β The backend serves the built frontend at
http://localhost:8001 - Runs Playwright β Executes the test specs against the live application
- Tears down β Stops the server after tests complete
Test isolation
Test mode uses a completely separate database (backend/data/test/sqlite/app.db). Your production data is never touched.
π Flags
Frontend test categories (front-utility, front-user, front-fx) support these flags:
| Flag | Effect | When to Use |
|---|---|---|
--headed |
Opens a visible browser window instead of headless | Watch the test flow visually, debug layout issues |
--debug |
Enables Playwright Inspector β pauses before each action | Step through actions one by one, inspect selectors, set breakpoints |
--ui |
Opens Playwright UI Mode β a full interactive test runner | Explore tests interactively, view timeline/trace, re-run selectively |
--list |
Lists available test files without running them | Discover tests, verify naming, plan what to run |
π¨ Playwright UI Mode (--ui)
The UI mode provides a rich interactive experience:
- Timeline view β See every action (click, fill, navigate) on a visual timeline
- DOM snapshot β Inspect the page state at any point during the test
- Network tab β Monitor API calls and responses
- Re-run β Click to re-run a single test or a filtered subset
- Filter β Filter by file name, test title, or
describeblock
π Test Categories
| Category | Command | What's Tested |
|---|---|---|
| Front-Utility | ./dev.py test front-utility all |
Auth, settings, files, select, image-crop |
| Front-User | ./dev.py test front-user all |
Brokers, multi-user, sharing |
| Front-FX | ./dev.py test front-fx all |
FX list, detail, add-pair, editor, sync |