File size: 6,039 Bytes
60b6623
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# End-to-End Test Suite for PromptAid Vision

This directory contains comprehensive end-to-end tests that validate the complete user experience through the entire application stack.

## 🎯 Overview

These are **true E2E tests** that:
- βœ… Hit the running app over HTTP via real browsers
- βœ… Test complete user workflows from start to finish
- βœ… Validate frontend, backend, and database integration
- βœ… Use real browser automation with Playwright
- βœ… Run against containerized services

## πŸ—οΈ Architecture

```
e2e/
β”œβ”€β”€ docker-compose.e2e.yml    # E2E environment setup
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ pytest.ini              # Pytest configuration
β”œβ”€β”€ conftest.py             # Test fixtures and setup
β”œβ”€β”€ run_e2e_tests.sh        # Test runner script
β”œβ”€β”€ pages/                  # Page Object Models
β”‚   β”œβ”€β”€ base_page.py
β”‚   β”œβ”€β”€ upload_page.py
β”‚   β”œβ”€β”€ explore_page.py
β”‚   └── admin_page.py
β”œβ”€β”€ specs/                  # Test specifications
β”‚   β”œβ”€β”€ upload_flow_spec.py
β”‚   β”œβ”€β”€ admin_settings_spec.py
β”‚   └── export_spec.py
└── fixtures/              # Test data
    └── test_image.jpg
```

## πŸš€ Quick Start

### Prerequisites
- Docker and Docker Compose
- Python 3.8+
- Git

### Run E2E Tests

```bash
# Option 1: Use the automated script
chmod +x run_e2e_tests.sh
./run_e2e_tests.sh

# Option 2: Manual steps
docker-compose -f docker-compose.e2e.yml up -d --build
pip install -r requirements.txt
playwright install
pytest -m e2e -v
docker-compose -f docker-compose.e2e.yml down -v
```

## πŸ§ͺ Test Categories

### 1. Upload Flow Tests (`upload_flow_spec.py`)
- **Complete upload workflow**: File selection β†’ Analysis β†’ Success
- **Invalid file handling**: Error messages for wrong file types
- **Large file handling**: Performance with large images

### 2. Admin Settings Tests (`admin_settings_spec.py`)
- **Authentication flow**: Login/logout with correct/incorrect credentials
- **Schema management**: Admin interface for schema configuration
- **Model configuration**: VLM service configuration
- **System monitoring**: Health checks and monitoring

### 3. Export Tests (`export_spec.py`)
- **Filtered data export**: Export with applied filters
- **Bulk export workflow**: Export multiple selected items
- **Export format validation**: Different export formats
- **Performance testing**: Export with large datasets

## πŸ”§ Environment Setup

### Docker Services
- **PostgreSQL 16**: Test database with health checks
- **MinIO**: S3-compatible storage for file uploads
- **Backend**: FastAPI with mock VLM provider
- **Frontend**: React application with Vite

### Health Checks
- Backend: `http://localhost:7860/health`
- Frontend: `http://localhost:3000`
- Database: PostgreSQL connection check
- MinIO: S3 health endpoint

## πŸ“Š Test Metrics

### What We Measure
- **Flakiness rate**: Test stability and reliability
- **Test duration**: Median and 95th percentile times
- **Critical path coverage**: Key user workflows
- **Failure triage speed**: Debug information availability

### What We Don't Measure
- ❌ Code coverage (not relevant for E2E)
- ❌ Individual test duration targets
- ❌ UI element coverage percentages

## 🎭 Playwright Configuration

### Browser Settings
- **Viewport**: 1920x1080
- **Video recording**: Enabled for all tests
- **Screenshots**: On failure
- **Traces**: Available for debugging

### Auto-wait Strategy
- No explicit `sleep()` calls
- Uses Playwright's built-in auto-wait
- Relies on `expect().toBeVisible()` assertions
- URL-based navigation verification

## πŸ“ Test Data Management

### Data Isolation
- **Per-test reset**: `/test/reset` endpoint (E2E mode only)
- **Volume cleanup**: `docker-compose down -v` after suite
- **Namespaced data**: Unique filenames per test

### Test Fixtures
- Sample images for upload testing
- Test schemas for validation
- Mock data for various scenarios

## 🚨 Troubleshooting

### Common Issues

1. **Services not ready**
   ```bash
   # Check service health
   curl http://localhost:7860/health
   curl http://localhost:3000
   ```

2. **Browser installation issues**
   ```bash
   # Reinstall Playwright browsers
   playwright install
   ```

3. **Test failures with traces**
   ```bash
   # View test traces
   playwright show-trace test-results/trace.zip
   ```

### Debug Mode
```bash
# Run tests with headed browser
pytest -m e2e --headed --slowmo=1000

# Run specific test with debugging
pytest specs/upload_flow_spec.py::TestUploadFlow::test_complete_upload_flow -v --headed
```

## πŸ“ˆ CI/CD Integration

### GitHub Actions Example
```yaml
name: E2E Tests
on: [push, pull_request]
jobs:
  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Start E2E environment
        run: docker-compose -f e2e/docker-compose.e2e.yml up -d --build
      - name: Wait for services
        run: sleep 30
      - name: Install dependencies
        run: |
          cd e2e
          pip install -r requirements.txt
          playwright install
      - name: Run E2E tests
        run: |
          cd e2e
          pytest -m e2e -v
      - name: Upload test results
        uses: actions/upload-artifact@v3
        with:
          name: e2e-test-results
          path: e2e/test-results/
```

## πŸ“‹ Test Results

### Output Locations
- **Videos**: `test-results/videos/`
- **Screenshots**: `test-results/screenshots/`
- **Traces**: `test-results/har/`
- **Reports**: Playwright HTML report

### Success Criteria
- All critical user paths covered
- <5% flakiness rate
- <5 minutes total suite duration
- Clear failure debugging information

## πŸ”„ Maintenance

### Regular Tasks
- Update test selectors when UI changes
- Refresh test data periodically
- Monitor flakiness trends
- Update dependencies

### Best Practices
- Use stable `data-testid` selectors
- Keep page objects thin and focused
- Write descriptive test names
- Maintain test data isolation