|
| 1 | +# E2E Tests for LobeChat |
| 2 | + |
| 3 | +This directory contains end-to-end (E2E) tests for LobeChat using Cucumber (BDD) and Playwright. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +```` |
| 8 | +e2e/ |
| 9 | +├── src/ # Source files |
| 10 | +│ ├── features/ # Gherkin feature files |
| 11 | +│ │ └── discover/ # Discover page tests |
| 12 | +│ ├── steps/ # Step definitions |
| 13 | +│ │ ├── common/ # Reusable step definitions |
| 14 | +│ │ └── discover/ # Discover-specific steps |
| 15 | +│ └── support/ # Test support files |
| 16 | +│ └── world.ts # Custom World context |
| 17 | +├── reports/ # Test reports (generated) |
| 18 | +├── cucumber.config.js # Cucumber configuration |
| 19 | +├── tsconfig.json # TypeScript configuration |
| 20 | +└── package.json # Dependencies and scripts |
| 21 | +
|
| 22 | +## Prerequisites |
| 23 | +
|
| 24 | +- Node.js 20, 22, or >=24 |
| 25 | +- Dev server running on `http://localhost:3010` (or set `BASE_URL` env var) |
| 26 | +
|
| 27 | +## Installation |
| 28 | +
|
| 29 | +Install dependencies: |
| 30 | +
|
| 31 | +```bash |
| 32 | +cd e2e |
| 33 | +pnpm install |
| 34 | +```` |
| 35 | + |
| 36 | +Install Playwright browsers: |
| 37 | + |
| 38 | +```bash |
| 39 | +npx playwright install chromium |
| 40 | +``` |
| 41 | + |
| 42 | +## Running Tests |
| 43 | + |
| 44 | +Run all tests: |
| 45 | + |
| 46 | +```bash |
| 47 | +npm test |
| 48 | +``` |
| 49 | + |
| 50 | +Run tests in headed mode (see browser): |
| 51 | + |
| 52 | +```bash |
| 53 | +npm run test:headed |
| 54 | +``` |
| 55 | + |
| 56 | +Run only smoke tests: |
| 57 | + |
| 58 | +```bash |
| 59 | +npm run test:smoke |
| 60 | +``` |
| 61 | + |
| 62 | +Run discover tests: |
| 63 | + |
| 64 | +```bash |
| 65 | +npm run test:discover |
| 66 | +``` |
| 67 | + |
| 68 | +## Environment Variables |
| 69 | + |
| 70 | +- `BASE_URL`: Base URL for the application (default: `http://localhost:3010`) |
| 71 | +- `PORT`: Port number (default: `3010`) |
| 72 | +- `HEADLESS`: Run browser in headless mode (default: `true`, set to `false` to see browser) |
| 73 | + |
| 74 | +Example: |
| 75 | + |
| 76 | +```bash |
| 77 | +HEADLESS=false BASE_URL=http://localhost:3000 npm run test:smoke |
| 78 | +``` |
| 79 | + |
| 80 | +## Writing Tests |
| 81 | + |
| 82 | +### Feature Files |
| 83 | + |
| 84 | +Feature files are written in Gherkin syntax and placed in the `src/features/` directory: |
| 85 | + |
| 86 | +```gherkin |
| 87 | +@discover @smoke |
| 88 | +Feature: Discover Smoke Tests |
| 89 | + Critical path tests to ensure the discover module is functional |
| 90 | +
|
| 91 | + @DISCOVER-SMOKE-001 @P0 |
| 92 | + Scenario: Load discover assistant list page |
| 93 | + Given I navigate to "/discover/assistant" |
| 94 | + Then the page should load without errors |
| 95 | + And I should see the page body |
| 96 | + And I should see the search bar |
| 97 | + And I should see assistant cards |
| 98 | +``` |
| 99 | + |
| 100 | +### Step Definitions |
| 101 | + |
| 102 | +Step definitions are TypeScript files in the `src/steps/` directory that implement the steps from feature files: |
| 103 | + |
| 104 | +```typescript |
| 105 | +import { Given, Then } from '@cucumber/cucumber'; |
| 106 | +import { expect } from '@playwright/test'; |
| 107 | + |
| 108 | +import { CustomWorld } from '../../support/world'; |
| 109 | + |
| 110 | +Given('I navigate to {string}', async function (this: CustomWorld, path: string) { |
| 111 | + await this.page.goto(path); |
| 112 | + await this.page.waitForLoadState('domcontentloaded'); |
| 113 | +}); |
| 114 | +``` |
| 115 | + |
| 116 | +## Test Reports |
| 117 | + |
| 118 | +After running tests, HTML and JSON reports are generated in the `reports/` directory: |
| 119 | + |
| 120 | +- `reports/cucumber-report.html` - Human-readable HTML report |
| 121 | +- `reports/cucumber-report.json` - Machine-readable JSON report |
| 122 | + |
| 123 | +## Troubleshooting |
| 124 | + |
| 125 | +### Browser not found |
| 126 | + |
| 127 | +If you see errors about missing browser executables: |
| 128 | + |
| 129 | +```bash |
| 130 | +npx playwright install chromium |
| 131 | +``` |
| 132 | + |
| 133 | +### Port already in use |
| 134 | + |
| 135 | +Make sure the dev server is running on the expected port (3010 by default), or set `PORT` or `BASE_URL` environment variable. |
| 136 | + |
| 137 | +### Test timeout |
| 138 | + |
| 139 | +Increase timeout in `cucumber.config.js` or `src/steps/hooks.ts`: |
| 140 | + |
| 141 | +```typescript |
| 142 | +setDefaultTimeout(120000); // 2 minutes |
| 143 | +``` |
0 commit comments