@test-bro/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +855 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10344 -0
- package/package.json +60 -0
package/README.md
ADDED
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
# TestBro CLI
|
|
2
|
+
|
|
3
|
+
Command-line interface for AI-powered browser testing. Generate, run, and manage automated Playwright tests from your terminal.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### Global Installation (Recommended)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g testbro-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Local Development
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cd apps/cli
|
|
17
|
+
pnpm install
|
|
18
|
+
pnpm build
|
|
19
|
+
pnpm link --global
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### 1. Authenticate
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Get API token from https://testbro.dev/settings/tokens
|
|
28
|
+
testbro login --token tb_live_xxxxx
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### 2. Create Project Configuration
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# Initialize config in your project directory
|
|
35
|
+
testbro config init
|
|
36
|
+
|
|
37
|
+
# Edit test-bro.config.json
|
|
38
|
+
{
|
|
39
|
+
"baseUrl": "https://your-app.com",
|
|
40
|
+
"projectId": "your-project-id",
|
|
41
|
+
"mode": "hybrid"
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 3. Run Tests
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Run from natural language description
|
|
49
|
+
testbro run --description "Test user login with valid credentials"
|
|
50
|
+
|
|
51
|
+
# Run from PRD/requirements file
|
|
52
|
+
testbro run --file ./requirements.md
|
|
53
|
+
|
|
54
|
+
# Run saved test case
|
|
55
|
+
testbro run --test-case tc_abc123
|
|
56
|
+
|
|
57
|
+
# Run all project test cases
|
|
58
|
+
testbro run --project proj_xyz789
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Commands
|
|
62
|
+
|
|
63
|
+
### Authentication
|
|
64
|
+
|
|
65
|
+
#### `testbro init`
|
|
66
|
+
|
|
67
|
+
Interactive setup wizard for first-time configuration. Recommended for new users.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Interactive mode (recommended)
|
|
71
|
+
testbro init
|
|
72
|
+
|
|
73
|
+
# Non-interactive mode (CI/CD)
|
|
74
|
+
testbro init --token tb_live_xxxxx --non-interactive
|
|
75
|
+
|
|
76
|
+
# Non-interactive with project
|
|
77
|
+
testbro init --token tb_live_xxxxx --project-id proj_abc123 --non-interactive
|
|
78
|
+
|
|
79
|
+
# Skip project setup
|
|
80
|
+
testbro init --token tb_live_xxxxx --skip-project --non-interactive
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Options:**
|
|
84
|
+
- `--token <token>`: API token (skips interactive authentication prompt)
|
|
85
|
+
- `--non-interactive`: Skip all prompts, use defaults (for CI/CD)
|
|
86
|
+
- `--project-id <id>`: Set project ID in non-interactive mode
|
|
87
|
+
- `--skip-project`: Skip project setup entirely
|
|
88
|
+
|
|
89
|
+
**What it does:**
|
|
90
|
+
|
|
91
|
+
1. **Global Configuration**: Creates `~/.testbro/config.json` if needed
|
|
92
|
+
2. **Authentication**: Prompts for API token and validates it
|
|
93
|
+
3. **Project Setup**: Offers to create new project, use existing, or skip
|
|
94
|
+
4. **Verification**: Runs health checks on API, token, and project access
|
|
95
|
+
|
|
96
|
+
**Output (Interactive Mode):**
|
|
97
|
+
```
|
|
98
|
+
Welcome to TestBro!
|
|
99
|
+
|
|
100
|
+
Step 1/4: Global configuration
|
|
101
|
+
Config directory: ~/.testbro/ (will be created)
|
|
102
|
+
Global config created at ~/.testbro/config.json
|
|
103
|
+
|
|
104
|
+
Step 2/4: Authentication
|
|
105
|
+
> Enter your API token: tb_live_***********
|
|
106
|
+
Validating token... done
|
|
107
|
+
Logged in as user@example.com
|
|
108
|
+
|
|
109
|
+
Step 3/4: Project setup
|
|
110
|
+
? Initialize project-level config here? (Y/n): Y
|
|
111
|
+
? Create a new project or use an existing one?
|
|
112
|
+
> Create new project
|
|
113
|
+
Use existing project
|
|
114
|
+
Skip
|
|
115
|
+
|
|
116
|
+
? Project name: My App
|
|
117
|
+
? Base URL [http://localhost:3000]:
|
|
118
|
+
? Default test mode [hybrid]:
|
|
119
|
+
|
|
120
|
+
Creating project... done
|
|
121
|
+
Project "My App" created (ID: proj_abc123)
|
|
122
|
+
Created test-bro.config.json
|
|
123
|
+
|
|
124
|
+
Step 4/4: Verification
|
|
125
|
+
Checking API connection... healthy
|
|
126
|
+
Checking authentication... valid
|
|
127
|
+
Checking project access... ok
|
|
128
|
+
|
|
129
|
+
Setup complete!
|
|
130
|
+
|
|
131
|
+
Next steps:
|
|
132
|
+
testbro run --url http://localhost:3000 -d "Test the login page"
|
|
133
|
+
testbro generate --file requirements.md --save
|
|
134
|
+
testbro config show
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### `testbro login`
|
|
138
|
+
|
|
139
|
+
Authenticate with TestBro API.
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# Token-based authentication (recommended)
|
|
143
|
+
testbro login --token tb_live_xxxxx
|
|
144
|
+
|
|
145
|
+
# Custom API URL
|
|
146
|
+
testbro login --token tb_live_xxxxx --url https://api.testbro.dev
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Options:**
|
|
150
|
+
- `-t, --token <token>`: API token from your TestBro account
|
|
151
|
+
- `-u, --url <url>`: API URL (default: http://localhost:3024)
|
|
152
|
+
|
|
153
|
+
#### `testbro logout`
|
|
154
|
+
|
|
155
|
+
Remove stored credentials.
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
testbro logout
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### `testbro whoami`
|
|
162
|
+
|
|
163
|
+
Show current authenticated user and active project.
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
testbro whoami
|
|
167
|
+
# Output:
|
|
168
|
+
# Logged in as: user@example.com
|
|
169
|
+
# Active Project: My Test Project (proj_123)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Project Management
|
|
173
|
+
|
|
174
|
+
#### `testbro projects`
|
|
175
|
+
|
|
176
|
+
List all projects for the authenticated user.
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
testbro projects
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Output:**
|
|
183
|
+
```
|
|
184
|
+
Your Projects:
|
|
185
|
+
• My Web App (proj_abc123)
|
|
186
|
+
https://myapp.com
|
|
187
|
+
Created: 2024-01-15
|
|
188
|
+
|
|
189
|
+
• Mobile Site (proj_xyz789)
|
|
190
|
+
https://mobile.example.com
|
|
191
|
+
Created: 2024-01-20
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### `testbro projects create`
|
|
195
|
+
|
|
196
|
+
Create a new project interactively.
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
testbro projects create
|
|
200
|
+
|
|
201
|
+
# Interactive prompts:
|
|
202
|
+
# ? Project name: My New App
|
|
203
|
+
# ? Description (optional): E-commerce testing suite
|
|
204
|
+
# ? Base URL (optional): https://shop.example.com
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### `testbro use-project`
|
|
208
|
+
|
|
209
|
+
Set or clear the active project.
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Set active project
|
|
213
|
+
testbro use-project proj_abc123
|
|
214
|
+
|
|
215
|
+
# Clear active project
|
|
216
|
+
testbro use-project --clear
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Options:**
|
|
220
|
+
- `-c, --clear`: Clear the active project
|
|
221
|
+
|
|
222
|
+
### Test Generation
|
|
223
|
+
|
|
224
|
+
#### `testbro generate`
|
|
225
|
+
|
|
226
|
+
Generate test cases from a file or description.
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
# Generate from PRD file
|
|
230
|
+
testbro generate --file ./prd.md
|
|
231
|
+
|
|
232
|
+
# Generate from text description
|
|
233
|
+
testbro generate --description "Test checkout flow with payment"
|
|
234
|
+
|
|
235
|
+
# Generate and save to project
|
|
236
|
+
testbro generate --file ./requirements.md --save
|
|
237
|
+
|
|
238
|
+
# Specify project
|
|
239
|
+
testbro generate --file ./ac.md --save --project proj_123
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Options:**
|
|
243
|
+
- `-f, --file <path>`: Path to requirements/PRD file
|
|
244
|
+
- `-d, --description <text>`: Text description
|
|
245
|
+
- `-s, --save`: Save generated test cases to project
|
|
246
|
+
- `-p, --project <id>`: Project ID (overrides active project)
|
|
247
|
+
|
|
248
|
+
**Example Output:**
|
|
249
|
+
```
|
|
250
|
+
Generating test cases...
|
|
251
|
+
|
|
252
|
+
Generated 3 test cases:
|
|
253
|
+
|
|
254
|
+
1. Test: User Login Flow
|
|
255
|
+
Steps:
|
|
256
|
+
1. Navigate to login page
|
|
257
|
+
2. Fill in email field
|
|
258
|
+
3. Fill in password field
|
|
259
|
+
4. Click login button
|
|
260
|
+
5. Verify redirect to dashboard
|
|
261
|
+
|
|
262
|
+
2. Test: Invalid Login Attempt
|
|
263
|
+
Steps: ...
|
|
264
|
+
|
|
265
|
+
3. Test: Password Reset Flow
|
|
266
|
+
Steps: ...
|
|
267
|
+
|
|
268
|
+
Save to project? [y/N] y
|
|
269
|
+
✓ Saved 3 test cases to project
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Test Execution
|
|
273
|
+
|
|
274
|
+
#### `testbro run`
|
|
275
|
+
|
|
276
|
+
Run tests against a URL.
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# Run from description
|
|
280
|
+
testbro run --url https://example.com --description "Test login flow"
|
|
281
|
+
|
|
282
|
+
# Run from file (with deduplication)
|
|
283
|
+
testbro run --file ./acceptance-criteria.md
|
|
284
|
+
|
|
285
|
+
# Run specific test case
|
|
286
|
+
testbro run --test-case tc_abc123
|
|
287
|
+
|
|
288
|
+
# Run all project test cases
|
|
289
|
+
testbro run --project proj_xyz789
|
|
290
|
+
|
|
291
|
+
# Use different execution modes
|
|
292
|
+
testbro run --mode ai --description "Test search functionality"
|
|
293
|
+
testbro run --mode hybrid --file ./test-plan.md
|
|
294
|
+
testbro run --mode selector --test-case tc_123
|
|
295
|
+
|
|
296
|
+
# Run in headed mode (visible browser)
|
|
297
|
+
testbro run --headed --description "Debug login issue"
|
|
298
|
+
|
|
299
|
+
# Learn selectors from AI actions
|
|
300
|
+
testbro run --mode ai --learn-selectors --yes
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
**Options:**
|
|
304
|
+
|
|
305
|
+
**Target:**
|
|
306
|
+
- `-u, --url <url>`: Target URL (or use baseUrl from config)
|
|
307
|
+
- `--file <path>`: Generate and run from PRD/AC file
|
|
308
|
+
- `-d, --description <text>`: Feature description to test
|
|
309
|
+
- `-p, --project <id>`: Run all test cases from project
|
|
310
|
+
- `-t, --test-case <id>`: Run specific test case
|
|
311
|
+
|
|
312
|
+
**Execution:**
|
|
313
|
+
- `-m, --mode <mode>`: Execution mode: `selector` (default), `ai`, or `hybrid`
|
|
314
|
+
- `--headed`: Run browser in headed mode (visible)
|
|
315
|
+
- `--remote`: Run on remote staging environment
|
|
316
|
+
- `--timeout <ms>`: Timeout per step (default: 30000ms)
|
|
317
|
+
- `--sequential`: Keep browser session between test cases (default: true)
|
|
318
|
+
- `--no-sequential`: Start fresh browser session for each test case
|
|
319
|
+
|
|
320
|
+
**Output:**
|
|
321
|
+
- `-f, --format <format>`: Output format: `pretty` or `json` (default: `pretty`)
|
|
322
|
+
- `-v, --verbose`: Show verbose output
|
|
323
|
+
|
|
324
|
+
**Recording:**
|
|
325
|
+
- `--record-video`: Record video of test execution (automatically uploads to server)
|
|
326
|
+
- `--record-trace`: Capture Playwright trace for debugging (automatically uploads to server)
|
|
327
|
+
|
|
328
|
+
**Selector Learning:**
|
|
329
|
+
- `--learn-selectors`: Learn selectors from AI actions
|
|
330
|
+
- `--yes`: Auto-confirm selector learning
|
|
331
|
+
|
|
332
|
+
**Deduplication (when using --file):**
|
|
333
|
+
- `--no-dedup`: Skip deduplication check
|
|
334
|
+
- `--auto-merge`: Auto-apply smart merge without prompting
|
|
335
|
+
|
|
336
|
+
**Examples:**
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# Basic test run
|
|
340
|
+
testbro run --url https://myapp.com --description "Test user registration"
|
|
341
|
+
|
|
342
|
+
# Run with AI mode and selector learning
|
|
343
|
+
testbro run --mode ai --learn-selectors --description "Test complex form"
|
|
344
|
+
|
|
345
|
+
# Run from PRD with smart deduplication
|
|
346
|
+
testbro run --file ./prd.md --auto-merge
|
|
347
|
+
|
|
348
|
+
# Debug test in visible browser
|
|
349
|
+
testbro run --headed --verbose --test-case tc_123
|
|
350
|
+
|
|
351
|
+
# CI/CD integration (JSON output)
|
|
352
|
+
testbro run --format json --project proj_123 > results.json
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**Output (Pretty Format):**
|
|
356
|
+
```
|
|
357
|
+
Running tests...
|
|
358
|
+
|
|
359
|
+
✓ Test: User Login Flow (2.3s)
|
|
360
|
+
✓ Navigate to login page (450ms)
|
|
361
|
+
✓ Fill in email field (320ms)
|
|
362
|
+
✓ Fill in password field (290ms)
|
|
363
|
+
✓ Click login button (180ms)
|
|
364
|
+
✓ Verify redirect to dashboard (1.1s)
|
|
365
|
+
|
|
366
|
+
Summary:
|
|
367
|
+
Tests: 1 passed, 0 failed, 1 total
|
|
368
|
+
Duration: 2.3s
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
**Output (JSON Format):**
|
|
372
|
+
```json
|
|
373
|
+
{
|
|
374
|
+
"summary": {
|
|
375
|
+
"totalTestCases": 1,
|
|
376
|
+
"totalPassed": 1,
|
|
377
|
+
"totalFailed": 0,
|
|
378
|
+
"totalDuration": 2340
|
|
379
|
+
},
|
|
380
|
+
"testCases": [
|
|
381
|
+
{
|
|
382
|
+
"id": "tc_1",
|
|
383
|
+
"name": "User Login Flow",
|
|
384
|
+
"status": "passed",
|
|
385
|
+
"duration": 2340,
|
|
386
|
+
"steps": [...]
|
|
387
|
+
}
|
|
388
|
+
]
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Configuration
|
|
393
|
+
|
|
394
|
+
#### `testbro config`
|
|
395
|
+
|
|
396
|
+
Show current configuration.
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
testbro config
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
**Output:**
|
|
403
|
+
```
|
|
404
|
+
TestBro Configuration
|
|
405
|
+
|
|
406
|
+
User Config (~/.testbro/config.json)
|
|
407
|
+
Path: /Users/name/.testbro/config.json
|
|
408
|
+
API URL: http://localhost:3024
|
|
409
|
+
Authenticated: Yes
|
|
410
|
+
Active Project: proj_abc123
|
|
411
|
+
|
|
412
|
+
Project Config (test-bro.config.json)
|
|
413
|
+
Path: /path/to/project/test-bro.config.json
|
|
414
|
+
Base URL: https://myapp.com
|
|
415
|
+
Environment: local
|
|
416
|
+
Mode: hybrid
|
|
417
|
+
Timeout: 30000ms
|
|
418
|
+
Project ID: proj_abc123
|
|
419
|
+
|
|
420
|
+
Authentication
|
|
421
|
+
Token: tb_l...xyz (from user config)
|
|
422
|
+
OpenRouter API Key: sk-o...abc (from OPENROUTER_API_KEY env)
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### `testbro config show`
|
|
426
|
+
|
|
427
|
+
Alias for `testbro config`.
|
|
428
|
+
|
|
429
|
+
#### `testbro config init`
|
|
430
|
+
|
|
431
|
+
Create test-bro.config.json template.
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
testbro config init
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
Note: For interactive setup with authentication and project selection, use `testbro init` instead.
|
|
438
|
+
|
|
439
|
+
Creates `test-bro.config.json` in the current directory:
|
|
440
|
+
|
|
441
|
+
```json
|
|
442
|
+
{
|
|
443
|
+
"baseUrl": "https://your-app.com",
|
|
444
|
+
"environment": "local",
|
|
445
|
+
"mode": "hybrid",
|
|
446
|
+
"timeout": 30000,
|
|
447
|
+
"headed": false,
|
|
448
|
+
"projectId": "",
|
|
449
|
+
"credentials": {
|
|
450
|
+
"username": "${USERNAME}",
|
|
451
|
+
"password": "${PASSWORD}"
|
|
452
|
+
},
|
|
453
|
+
"deduplication": {
|
|
454
|
+
"enabled": true,
|
|
455
|
+
"autoMerge": false
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
## Configuration Files
|
|
461
|
+
|
|
462
|
+
### User Config (~/.testbro/config.json)
|
|
463
|
+
|
|
464
|
+
Stores user-level settings and authentication.
|
|
465
|
+
|
|
466
|
+
```json
|
|
467
|
+
{
|
|
468
|
+
"apiUrl": "http://localhost:3024",
|
|
469
|
+
"token": "tb_live_xxxxx",
|
|
470
|
+
"activeProjectId": "proj_abc123"
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
**Never commit this file to git.**
|
|
475
|
+
|
|
476
|
+
### Project Config (test-bro.config.json)
|
|
477
|
+
|
|
478
|
+
Project-specific settings, checked into version control.
|
|
479
|
+
|
|
480
|
+
```json
|
|
481
|
+
{
|
|
482
|
+
"baseUrl": "https://staging.myapp.com",
|
|
483
|
+
"environment": "staging",
|
|
484
|
+
"mode": "hybrid",
|
|
485
|
+
"timeout": 30000,
|
|
486
|
+
"headed": false,
|
|
487
|
+
"projectId": "proj_xyz789",
|
|
488
|
+
"credentials": {
|
|
489
|
+
"username": "${TEST_USERNAME}",
|
|
490
|
+
"password": "${TEST_PASSWORD}"
|
|
491
|
+
},
|
|
492
|
+
"deduplication": {
|
|
493
|
+
"enabled": true,
|
|
494
|
+
"autoMerge": false
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
**Config Options:**
|
|
500
|
+
|
|
501
|
+
- `baseUrl` (string): Default URL for tests
|
|
502
|
+
- `environment` ("local" | "staging"): Execution environment
|
|
503
|
+
- `mode` ("selector" | "ai" | "hybrid"): Default execution mode
|
|
504
|
+
- `timeout` (number): Default step timeout in milliseconds
|
|
505
|
+
- `headed` (boolean): Run browser in headed mode
|
|
506
|
+
- `projectId` (string): TestBro project ID
|
|
507
|
+
- `credentials` (object): Environment variable references for auth
|
|
508
|
+
- `deduplication` (object): Test case deduplication settings
|
|
509
|
+
- `enabled` (boolean): Enable deduplication checks
|
|
510
|
+
- `autoMerge` (boolean): Automatically apply smart merge
|
|
511
|
+
|
|
512
|
+
**Can commit to git.** Use environment variables for secrets.
|
|
513
|
+
|
|
514
|
+
## Environment Variables
|
|
515
|
+
|
|
516
|
+
### Required for AI Mode
|
|
517
|
+
|
|
518
|
+
```bash
|
|
519
|
+
OPENROUTER_API_KEY=sk-or-v1-xxxxx
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
### Optional
|
|
523
|
+
|
|
524
|
+
```bash
|
|
525
|
+
# Authentication (alternative to testbro login)
|
|
526
|
+
TEST_BRO_TOKEN=tb_live_xxxxx
|
|
527
|
+
|
|
528
|
+
# Test credentials (referenced in config)
|
|
529
|
+
TEST_USERNAME=testuser@example.com
|
|
530
|
+
TEST_PASSWORD=SecureP@ssw0rd
|
|
531
|
+
|
|
532
|
+
# API URL override
|
|
533
|
+
TESTBRO_API_URL=https://api.testbro.dev
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
## Session Continuity
|
|
537
|
+
|
|
538
|
+
### Sequential Test Execution (Default)
|
|
539
|
+
|
|
540
|
+
By default, TestBro keeps the browser session alive between test cases when running multiple tests in a single command. This enables sequential flows where later test cases build on the state left by earlier ones.
|
|
541
|
+
|
|
542
|
+
**Example:**
|
|
543
|
+
```bash
|
|
544
|
+
testbro run --project proj_123
|
|
545
|
+
# Test 1: Navigate to /login, log in, verify dashboard
|
|
546
|
+
# Test 2: Continue from dashboard, click profile, verify profile page
|
|
547
|
+
# Test 3: Continue from profile, edit settings, verify changes
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
**How it works:**
|
|
551
|
+
- First test case includes a `navigate` step to the starting URL
|
|
552
|
+
- Subsequent test cases skip their leading `navigate` step and continue from the current page
|
|
553
|
+
- Browser context and cookies persist across all test cases in the run
|
|
554
|
+
- If using auto-login (`storageState`), authentication is injected before the test plan starts
|
|
555
|
+
|
|
556
|
+
**Opt out:**
|
|
557
|
+
```bash
|
|
558
|
+
testbro run --project proj_123 --no-sequential
|
|
559
|
+
# Each test case starts fresh with a new browser session
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
**When to use `--no-sequential`:**
|
|
563
|
+
- Tests should be fully independent
|
|
564
|
+
- Each test requires a clean browser state
|
|
565
|
+
- Testing logout/login flows that conflict with session persistence
|
|
566
|
+
|
|
567
|
+
## Execution Modes
|
|
568
|
+
|
|
569
|
+
### Selector Mode (Default)
|
|
570
|
+
|
|
571
|
+
Fast execution using learned selectors from previous AI runs.
|
|
572
|
+
|
|
573
|
+
```bash
|
|
574
|
+
testbro run --mode selector --test-case tc_123
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**Pros:**
|
|
578
|
+
- Fast (no AI API calls)
|
|
579
|
+
- Reliable for stable UIs
|
|
580
|
+
- No API costs
|
|
581
|
+
|
|
582
|
+
**Cons:**
|
|
583
|
+
- Requires learned selectors
|
|
584
|
+
- May fail on UI changes
|
|
585
|
+
|
|
586
|
+
### AI Mode
|
|
587
|
+
|
|
588
|
+
Uses GPT-4o-mini vision for every action.
|
|
589
|
+
|
|
590
|
+
```bash
|
|
591
|
+
testbro run --mode ai --description "Test complex workflow"
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
**Pros:**
|
|
595
|
+
- Handles dynamic UIs
|
|
596
|
+
- No selectors needed
|
|
597
|
+
- Adapts to changes
|
|
598
|
+
|
|
599
|
+
**Cons:**
|
|
600
|
+
- Slower execution
|
|
601
|
+
- API costs per run
|
|
602
|
+
- Requires OPENROUTER_API_KEY
|
|
603
|
+
|
|
604
|
+
### Hybrid Mode (Recommended)
|
|
605
|
+
|
|
606
|
+
Tries selectors first, falls back to AI if needed.
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
testbro run --mode hybrid --file ./tests.md
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
**Pros:**
|
|
613
|
+
- Best of both worlds
|
|
614
|
+
- Fast when selectors work
|
|
615
|
+
- Resilient to UI changes
|
|
616
|
+
- Can learn new selectors
|
|
617
|
+
|
|
618
|
+
**Cons:**
|
|
619
|
+
- Requires OPENROUTER_API_KEY
|
|
620
|
+
- Slight overhead on fallback
|
|
621
|
+
|
|
622
|
+
## Selector Learning
|
|
623
|
+
|
|
624
|
+
Automatically learn selectors from AI executions to speed up future runs.
|
|
625
|
+
|
|
626
|
+
```bash
|
|
627
|
+
# Enable selector learning
|
|
628
|
+
testbro run --mode ai --learn-selectors --description "Test flow"
|
|
629
|
+
|
|
630
|
+
# Auto-confirm learned selectors
|
|
631
|
+
testbro run --mode hybrid --learn-selectors --yes
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
**Workflow:**
|
|
635
|
+
1. AI executes actions and records element interactions
|
|
636
|
+
2. Selectors are generated from DOM analysis
|
|
637
|
+
3. Selectors are verified on the page
|
|
638
|
+
4. User confirms selectors to save (or --yes auto-confirms)
|
|
639
|
+
5. Selectors are stored in database
|
|
640
|
+
6. Future runs use learned selectors (selector or hybrid mode)
|
|
641
|
+
|
|
642
|
+
## Deduplication
|
|
643
|
+
|
|
644
|
+
When generating tests from files, TestBro can detect and merge similar test cases.
|
|
645
|
+
|
|
646
|
+
```bash
|
|
647
|
+
# Enable deduplication (default)
|
|
648
|
+
testbro run --file ./requirements.md
|
|
649
|
+
|
|
650
|
+
# Skip deduplication
|
|
651
|
+
testbro run --file ./requirements.md --no-dedup
|
|
652
|
+
|
|
653
|
+
# Auto-merge similar tests
|
|
654
|
+
testbro run --file ./requirements.md --auto-merge
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
**Deduplication Modes:**
|
|
658
|
+
|
|
659
|
+
- **Smart (default)**: Prompt user for duplicates
|
|
660
|
+
- Skip test cases >90% similar
|
|
661
|
+
- Update test cases 75-89% similar
|
|
662
|
+
- Create new test cases <75% similar
|
|
663
|
+
|
|
664
|
+
- **Force (--no-dedup)**: Create all test cases
|
|
665
|
+
|
|
666
|
+
- **Auto-merge (--auto-merge)**: Apply smart mode without prompts
|
|
667
|
+
|
|
668
|
+
## CI/CD Integration
|
|
669
|
+
|
|
670
|
+
### GitHub Actions
|
|
671
|
+
|
|
672
|
+
```yaml
|
|
673
|
+
name: TestBro Tests
|
|
674
|
+
|
|
675
|
+
on: [push, pull_request]
|
|
676
|
+
|
|
677
|
+
jobs:
|
|
678
|
+
test:
|
|
679
|
+
runs-on: ubuntu-latest
|
|
680
|
+
steps:
|
|
681
|
+
- uses: actions/checkout@v3
|
|
682
|
+
|
|
683
|
+
- name: Setup Node.js
|
|
684
|
+
uses: actions/setup-node@v3
|
|
685
|
+
with:
|
|
686
|
+
node-version: 18
|
|
687
|
+
|
|
688
|
+
- name: Install TestBro CLI
|
|
689
|
+
run: npm install -g testbro-cli
|
|
690
|
+
|
|
691
|
+
- name: Run Tests
|
|
692
|
+
env:
|
|
693
|
+
TEST_BRO_TOKEN: ${{ secrets.TEST_BRO_TOKEN }}
|
|
694
|
+
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
|
|
695
|
+
run: |
|
|
696
|
+
testbro run --project proj_123 --format json > results.json
|
|
697
|
+
|
|
698
|
+
- name: Upload Results
|
|
699
|
+
uses: actions/upload-artifact@v3
|
|
700
|
+
with:
|
|
701
|
+
name: test-results
|
|
702
|
+
path: results.json
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
### GitLab CI
|
|
706
|
+
|
|
707
|
+
```yaml
|
|
708
|
+
test:
|
|
709
|
+
image: node:18
|
|
710
|
+
script:
|
|
711
|
+
- npm install -g testbro-cli
|
|
712
|
+
- testbro run --project $PROJECT_ID --format json > results.json
|
|
713
|
+
artifacts:
|
|
714
|
+
paths:
|
|
715
|
+
- results.json
|
|
716
|
+
variables:
|
|
717
|
+
TEST_BRO_TOKEN: $TEST_BRO_TOKEN
|
|
718
|
+
OPENROUTER_API_KEY: $OPENROUTER_API_KEY
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
## Error Handling
|
|
722
|
+
|
|
723
|
+
### Common Errors
|
|
724
|
+
|
|
725
|
+
**Not authenticated:**
|
|
726
|
+
```
|
|
727
|
+
Error: Not authenticated. Run 'testbro login --token <token>' first.
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
**Solution:** Run `testbro login --token tb_live_xxxxx`
|
|
731
|
+
|
|
732
|
+
**Missing OPENROUTER_API_KEY:**
|
|
733
|
+
```
|
|
734
|
+
Error: OPENROUTER_API_KEY environment variable is required for AI mode.
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
**Solution:** Set environment variable:
|
|
738
|
+
```bash
|
|
739
|
+
export OPENROUTER_API_KEY=sk-or-v1-xxxxx
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
**No URL specified:**
|
|
743
|
+
```
|
|
744
|
+
Error: No URL specified. Use --url or set baseUrl in test-bro.config.json
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
**Solution:** Add URL to config or use `--url` flag
|
|
748
|
+
|
|
749
|
+
### Debug Mode
|
|
750
|
+
|
|
751
|
+
```bash
|
|
752
|
+
# Verbose output
|
|
753
|
+
testbro run --verbose --test-case tc_123
|
|
754
|
+
|
|
755
|
+
# Headed mode (see browser)
|
|
756
|
+
testbro run --headed --description "Debug test"
|
|
757
|
+
|
|
758
|
+
# Longer timeout
|
|
759
|
+
testbro run --timeout 60000 --test-case tc_123
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
## Best Practices
|
|
763
|
+
|
|
764
|
+
### 1. Use Project Config for Shared Settings
|
|
765
|
+
|
|
766
|
+
```json
|
|
767
|
+
{
|
|
768
|
+
"baseUrl": "https://staging.myapp.com",
|
|
769
|
+
"mode": "hybrid",
|
|
770
|
+
"projectId": "proj_123",
|
|
771
|
+
"deduplication": {
|
|
772
|
+
"enabled": true,
|
|
773
|
+
"autoMerge": false
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
Commit to git for team consistency.
|
|
779
|
+
|
|
780
|
+
### 2. Store Secrets in Environment Variables
|
|
781
|
+
|
|
782
|
+
```bash
|
|
783
|
+
# .env (don't commit)
|
|
784
|
+
TEST_BRO_TOKEN=tb_live_xxxxx
|
|
785
|
+
OPENROUTER_API_KEY=sk-or-v1-xxxxx
|
|
786
|
+
TEST_USERNAME=user@example.com
|
|
787
|
+
TEST_PASSWORD=password123
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
Reference in config:
|
|
791
|
+
```json
|
|
792
|
+
{
|
|
793
|
+
"credentials": {
|
|
794
|
+
"username": "${TEST_USERNAME}",
|
|
795
|
+
"password": "${TEST_PASSWORD}"
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
### 3. Use Hybrid Mode for Best Results
|
|
801
|
+
|
|
802
|
+
```bash
|
|
803
|
+
testbro run --mode hybrid --learn-selectors
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
Balances speed and flexibility.
|
|
807
|
+
|
|
808
|
+
### 4. Enable Selector Learning
|
|
809
|
+
|
|
810
|
+
```bash
|
|
811
|
+
testbro run --mode ai --learn-selectors --yes
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
First run uses AI, subsequent runs use selectors.
|
|
815
|
+
|
|
816
|
+
### 5. Use JSON Output in CI/CD
|
|
817
|
+
|
|
818
|
+
```bash
|
|
819
|
+
testbro run --format json --project proj_123 > results.json
|
|
820
|
+
```
|
|
821
|
+
|
|
822
|
+
Parse results programmatically.
|
|
823
|
+
|
|
824
|
+
## Development
|
|
825
|
+
|
|
826
|
+
```bash
|
|
827
|
+
# Install dependencies
|
|
828
|
+
pnpm install
|
|
829
|
+
|
|
830
|
+
# Build
|
|
831
|
+
pnpm build
|
|
832
|
+
|
|
833
|
+
# Link globally for testing
|
|
834
|
+
pnpm link --global
|
|
835
|
+
|
|
836
|
+
# Run locally
|
|
837
|
+
pnpm start -- run --help
|
|
838
|
+
|
|
839
|
+
# Type check
|
|
840
|
+
pnpm typecheck
|
|
841
|
+
|
|
842
|
+
# Lint
|
|
843
|
+
pnpm lint
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
## Related Packages
|
|
847
|
+
|
|
848
|
+
- [@testbro/core](../../packages/core) - Type definitions and schemas
|
|
849
|
+
- [@testbro/runner](../../packages/runner) - Playwright test executor
|
|
850
|
+
- [@testbro/ai-agent](../../packages/ai-agent) - AI-powered testing
|
|
851
|
+
- [apps/web](../web) - TestBro web API
|
|
852
|
+
|
|
853
|
+
## License
|
|
854
|
+
|
|
855
|
+
MIT
|