|
| 1 | +# E2E Test Setup Guide |
| 2 | + |
| 3 | +This guide explains how to set up and run the end-to-end (e2e) tests for Otter Blocks. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. **Docker**: Docker must be installed and running |
| 8 | + ```bash |
| 9 | + docker --version |
| 10 | + docker ps |
| 11 | + ``` |
| 12 | + |
| 13 | +2. **Node.js**: Node.js and npm must be installed |
| 14 | + ```bash |
| 15 | + node --version |
| 16 | + npm --version |
| 17 | + ``` |
| 18 | + |
| 19 | +3. **Network Access**: Internet connection is required to download WordPress and dependencies |
| 20 | + |
| 21 | +## Setup Steps |
| 22 | + |
| 23 | +### 1. Install Dependencies |
| 24 | + |
| 25 | +```bash |
| 26 | +npm ci |
| 27 | +``` |
| 28 | + |
| 29 | +This installs all required packages including: |
| 30 | +- `@wordpress/env` - WordPress environment manager |
| 31 | +- `@playwright/test` - Playwright testing framework |
| 32 | +- All other project dependencies |
| 33 | + |
| 34 | +### 2. Install Playwright Browsers |
| 35 | + |
| 36 | +```bash |
| 37 | +npx playwright install chromium |
| 38 | +``` |
| 39 | + |
| 40 | +This downloads the Chromium browser binary required for running tests. |
| 41 | + |
| 42 | +### 3. Start WordPress Environment |
| 43 | + |
| 44 | +```bash |
| 45 | +npm run wp-env start |
| 46 | +``` |
| 47 | + |
| 48 | +This command: |
| 49 | +- Downloads WordPress (if not cached) |
| 50 | +- Creates Docker containers |
| 51 | +- Sets up a test WordPress site at http://localhost:8889 |
| 52 | +- Installs the Otter Blocks plugin |
| 53 | +- Configures test themes and plugins |
| 54 | + |
| 55 | +**Note**: First run may take 5-10 minutes to download WordPress and set up containers. |
| 56 | + |
| 57 | +### 4. Build the Plugin |
| 58 | + |
| 59 | +```bash |
| 60 | +npm run build |
| 61 | +``` |
| 62 | + |
| 63 | +Or for development builds: |
| 64 | +```bash |
| 65 | +npm run build-dev |
| 66 | +``` |
| 67 | + |
| 68 | +### 5. Run E2E Tests |
| 69 | + |
| 70 | +```bash |
| 71 | +npm run test:e2e:playwright |
| 72 | +``` |
| 73 | + |
| 74 | +Additional test commands: |
| 75 | +- `npm run test:e2e:playwright-ui` - Run tests with Playwright UI |
| 76 | +- `npm run test:performance` - Run performance tests |
| 77 | + |
| 78 | +## Troubleshooting |
| 79 | + |
| 80 | +### Network Issues |
| 81 | + |
| 82 | +If you see errors about network unavailability: |
| 83 | +``` |
| 84 | +✖ Could not find the current WordPress version in the cache and the network is not available. |
| 85 | +``` |
| 86 | + |
| 87 | +**Solutions:** |
| 88 | +1. Ensure you have internet connectivity |
| 89 | +2. Check if your firewall allows Docker to access the internet |
| 90 | +3. Try clearing the wp-env cache: `npm run wp-env clean all` |
| 91 | + |
| 92 | +### Docker Issues |
| 93 | + |
| 94 | +If Docker is not running: |
| 95 | +```bash |
| 96 | +# On Linux/Mac |
| 97 | +sudo service docker start |
| 98 | + |
| 99 | +# Or check Docker Desktop application |
| 100 | +``` |
| 101 | + |
| 102 | +### Port Conflicts |
| 103 | + |
| 104 | +If port 8889 is already in use, you can: |
| 105 | +1. Stop the conflicting service |
| 106 | +2. Change the port in `.wp-env.json` (update both `port` and `env.tests.port`) |
| 107 | + |
| 108 | +### Reset Environment |
| 109 | + |
| 110 | +To completely reset the test environment: |
| 111 | +```bash |
| 112 | +npm run wp-env clean all |
| 113 | +npm run wp-env start |
| 114 | +``` |
| 115 | + |
| 116 | +## Test Structure |
| 117 | + |
| 118 | +- **E2E Tests**: `src/blocks/test/e2e/blocks/` |
| 119 | +- **Test Configuration**: `src/blocks/test/e2e/playwright.config.js` |
| 120 | +- **Test Theme**: `test/emptytheme/` |
| 121 | +- **Test Plugins**: `packages/e2e-tests/plugins/` |
| 122 | +- **MU Plugins**: `packages/e2e-tests/mu-plugins/` |
| 123 | + |
| 124 | +## Configuration Files |
| 125 | + |
| 126 | +- `.wp-env.json` - Base WordPress environment configuration |
| 127 | +- `.wp-env.override.json` - Override configuration with additional settings |
| 128 | +- `playwright.config.js` - Playwright test configuration |
| 129 | + |
| 130 | +## Continuous Integration |
| 131 | + |
| 132 | +In CI environments (GitHub Actions), the workflow: |
| 133 | +1. Installs dependencies |
| 134 | +2. Installs Playwright browsers |
| 135 | +3. Starts wp-env |
| 136 | +4. Builds the plugin |
| 137 | +5. Runs e2e tests |
| 138 | +6. Uploads test artifacts |
| 139 | + |
| 140 | +See `.github/workflows/e2e-js.yml` for the complete CI configuration. |
| 141 | + |
| 142 | +## Development Tips |
| 143 | + |
| 144 | +### Watch Mode |
| 145 | + |
| 146 | +For development, you can run tests in watch mode: |
| 147 | +```bash |
| 148 | +npx playwright test --config src/blocks/test/e2e/playwright.config.js --ui |
| 149 | +``` |
| 150 | + |
| 151 | +### Debug Mode |
| 152 | + |
| 153 | +To debug failing tests: |
| 154 | +```bash |
| 155 | +npx playwright test --config src/blocks/test/e2e/playwright.config.js --debug |
| 156 | +``` |
| 157 | + |
| 158 | +### Specific Tests |
| 159 | + |
| 160 | +To run a specific test file: |
| 161 | +```bash |
| 162 | +npx playwright test src/blocks/test/e2e/blocks/accordion.spec.js |
| 163 | +``` |
| 164 | + |
| 165 | +### Screenshots and Videos |
| 166 | + |
| 167 | +Test artifacts (screenshots, videos) are saved to: |
| 168 | +- `artifacts/test-results/` - Test results and failure screenshots |
| 169 | +- `artifacts/storage-states/` - Authentication state |
| 170 | + |
| 171 | +## Common Issues |
| 172 | + |
| 173 | +### Tests Failing After Code Changes |
| 174 | + |
| 175 | +1. Rebuild the plugin: `npm run build` |
| 176 | +2. Restart wp-env: `npm run wp-env restart` |
| 177 | +3. Clear browser cache if needed |
| 178 | + |
| 179 | +### Authentication Issues |
| 180 | + |
| 181 | +The tests use stored authentication state. If you see login failures: |
| 182 | +1. Check `artifacts/storage-states/admin.json` exists |
| 183 | +2. Verify the global setup script runs: `src/blocks/test/e2e/global-setup.ts` |
| 184 | + |
| 185 | +### Timeout Errors |
| 186 | + |
| 187 | +If tests timeout, you can increase the timeout in `playwright.config.js`: |
| 188 | +```javascript |
| 189 | +timeout: 100_000, // 100 seconds (default) |
| 190 | +``` |
| 191 | + |
| 192 | +## Getting Help |
| 193 | + |
| 194 | +- Check test output for specific error messages |
| 195 | +- Review test artifacts in `artifacts/` directory |
| 196 | +- Check Docker logs: `docker logs <container-id>` |
| 197 | +- Verify WordPress is running: http://localhost:8889 |
| 198 | + |
| 199 | +## Cleaning Up |
| 200 | + |
| 201 | +After testing, to stop and remove containers: |
| 202 | +```bash |
| 203 | +npm run wp-env stop |
| 204 | +``` |
| 205 | + |
| 206 | +To completely remove all wp-env data: |
| 207 | +```bash |
| 208 | +npm run wp-env destroy |
| 209 | +``` |
0 commit comments