tauri-test-cli 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 lllangWV
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,477 @@
1
+ # tauri-test-cli
2
+
3
+ CLI for testing Tauri applications with screenshot capture, DOM inspection, and user interaction simulation. Designed for use by AI agents (like Claude Code) to automate testing of Tauri desktop apps.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Install globally
9
+ npm install -g tauri-test-cli
10
+
11
+ # Install tauri-test (required)
12
+ tauri-test setup
13
+
14
+ # Check dependencies
15
+ tauri-test check-deps
16
+
17
+ # Start server and test your app
18
+ tauri-test server --app ./target/debug/my-app &
19
+ tauri-test screenshot --output /tmp/screen.png
20
+ tauri-test click "button.submit"
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ ### Global Install via npm
26
+
27
+ ```bash
28
+ npm install -g tauri-test-cli
29
+ # or
30
+ bun install -g tauri-test-cli
31
+ # or
32
+ pnpm install -g tauri-test-cli
33
+
34
+ # Then install tauri-test
35
+ tauri-test setup
36
+ ```
37
+
38
+ ### Using Pixi (Recommended for Development)
39
+
40
+ Pixi handles all system-level dependencies automatically (WebKit, GTK, Rust).
41
+
42
+ ```bash
43
+ # Clone and install
44
+ git clone https://github.com/lllangWV/tauri-test-cli
45
+ cd tauri-test-cli
46
+ pixi install
47
+
48
+ # Build the CLI
49
+ pixi run build
50
+
51
+ # Run commands via pixi
52
+ pixi run dev server --app ./target/debug/my-app
53
+ ```
54
+
55
+ ### Prerequisites
56
+
57
+ The CLI will check for missing dependencies and provide install instructions:
58
+
59
+ ```bash
60
+ tauri-test check-deps
61
+ ```
62
+
63
+ <details>
64
+ <summary>Manual prerequisite installation</summary>
65
+
66
+ #### Linux
67
+
68
+ ```bash
69
+ # WebKit (required)
70
+ sudo apt install libwebkit2gtk-4.1-dev # Debian/Ubuntu
71
+ sudo dnf install webkit2gtk4.1-devel # Fedora
72
+ sudo pacman -S webkit2gtk-4.1 # Arch
73
+
74
+ # Rust and tauri-test
75
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
76
+ tauri-test setup
77
+ ```
78
+
79
+ #### macOS
80
+
81
+ WebKit is included in macOS. Just install tauri-test:
82
+
83
+ ```bash
84
+ tauri-test setup
85
+ ```
86
+
87
+ #### Windows
88
+
89
+ WebView2 is included in Windows 10/11. Just install tauri-test:
90
+
91
+ ```bash
92
+ tauri-test setup
93
+ ```
94
+
95
+ </details>
96
+
97
+ ## Usage
98
+
99
+ ### Server Mode (Recommended)
100
+
101
+ Start a persistent HTTP server - send commands anytime via HTTP.
102
+
103
+ ```bash
104
+ # Start server
105
+ tauri-test server --app ./target/debug/my-app &
106
+
107
+ # Send commands
108
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"click","selector":"button"}'
109
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"screenshot","output":"/tmp/screen.png"}'
110
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"snapshot"}'
111
+
112
+ # Check status
113
+ curl -s http://127.0.0.1:9222/status
114
+
115
+ # Stop server
116
+ tauri-test stop
117
+ ```
118
+
119
+ #### Virtual Display Mode (Linux)
120
+
121
+ Run in a virtual display to avoid focus-related throttling:
122
+
123
+ ```bash
124
+ # Using built-in --xvfb flag (recommended)
125
+ tauri-test server --app ./target/debug/my-app --xvfb &
126
+
127
+ # Or manually with Xvfb
128
+ Xvfb :99 -screen 0 1920x1080x24 &
129
+ DISPLAY=:99 tauri-test server --app ./target/debug/my-app &
130
+ ```
131
+
132
+ ### Client Mode (CLI without --app)
133
+
134
+ Once the server is running, you can use CLI commands directly - no `--app` needed, no curl required:
135
+
136
+ ```bash
137
+ # Start server once
138
+ tauri-test server --app ./target/debug/my-app &
139
+
140
+ # Run commands - they automatically connect to the server!
141
+ tauri-test click "button.submit"
142
+ tauri-test type "input[name=email]" "user@example.com"
143
+ tauri-test screenshot --output /tmp/screen.png
144
+ tauri-test snapshot --output /tmp/dom.yaml
145
+ tauri-test eval "document.title"
146
+ tauri-test wait ".modal" --gone --timeout 5000
147
+
148
+ # Check server status
149
+ tauri-test status
150
+
151
+ # Stop when done
152
+ tauri-test stop
153
+ ```
154
+
155
+ Use `--port` to connect to a different server:
156
+
157
+ ```bash
158
+ tauri-test click "button" --port 8080
159
+ ```
160
+
161
+ ### Why Server Mode?
162
+
163
+ - **No startup delay**: App stays running between commands
164
+ - **Simple CLI or HTTP API**: Use CLI commands or `curl`/`fetch`
165
+ - **Instant execution**: No auto-wait delay by default
166
+
167
+ ## Commands
168
+
169
+ ### Testing Commands
170
+
171
+ | Command | Required Fields | Optional Fields |
172
+ |---------|----------------|-----------------|
173
+ | `click` | `selector` | `timeout` |
174
+ | `type` | `selector`, `text` | `timeout` |
175
+ | `screenshot` | - | `output`, `fullPage` |
176
+ | `snapshot` | - | `output` |
177
+ | `eval` | `script` | - |
178
+ | `wait` | `selector` | `timeout`, `gone` |
179
+
180
+ ### Utility Commands
181
+
182
+ | Command | Description |
183
+ |---------|-------------|
184
+ | `tauri-test setup` | Install tauri-test via cargo |
185
+ | `tauri-test status [--port]` | Check if a server is running |
186
+ | `tauri-test stop [--port]` | Stop a running server |
187
+ | `tauri-test cleanup` | Kill stale WebDriver processes |
188
+ | `tauri-test check-deps` | Check system dependencies |
189
+
190
+ ### Examples
191
+
192
+ **Using CLI (recommended):**
193
+
194
+ ```bash
195
+ # Click a button
196
+ tauri-test click "button.submit"
197
+
198
+ # Type into an input
199
+ tauri-test type "input[name=email]" "user@example.com"
200
+
201
+ # Take screenshot
202
+ tauri-test screenshot --output /tmp/screen.png
203
+
204
+ # Get DOM snapshot (accessibility tree in YAML format)
205
+ tauri-test snapshot --output /tmp/dom.yaml
206
+
207
+ # Execute JavaScript
208
+ tauri-test eval "document.title"
209
+
210
+ # Wait for element to disappear
211
+ tauri-test wait ".modal" --gone --timeout 5000
212
+ ```
213
+
214
+ **Using curl:**
215
+
216
+ ```bash
217
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"click","selector":"button.submit"}'
218
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"type","selector":"input[name=email]","text":"user@example.com"}'
219
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"screenshot","output":"/tmp/screen.png"}'
220
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"snapshot","output":"/tmp/dom.yaml"}'
221
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"eval","script":"document.title"}'
222
+ curl -s http://127.0.0.1:9222 -d '{"cmd":"wait","selector":".modal","gone":true,"timeout":5000}'
223
+ ```
224
+
225
+ ### Server Response Format
226
+
227
+ ```json
228
+ {"success": true, "result": {"path": "/tmp/screen.png", "width": 1280, "height": 720}}
229
+ ```
230
+
231
+ On error:
232
+ ```json
233
+ {"success": false, "error": "Element not found: .missing"}
234
+ ```
235
+
236
+ ## Batch Mode
237
+
238
+ For single-invocation workflows with multiple commands:
239
+
240
+ ```bash
241
+ echo '[
242
+ {"cmd":"click","selector":"button"},
243
+ {"cmd":"screenshot","output":"/tmp/result.png"}
244
+ ]' | tauri-test batch --app ./target/debug/my-app --json
245
+ ```
246
+
247
+ ## Single Commands
248
+
249
+ Each command starts a fresh session (slower but simpler):
250
+
251
+ ```bash
252
+ tauri-test screenshot --app ./target/debug/my-app --output /tmp/screen.png
253
+ tauri-test click "button#submit" --app ./target/debug/my-app
254
+ tauri-test snapshot --app ./target/debug/my-app
255
+ ```
256
+
257
+ ## Using with Claude Code
258
+
259
+ This CLI is designed for AI agents. Add this to your project's CLAUDE.md:
260
+
261
+ ```markdown
262
+ ## Testing Tauri Apps
263
+
264
+ Use `tauri-test` CLI for testing the Tauri application.
265
+
266
+ ### Start test server
267
+ tauri-test server --app ./target/debug/my-app --xvfb &
268
+
269
+ ### Available commands (once server is running, no --app needed)
270
+ - Click: `tauri-test click "button"`
271
+ - Type: `tauri-test type "input" "hello"`
272
+ - Screenshot: `tauri-test screenshot --output /tmp/screen.png`
273
+ - Snapshot: `tauri-test snapshot --output /tmp/dom.yaml`
274
+ - Eval: `tauri-test eval "document.title"`
275
+ - Wait: `tauri-test wait ".element" --timeout 5000`
276
+
277
+ ### Check server status
278
+ tauri-test status
279
+
280
+ ### Stop server
281
+ tauri-test stop
282
+ ```
283
+
284
+ ## Development
285
+
286
+ ### Setup
287
+
288
+ ```bash
289
+ # Clone and install dependencies
290
+ git clone https://github.com/lllangWV/tauri-test-cli
291
+ cd tauri-test-cli
292
+ pixi install
293
+
294
+ # Build the CLI
295
+ pixi run build
296
+
297
+ # Build the test app (required for integration tests)
298
+ pixi run test-app-build
299
+ ```
300
+
301
+ ### Running Tests
302
+
303
+ ```bash
304
+ # Run all tests (builds test app automatically)
305
+ pixi run test-all
306
+
307
+ # Run only unit tests (fast, no test app needed)
308
+ pixi run test-unit
309
+
310
+ # Run only integration tests (requires test app)
311
+ pixi run test-integration
312
+
313
+ # Watch mode for development
314
+ pixi run test-watch
315
+ ```
316
+
317
+ ### Test Structure
318
+
319
+ | Test File | Description | Count |
320
+ |-----------|-------------|-------|
321
+ | `src/cli.test.ts` | Arg parsing, batch command validation | 50 |
322
+ | `src/checks.test.ts` | Dependency checking | 20 |
323
+ | `src/commands/utils.test.ts` | Utility functions | 6 |
324
+ | `src/integration.test.ts` | End-to-end tests against test app | 30 |
325
+
326
+ ### Test App
327
+
328
+ A minimal Tauri test app is included in `apps/test-app/` for integration testing:
329
+
330
+ ```bash
331
+ # Build the test app
332
+ pixi run test-app-build
333
+
334
+ # Run the test app manually
335
+ pixi run test-app-run
336
+
337
+ # Start tauri-test server with test app
338
+ pixi run test-server
339
+ ```
340
+
341
+ ### Available Pixi Tasks
342
+
343
+ ```bash
344
+ pixi task list # Show all available tasks
345
+ ```
346
+
347
+ Key development tasks:
348
+ - `pixi run build` - Build the CLI
349
+ - `pixi run dev` - Run CLI in development mode
350
+ - `pixi run typecheck` - Run TypeScript type checking
351
+ - `pixi run test-all` - Run all tests
352
+ - `pixi run test-server` - Start server with test app
353
+
354
+ ### Benchmarks (Claude Code Headless Testing)
355
+
356
+ Run Claude Code in headless mode to test the CLI and measure performance:
357
+
358
+ ```bash
359
+ # List available benchmark tasks
360
+ pixi run benchmark-list
361
+
362
+ # Run a single benchmark with visualization
363
+ pixi run benchmark -v screenshot
364
+
365
+ # Run all benchmarks
366
+ pixi run benchmark-all
367
+
368
+ # Run all benchmarks quietly (timing only)
369
+ pixi run benchmark-all-quiet
370
+
371
+ # Run with different models
372
+ pixi run benchmark-opus # Claude Opus
373
+ pixi run benchmark-haiku # Claude Haiku
374
+ MODEL=sonnet pixi run benchmark-all # Explicit model
375
+ ```
376
+
377
+ #### Available Benchmark Tasks
378
+
379
+ | Task | Description |
380
+ |------|-------------|
381
+ | `screenshot` | Take a screenshot |
382
+ | `click` | Click a button and verify |
383
+ | `type` | Type text into input |
384
+ | `snapshot` | Get DOM snapshot |
385
+ | `eval` | Execute JavaScript |
386
+ | `wait` | Wait for elements |
387
+ | `form-fill` | Fill and submit form |
388
+ | `full-workflow` | Complete end-to-end test |
389
+
390
+ #### Benchmark Results
391
+
392
+ Results are saved to `benchmarks/results/` with:
393
+ - Individual task JSON files with timing and token usage
394
+ - Summary JSON with all results from a run
395
+
396
+ Example output:
397
+ ```json
398
+ {
399
+ "task": "screenshot",
400
+ "model": "sonnet",
401
+ "status": "passed",
402
+ "duration_seconds": 12.5,
403
+ "tokens": {
404
+ "input": 1234,
405
+ "output": 567,
406
+ "cache_read": 890,
407
+ "cache_create": 0
408
+ }
409
+ }
410
+ ```
411
+
412
+ ## Troubleshooting
413
+
414
+ ### "Maximum number of active sessions" Error
415
+
416
+ ```bash
417
+ tauri-test cleanup
418
+ ```
419
+
420
+ ### Server won't start
421
+
422
+ ```bash
423
+ tauri-test stop
424
+ tauri-test cleanup
425
+ ```
426
+
427
+ ### Missing dependencies
428
+
429
+ ```bash
430
+ tauri-test check-deps
431
+ tauri-test setup # Install tauri-test
432
+ ```
433
+
434
+ ### Window focus issues (slow commands)
435
+
436
+ Use the `--xvfb` flag to run in a virtual display:
437
+
438
+ ```bash
439
+ tauri-test server --app ./target/debug/my-app --xvfb &
440
+ ```
441
+
442
+ ## CLI Reference
443
+
444
+ ```
445
+ tauri-test - CLI for testing Tauri applications
446
+
447
+ USAGE:
448
+ tauri-test <command> [options]
449
+
450
+ When --app is omitted, commands connect to a running server (client mode).
451
+
452
+ COMMANDS:
453
+ server [--port <port>] [--xvfb] Start HTTP server for persistent sessions
454
+ screenshot [--output <path>] Take a screenshot
455
+ snapshot [--output <path>] Get DOM/accessibility tree snapshot
456
+ click <selector> Click an element
457
+ type <selector> <text> Type text into an element
458
+ wait <selector> Wait for an element
459
+ eval <script> Execute JavaScript
460
+ batch Execute multiple commands from stdin
461
+ status [--port <port>] Check if a server is running
462
+ stop [--port <port>] Stop a running server
463
+ cleanup Kill stale WebDriver processes
464
+ setup Install tauri-test via cargo
465
+ check-deps Check system dependencies
466
+
467
+ OPTIONS:
468
+ --app <path> Path to Tauri app binary (required for server/batch)
469
+ --port <port> Port for server/client mode (default: 9222)
470
+ --xvfb Run server in virtual display (Linux)
471
+ --json Output results as JSON
472
+ --help, -h Show help
473
+ ```
474
+
475
+ ## License
476
+
477
+ MIT