File size: 4,149 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# E2E Test Suite

End-to-end tests for PinchTab that exercise the full stack including browser automation.

## Quick Start

### With Docker (recommended)

```bash
./dev e2e          # Run all E2E tests
./dev e2e recent   # Run only recently added/changed scenarios (fast feedback)
./dev e2e orchestrator  # Run orchestrator-heavy scenarios only
./dev e2e curl     # Run only Curl-based scenarios
./dev e2e cli      # Run only CLI-based scenarios
```

Or directly:
```bash
docker compose -f tests/e2e/docker-compose.yml up --build
docker compose -f tests/e2e/docker-compose-orchestrator.yml run --build --rm runner
```

## Architecture

```
tests/e2e/
β”œβ”€β”€ docker-compose.yml      # Generic curl scenarios
β”œβ”€β”€ docker-compose-orchestrator.yml # Orchestrator-specific services
β”œβ”€β”€ config/                 # E2E-specific PinchTab configs
β”‚   β”œβ”€β”€ pinchtab.json
β”‚   β”œβ”€β”€ pinchtab-secure.json
β”‚   └── pinchtab-bridge.json
β”œβ”€β”€ fixtures/               # Static HTML test pages
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ form.html
β”‚   β”œβ”€β”€ table.html
β”‚   └── buttons.html
β”œβ”€β”€ scenarios/              # Test scripts
β”‚   β”œβ”€β”€ common.sh           # Shared utilities
β”‚   β”œβ”€β”€ run-all.sh          # Generic curl scenarios
β”‚   β”œβ”€β”€ 01-health.sh
β”‚   β”œβ”€β”€ 02-navigate.sh
β”‚   β”œβ”€β”€ 03-snapshot.sh
β”‚   β”œβ”€β”€ 04-tabs-api.sh      # Regression test for #207
β”‚   β”œβ”€β”€ 05-actions.sh
β”‚   └── 06-screenshot-pdf.sh
β”œβ”€β”€ scenarios-orchestrator/ # Multi-instance and attach flows
β”‚   β”œβ”€β”€ run-all.sh
β”‚   β”œβ”€β”€ 01-attach-bridge.sh
β”‚   └── 31-multi-instance.sh
β”œβ”€β”€ runner/                 # Test runner container
β”‚   └── Dockerfile
└── results/                # Test output (gitignored)
```

The Docker stack reuses the repository root `Dockerfile` and mounts explicit config files with `PINCHTAB_CONFIG` instead of maintaining separate e2e-only images.

## Test Scenarios

| Script | Tests |
|--------|-------|
| 01-health | Basic connectivity, health endpoint |
| 02-navigate | Navigation, tab creation, tab listing |
| 03-snapshot | A11y tree extraction, text content |
| 04-tabs-api | Tab-scoped APIs (regression #207) |
| 05-actions | Click, type, press actions |
| 06-screenshot-pdf | Screenshot and PDF export |
| scenarios-orchestrator/01-attach-bridge | Orchestrator attaches to the dedicated `pinchtab-bridge` container and proxies tab traffic |
| scenarios-orchestrator/31-multi-instance | Launch/list/stop and aggregate orchestration behavior |

## Adding Tests

1. Create a new script in `scenarios/` following the naming pattern `NN-name.sh`
2. Source `common.sh` for utilities
3. Use the assertion helpers:

```bash
#!/bin/bash
source "$(dirname "$0")/common.sh"

start_test "My test name"

# Assert HTTP status
assert_status 200 "${PINCHTAB_URL}/health"

# Assert JSON field equals value
RESULT=$(pt_get "/some/endpoint")
assert_json_eq "$RESULT" '.field' 'expected'

# Assert JSON contains substring
assert_json_contains "$RESULT" '.message' 'success'

# Assert array length
assert_json_length "$RESULT" '.items' 5

end_test
```

## Adding Fixtures

Add HTML files to `fixtures/` for testing specific scenarios:

- Forms and inputs
- Tables and data
- Dynamic content
- iframes
- File upload/download

## CI Integration

The E2E tests run automatically:
- On release tags (`v*`)
- On PRs that modify `tests/e2e/`
- Manually via workflow dispatch

## Debugging

### View container logs
```bash
docker compose -f tests/e2e/docker-compose.yml logs pinchtab
```

### Interactive shell in runner
```bash
docker compose -f tests/e2e/docker-compose.yml run runner bash
```

### Run specific scenario
```bash
docker compose -f tests/e2e/docker-compose.yml run runner /scenarios/04-tabs-api.sh
```

### Run orchestrator scenarios
```bash
docker compose -f tests/e2e/docker-compose-orchestrator.yml run --build --rm runner
```

### Run remote bridge attach scenario
```bash
docker compose -f tests/e2e/docker-compose-orchestrator.yml run --build --rm runner /scenarios-orchestrator/01-attach-bridge.sh
```