playwright-mimic 0.1.0 → 0.1.2
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 +695 -446
- package/dist/agentic/agent.d.ts +106 -0
- package/dist/agentic/agent.d.ts.map +1 -0
- package/dist/agentic/agent.js +528 -0
- package/dist/agentic/agent.js.map +1 -0
- package/dist/agentic/index.d.ts +13 -0
- package/dist/agentic/index.d.ts.map +1 -0
- package/dist/agentic/index.js +12 -0
- package/dist/agentic/index.js.map +1 -0
- package/dist/agentic/planner.d.ts +41 -0
- package/dist/agentic/planner.d.ts.map +1 -0
- package/dist/agentic/planner.js +136 -0
- package/dist/agentic/planner.js.map +1 -0
- package/dist/agentic/react.d.ts +35 -0
- package/dist/agentic/react.d.ts.map +1 -0
- package/dist/agentic/react.js +170 -0
- package/dist/agentic/react.js.map +1 -0
- package/dist/agentic/recovery.d.ts +55 -0
- package/dist/agentic/recovery.d.ts.map +1 -0
- package/dist/agentic/recovery.js +200 -0
- package/dist/agentic/recovery.js.map +1 -0
- package/dist/agentic/reflection.d.ts +40 -0
- package/dist/agentic/reflection.d.ts.map +1 -0
- package/dist/agentic/reflection.js +142 -0
- package/dist/agentic/reflection.js.map +1 -0
- package/dist/agentic/types.d.ts +177 -0
- package/dist/agentic/types.d.ts.map +1 -0
- package/dist/agentic/types.js +8 -0
- package/dist/agentic/types.js.map +1 -0
- package/dist/agentic/wait.d.ts +50 -0
- package/dist/agentic/wait.d.ts.map +1 -0
- package/dist/agentic/wait.js +140 -0
- package/dist/agentic/wait.js.map +1 -0
- package/dist/agentic-mimic.d.ts +56 -0
- package/dist/agentic-mimic.d.ts.map +1 -0
- package/dist/agentic-mimic.js +98 -0
- package/dist/agentic-mimic.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/mimic/actionType.d.ts +7 -0
- package/dist/mimic/actionType.d.ts.map +1 -0
- package/dist/mimic/actionType.js +44 -0
- package/dist/mimic/actionType.js.map +1 -0
- package/dist/mimic/annotations.d.ts +21 -0
- package/dist/mimic/annotations.d.ts.map +1 -0
- package/dist/mimic/annotations.js +36 -0
- package/dist/mimic/annotations.js.map +1 -0
- package/dist/mimic/cli.d.ts +15 -0
- package/dist/mimic/cli.d.ts.map +1 -0
- package/dist/mimic/cli.js +17 -0
- package/dist/mimic/cli.js.map +1 -0
- package/dist/mimic/click.d.ts +39 -0
- package/dist/mimic/click.d.ts.map +1 -0
- package/dist/mimic/click.js +348 -0
- package/dist/mimic/click.js.map +1 -0
- package/dist/mimic/forms.d.ts +52 -0
- package/dist/mimic/forms.d.ts.map +1 -0
- package/dist/mimic/forms.js +511 -0
- package/dist/mimic/forms.js.map +1 -0
- package/dist/mimic/markers.d.ts +133 -0
- package/dist/mimic/markers.d.ts.map +1 -0
- package/dist/mimic/markers.js +589 -0
- package/dist/mimic/markers.js.map +1 -0
- package/dist/mimic/navigation.d.ts +19 -0
- package/dist/mimic/navigation.d.ts.map +1 -0
- package/dist/mimic/navigation.js +136 -0
- package/dist/mimic/navigation.js.map +1 -0
- package/dist/mimic/playwrightCodeGenerator.d.ts +55 -0
- package/dist/mimic/playwrightCodeGenerator.d.ts.map +1 -0
- package/dist/mimic/playwrightCodeGenerator.js +270 -0
- package/dist/mimic/playwrightCodeGenerator.js.map +1 -0
- package/dist/mimic/replay.d.ts +21 -0
- package/dist/mimic/replay.d.ts.map +1 -0
- package/dist/mimic/replay.js +142 -0
- package/dist/mimic/replay.js.map +1 -0
- package/dist/mimic/schema/action.d.ts +315 -0
- package/dist/mimic/schema/action.d.ts.map +1 -0
- package/dist/mimic/schema/action.js +186 -0
- package/dist/mimic/schema/action.js.map +1 -0
- package/dist/mimic/selector.d.ts +143 -0
- package/dist/mimic/selector.d.ts.map +1 -0
- package/dist/mimic/selector.js +1515 -0
- package/dist/mimic/selector.js.map +1 -0
- package/dist/mimic/selectorDescriptor.d.ts +25 -0
- package/dist/mimic/selectorDescriptor.d.ts.map +1 -0
- package/dist/mimic/selectorDescriptor.js +32 -0
- package/dist/mimic/selectorDescriptor.js.map +1 -0
- package/dist/mimic/selectorSerialization.d.ts +18 -0
- package/dist/mimic/selectorSerialization.d.ts.map +1 -0
- package/dist/mimic/selectorSerialization.js +32 -0
- package/dist/mimic/selectorSerialization.js.map +1 -0
- package/dist/mimic/selectorTypes.d.ts +122 -0
- package/dist/mimic/selectorTypes.d.ts.map +1 -0
- package/dist/mimic/selectorTypes.js +2 -0
- package/dist/mimic/selectorTypes.js.map +1 -0
- package/dist/mimic/selectorUtils.d.ts +52 -0
- package/dist/mimic/selectorUtils.d.ts.map +1 -0
- package/dist/mimic/selectorUtils.js +251 -0
- package/dist/mimic/selectorUtils.js.map +1 -0
- package/dist/mimic/storage.d.ts +110 -0
- package/dist/mimic/storage.d.ts.map +1 -0
- package/dist/mimic/storage.js +409 -0
- package/dist/mimic/storage.js.map +1 -0
- package/dist/mimic/types.d.ts +85 -0
- package/dist/mimic/types.d.ts.map +1 -0
- package/dist/mimic/types.js +7 -0
- package/dist/mimic/types.js.map +1 -0
- package/dist/mimic.d.ts +29 -4
- package/dist/mimic.d.ts.map +1 -1
- package/dist/mimic.js +530 -32
- package/dist/mimic.js.map +1 -1
- package/dist/mimicry.d.ts +4 -4
- package/dist/mimicry.d.ts.map +1 -1
- package/dist/mimicry.js +22 -13
- package/dist/mimicry.js.map +1 -1
- package/package.json +30 -6
package/README.md
CHANGED
|
@@ -1,446 +1,695 @@
|
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
type
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
await
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
##
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
1
|
+
# Mimic
|
|
2
|
+
|
|
3
|
+
**Mimic** is an AI-powered browser testing framework that converts Gherkin or plain language tests into executable code, with self-repair capabilities when tests break due to code changes.
|
|
4
|
+
|
|
5
|
+
> Mimic learns how your app works, remembers what succeeds, repeats it reliably — and only thinks again when something breaks.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 🤖 **AI-Powered Conversion**: Uses language models to understand and execute natural language test instructions
|
|
10
|
+
- 🎯 **Smart Element Selection**: Automatically finds and interacts with elements based on semantic understanding
|
|
11
|
+
- 📝 **Gherkin-Style Syntax**: Write tests in natural language, one instruction per line
|
|
12
|
+
- 🔄 **Self-Repair Capability**: Automatically repairs broken tests when application code changes
|
|
13
|
+
- 🎭 **Playwright Integration**: Built on top of Playwright for reliable browser automation
|
|
14
|
+
- 📊 **Token Tracking**: Built-in token usage tracking for AI model calls (early mode - working out the best way to report on usage)
|
|
15
|
+
- 💾 **Snapshot Storage**: Automatically saves and replays successful test executions
|
|
16
|
+
- 🎯 **Best Selector System**: Stores optimal selectors (role, label, testid) for reliable element identification
|
|
17
|
+
|
|
18
|
+
## How It Works
|
|
19
|
+
|
|
20
|
+
Mimic follows a simple, human-readable lifecycle:
|
|
21
|
+
|
|
22
|
+
**Learn → Remember → Repeat → Troubleshoot & Fix**
|
|
23
|
+
|
|
24
|
+
AI is used to learn and adapt — not to waste tokens repeating work it has already done.
|
|
25
|
+
|
|
26
|
+
### 1. Learn — Understand the Intent
|
|
27
|
+
|
|
28
|
+
You write your test in plain English or Gherkin-style steps:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
await mimic`
|
|
32
|
+
navigate to https://playwright.dev/
|
|
33
|
+
click on "get started"
|
|
34
|
+
and click on "trace viewer"
|
|
35
|
+
`;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
During **Learn**, Mimic:
|
|
39
|
+
|
|
40
|
+
- **Dynamically injects marker code** into the page to assign `data-mimic-id` attributes to elements, helping align the LLM on which components to interact with
|
|
41
|
+
- Uses an AI model to:
|
|
42
|
+
- Interpret your intent
|
|
43
|
+
- Reason about the structure and semantics of the page
|
|
44
|
+
- Identify the most likely elements to interact with (using marker IDs to reference elements)
|
|
45
|
+
- Generate executable Playwright steps
|
|
46
|
+
|
|
47
|
+
This is the most flexible phase — it's where Mimic figures out what you meant, not just what to click. The marker injection happens automatically and transparently — no changes to your application code are needed.
|
|
48
|
+
|
|
49
|
+
### 2. Remember — Capture a Verified Recording
|
|
50
|
+
|
|
51
|
+
Once the test runs successfully, Mimic remembers what worked.
|
|
52
|
+
|
|
53
|
+
It stores a verified recording (snapshot) of the execution, including:
|
|
54
|
+
|
|
55
|
+
- The resolved interaction steps with full action details
|
|
56
|
+
- **Best selector descriptors** for each element (role, label, testid, etc.) — not just marker IDs
|
|
57
|
+
- Element identification data and positioning information
|
|
58
|
+
- Context needed to reliably repeat the behavior
|
|
59
|
+
- Timestamps and execution metadata
|
|
60
|
+
|
|
61
|
+
The storage system automatically saves snapshots to `<testfile-name>.mimic.json` files alongside your test files. These snapshots contain:
|
|
62
|
+
- **SelectorDescriptor objects**: The best available selector for each element (e.g., `getByRole('button', { name: 'Submit' })`)
|
|
63
|
+
- **Mimic IDs**: Reference identifiers from dynamically injected `data-mimic-id` attributes (used during learning to help align the LLM on components)
|
|
64
|
+
- **Action results**: Complete details of what action was performed and how
|
|
65
|
+
|
|
66
|
+
You can review the execution (for example, via Playwright's video output) to confirm it behaves exactly as expected. Once verified, this recording becomes the trusted reference for future runs.
|
|
67
|
+
|
|
68
|
+
> **Note**: The storage system is actively being refined to improve selector stability and snapshot reliability.
|
|
69
|
+
|
|
70
|
+
### 3. Repeat — Fast, Deterministic Execution
|
|
71
|
+
|
|
72
|
+
On subsequent runs, Mimic simply repeats the recorded behavior using stored snapshots.
|
|
73
|
+
|
|
74
|
+
In this phase:
|
|
75
|
+
|
|
76
|
+
- No AI calls are made
|
|
77
|
+
- Token usage drops to near zero
|
|
78
|
+
- Tests run faster and more deterministically
|
|
79
|
+
- Behavior is repeatable because it's based on a known-good run
|
|
80
|
+
- **Selector reconstruction**: Uses stored `SelectorDescriptor` objects to rebuild locators
|
|
81
|
+
|
|
82
|
+
The replay system:
|
|
83
|
+
1. Loads the snapshot from the `.mimic.json` file
|
|
84
|
+
2. Dynamically injects marker code to assign `data-mimic-id` attributes to page elements (for reference during troubleshooting if needed)
|
|
85
|
+
3. Reconstructs locators from stored selector descriptors (e.g., `getByRole('button', { name: 'Submit' })`)
|
|
86
|
+
4. Executes actions directly without AI analysis
|
|
87
|
+
|
|
88
|
+
As long as the application hasn't changed in a way that breaks the test, Mimic stays in Repeat mode.
|
|
89
|
+
|
|
90
|
+
### 4. Troubleshoot & Fix — Adapt When Things Change
|
|
91
|
+
|
|
92
|
+
When a test can no longer repeat successfully — due to UI or structural changes — Mimic detects the failure and switches back into reasoning mode.
|
|
93
|
+
|
|
94
|
+
During **Troubleshoot & Fix**, Mimic:
|
|
95
|
+
|
|
96
|
+
- Analyzes what failed and why
|
|
97
|
+
- Re-learns the updated application structure
|
|
98
|
+
- Repairs or regenerates the broken steps (with selective regeneration: only regenerates steps that failed or changed)
|
|
99
|
+
- Saves a new verified recording
|
|
100
|
+
|
|
101
|
+
Once repaired and validated, the test returns to Repeat mode — stable, fast, and low-cost again.
|
|
102
|
+
|
|
103
|
+
**Troubleshoot Mode**: You can force Mimic to regenerate snapshots by running tests with the `--troubleshoot` flag:
|
|
104
|
+
```bash
|
|
105
|
+
npx playwright test --troubleshoot
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Even in troubleshoot mode, Mimic will attempt to use existing snapshots first and only regenerate if replay fails.
|
|
109
|
+
|
|
110
|
+
### The Full Loop
|
|
111
|
+
|
|
112
|
+
**Learn → Remember → Repeat → Troubleshoot & Fix → Repeat**
|
|
113
|
+
|
|
114
|
+
AI is invoked only when something is new or broken.
|
|
115
|
+
Everything else runs on verified knowledge.
|
|
116
|
+
|
|
117
|
+
## Architecture
|
|
118
|
+
|
|
119
|
+
Built on top of Playwright with AI model integration for natural language processing and test repair. Converts plain language or Gherkin syntax into executable Playwright test code, then monitors test execution to detect failures and automatically repair broken tests when application code changes.
|
|
120
|
+
|
|
121
|
+
### Element Identification System
|
|
122
|
+
|
|
123
|
+
Mimic uses a sophisticated element identification system:
|
|
124
|
+
|
|
125
|
+
- **Dynamic Marker Injection**: Automatically injects `data-mimic-id` attributes into page elements at runtime. These identifiers are added dynamically to help align the LLM on which components to interact with during the learning phase, without requiring any manual changes to your application code.
|
|
126
|
+
- **Best Selector Generation**: Generates optimal selectors using Playwright's semantic locators:
|
|
127
|
+
- `getByRole()` for ARIA roles
|
|
128
|
+
- `getByLabel()` for form labels
|
|
129
|
+
- `getByTestId()` for test IDs
|
|
130
|
+
- `getByText()` for visible text
|
|
131
|
+
- CSS selectors as fallback
|
|
132
|
+
- **Snapshot Storage**: Stores `SelectorDescriptor` objects (JSON-serializable) in snapshots for fast replay
|
|
133
|
+
|
|
134
|
+
The marker system works entirely behind the scenes — Mimic dynamically loads marker code into the page to assign `data-mimic-id` attributes to interactive, display, and structural elements. These markers help the LLM identify and reference elements during the learning phase, making element identification more reliable without requiring any modifications to your application.
|
|
135
|
+
|
|
136
|
+
This ensures tests remain stable even when DOM structure changes, while preferring semantic selectors over brittle CSS paths.
|
|
137
|
+
|
|
138
|
+
### Technology Stack
|
|
139
|
+
|
|
140
|
+
- **TypeScript**
|
|
141
|
+
- **Node.js**
|
|
142
|
+
- **Playwright**
|
|
143
|
+
|
|
144
|
+
## Installation
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npm install playwright-mimic
|
|
148
|
+
# or
|
|
149
|
+
pnpm install playwright-mimic
|
|
150
|
+
# or
|
|
151
|
+
yarn add playwright-mimic
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Prerequisites
|
|
155
|
+
|
|
156
|
+
- Node.js 18+
|
|
157
|
+
- Playwright installed in your project
|
|
158
|
+
- An AI model provider (OpenAI, Ollama, or compatible provider from the `ai` SDK)
|
|
159
|
+
|
|
160
|
+
## Quick Start
|
|
161
|
+
|
|
162
|
+
### 1. Install Dependencies
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npm install @playwright/test playwright-mimic @ai-sdk/openai ai
|
|
166
|
+
# or for Ollama
|
|
167
|
+
npm install @playwright/test playwright-mimic ollama-ai-provider-v2 ai
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 2. Set Up Environment Variables
|
|
171
|
+
|
|
172
|
+
Create a `.env` file in your project root:
|
|
173
|
+
|
|
174
|
+
```env
|
|
175
|
+
OPENAI_API_KEY=your_openai_api_key_here
|
|
176
|
+
# or for Ollama (if using local models)
|
|
177
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 3. Configure Playwright Fixtures
|
|
181
|
+
|
|
182
|
+
Create a test utilities file (e.g., `test-utils.ts`):
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import "dotenv/config";
|
|
186
|
+
import { test as base } from '@playwright/test';
|
|
187
|
+
import { createMimic, type Mimic } from 'playwright-mimic';
|
|
188
|
+
import { openai } from '@ai-sdk/openai';
|
|
189
|
+
// or for Ollama: import { ollama } from 'ollama-ai-provider-v2';
|
|
190
|
+
import { LanguageModel } from 'ai';
|
|
191
|
+
|
|
192
|
+
// Configure your AI model
|
|
193
|
+
const brains = openai('gpt-4o-mini');
|
|
194
|
+
// or for Ollama: const brains = ollama('llama3.2') as LanguageModel;
|
|
195
|
+
|
|
196
|
+
export * from '@playwright/test';
|
|
197
|
+
|
|
198
|
+
// Extend Playwright's test with mimic fixture
|
|
199
|
+
export const test = base.extend<{
|
|
200
|
+
mimic: Mimic
|
|
201
|
+
}>({
|
|
202
|
+
mimic: async ({ page }, use, testInfo) => {
|
|
203
|
+
const mimic = createMimic({
|
|
204
|
+
page,
|
|
205
|
+
brains,
|
|
206
|
+
// eyes is optional and may be removed in future versions
|
|
207
|
+
// If provided, can use a different model for visual analysis
|
|
208
|
+
testInfo,
|
|
209
|
+
});
|
|
210
|
+
await use(mimic);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### 4. Write Your First Test
|
|
216
|
+
|
|
217
|
+
Create a test file (e.g., `example.spec.ts`):
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
import { test, expect } from './test-utils';
|
|
221
|
+
|
|
222
|
+
test('navigate and interact with Playwright docs', async ({ page, mimic }) => {
|
|
223
|
+
await mimic`
|
|
224
|
+
navigate to https://playwright.dev/
|
|
225
|
+
click on "get started"
|
|
226
|
+
and click on "trace viewer"
|
|
227
|
+
`;
|
|
228
|
+
|
|
229
|
+
expect(page.url()).toBe('https://playwright.dev/docs/trace-viewer-intro');
|
|
230
|
+
|
|
231
|
+
await mimic`go back`;
|
|
232
|
+
|
|
233
|
+
expect(page.url()).toBe('https://playwright.dev/docs/intro');
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 5. Run Your Tests
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npx playwright test
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Usage
|
|
244
|
+
|
|
245
|
+
### Basic Syntax
|
|
246
|
+
|
|
247
|
+
Mimic uses a simple line-by-line syntax where each line represents a test step:
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
await mimic`
|
|
251
|
+
navigate to https://example.com
|
|
252
|
+
click on "Sign In"
|
|
253
|
+
type "username" into the email field
|
|
254
|
+
type "password123" into the password field
|
|
255
|
+
click on the submit button
|
|
256
|
+
`;
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Supported Actions
|
|
260
|
+
|
|
261
|
+
#### Navigation
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
await mimic`
|
|
265
|
+
navigate to https://example.com
|
|
266
|
+
go back
|
|
267
|
+
go forward
|
|
268
|
+
refresh the page
|
|
269
|
+
close the page
|
|
270
|
+
`;
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### Clicking Elements
|
|
274
|
+
|
|
275
|
+
Mimic can find elements by:
|
|
276
|
+
- Visible text: `click on "Sign In"`
|
|
277
|
+
- Button labels: `click on the submit button`
|
|
278
|
+
- Link text: `click on "About Us"`
|
|
279
|
+
- Semantic descriptions: `click on the login button in the header`
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
await mimic`
|
|
283
|
+
click on "Get Started"
|
|
284
|
+
click on the search icon
|
|
285
|
+
click on the menu button
|
|
286
|
+
`;
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
#### Form Interactions
|
|
290
|
+
|
|
291
|
+
Mimic supports the following form actions:
|
|
292
|
+
- `type`: Type text character by character (simulates real typing)
|
|
293
|
+
- `fill`: Replace all content in a field with text (faster, preferred for most cases)
|
|
294
|
+
- `select`: Select an option from a dropdown/select element
|
|
295
|
+
- `check`: Check a checkbox
|
|
296
|
+
- `uncheck`: Uncheck a checkbox
|
|
297
|
+
- `clear`: Clear field content
|
|
298
|
+
- `press`: Press a single keyboard key (e.g., "Enter", "Tab", "Escape")
|
|
299
|
+
- `setInputFiles`: Upload a file
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
await mimic`
|
|
303
|
+
type "john@example.com" into the email field
|
|
304
|
+
fill the password field with "secret123"
|
|
305
|
+
select "United States" from the country dropdown
|
|
306
|
+
check the terms and conditions checkbox
|
|
307
|
+
uncheck the newsletter checkbox
|
|
308
|
+
clear the message field
|
|
309
|
+
press "Enter" in the search field
|
|
310
|
+
`;
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Using Variables
|
|
314
|
+
|
|
315
|
+
You can use template literals to inject variables:
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
const username = 'testuser';
|
|
319
|
+
const password = 'testpass';
|
|
320
|
+
|
|
321
|
+
await mimic`
|
|
322
|
+
type "${username}" into the username field
|
|
323
|
+
type "${password}" into the password field
|
|
324
|
+
click on "Login"
|
|
325
|
+
`;
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Combining with Playwright Assertions
|
|
329
|
+
|
|
330
|
+
Mimic works seamlessly with Playwright's built-in assertions:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
test('complete user registration', async ({ page, mimic }) => {
|
|
334
|
+
await mimic`
|
|
335
|
+
navigate to https://example.com/register
|
|
336
|
+
type "John Doe" into the name field
|
|
337
|
+
type "john@example.com" into the email field
|
|
338
|
+
type "SecurePass123!" into the password field
|
|
339
|
+
click on "Create Account"
|
|
340
|
+
`;
|
|
341
|
+
|
|
342
|
+
// Use Playwright assertions
|
|
343
|
+
await expect(page.locator('text=Welcome')).toBeVisible();
|
|
344
|
+
expect(page.url()).toContain('/dashboard');
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Advanced: Direct API Usage
|
|
349
|
+
|
|
350
|
+
If you need more control, you can use the `mimic` function directly:
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
import { mimic } from 'playwright-mimic';
|
|
354
|
+
import { openai } from '@ai-sdk/openai';
|
|
355
|
+
import { test } from '@playwright/test';
|
|
356
|
+
|
|
357
|
+
test('custom usage', async ({ page, testInfo }) => {
|
|
358
|
+
const brains = openai('gpt-4o-mini');
|
|
359
|
+
|
|
360
|
+
await mimic(
|
|
361
|
+
'navigate to https://example.com\nclick on "Get Started"',
|
|
362
|
+
{
|
|
363
|
+
page,
|
|
364
|
+
brains,
|
|
365
|
+
// eyes is optional and may be removed in future versions
|
|
366
|
+
testInfo,
|
|
367
|
+
}
|
|
368
|
+
);
|
|
369
|
+
});
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## API Reference
|
|
373
|
+
|
|
374
|
+
### `createMimic(config)`
|
|
375
|
+
|
|
376
|
+
Creates a mimic function that can be used as a template literal tag.
|
|
377
|
+
|
|
378
|
+
**Parameters:**
|
|
379
|
+
- `config.page` (required): Playwright `Page` object
|
|
380
|
+
- `config.brains` (required): Language model for reasoning (from `ai` SDK)
|
|
381
|
+
- `config.eyes` (optional): Language model for visual analysis (may be removed in future versions)
|
|
382
|
+
- `config.testInfo` (optional): Playwright `TestInfo` object for test tracking
|
|
383
|
+
|
|
384
|
+
**Returns:** A function that accepts template literals
|
|
385
|
+
|
|
386
|
+
### `mimic(input, config)`
|
|
387
|
+
|
|
388
|
+
Direct function call version.
|
|
389
|
+
|
|
390
|
+
**Parameters:**
|
|
391
|
+
- `input` (string): Newline-separated test steps
|
|
392
|
+
- `config`: Same as `createMimic`
|
|
393
|
+
|
|
394
|
+
## Snapshot Files
|
|
395
|
+
|
|
396
|
+
Mimic automatically creates snapshot files (`.mimic.json`) in `__mimic__/` directories alongside your test files. Each file can contain multiple test snapshots, with each test identified by a unique `testHash`.
|
|
397
|
+
|
|
398
|
+
### Snapshot File Structure
|
|
399
|
+
|
|
400
|
+
The snapshot file is a JSON object containing a `tests` array:
|
|
401
|
+
|
|
402
|
+
```json
|
|
403
|
+
{
|
|
404
|
+
"tests": [
|
|
405
|
+
{
|
|
406
|
+
"testHash": "abc123...",
|
|
407
|
+
"testText": "click on \"Submit\"\nfill the email field with \"test@example.com\"",
|
|
408
|
+
"stepsByHash": {
|
|
409
|
+
"def456...": {
|
|
410
|
+
"stepHash": "def456...",
|
|
411
|
+
"stepIndex": 0,
|
|
412
|
+
"stepText": "click on \"Submit\"",
|
|
413
|
+
"actionKind": "click",
|
|
414
|
+
"actionDetails": { ... },
|
|
415
|
+
"targetElement": {
|
|
416
|
+
"selector": {
|
|
417
|
+
"type": "role",
|
|
418
|
+
"role": "button",
|
|
419
|
+
"name": "Submit"
|
|
420
|
+
},
|
|
421
|
+
"mimicId": 42
|
|
422
|
+
},
|
|
423
|
+
"executedAt": "2024-01-01T12:00:00.000Z"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
"steps": [
|
|
427
|
+
{
|
|
428
|
+
"stepHash": "def456...",
|
|
429
|
+
"stepIndex": 0,
|
|
430
|
+
"stepText": "click on \"Submit\"",
|
|
431
|
+
"actionKind": "click",
|
|
432
|
+
"actionDetails": { ... },
|
|
433
|
+
"targetElement": {
|
|
434
|
+
"selector": {
|
|
435
|
+
"type": "role",
|
|
436
|
+
"role": "button",
|
|
437
|
+
"name": "Submit"
|
|
438
|
+
},
|
|
439
|
+
"mimicId": 42
|
|
440
|
+
},
|
|
441
|
+
"executedAt": "2024-01-01T12:00:00.000Z"
|
|
442
|
+
}
|
|
443
|
+
],
|
|
444
|
+
"flags": {
|
|
445
|
+
"needsRetry": false,
|
|
446
|
+
"hasErrors": false,
|
|
447
|
+
"troubleshootingEnabled": false,
|
|
448
|
+
"skipSnapshot": false,
|
|
449
|
+
"forceRegenerate": false,
|
|
450
|
+
"debugMode": false,
|
|
451
|
+
"createdAt": "2024-01-01T12:00:00.000Z",
|
|
452
|
+
"lastPassedAt": "2024-01-01T12:00:00.000Z",
|
|
453
|
+
"lastFailedAt": null
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### Snapshot Structure Details
|
|
461
|
+
|
|
462
|
+
Each test snapshot contains:
|
|
463
|
+
|
|
464
|
+
- **testHash**: Unique identifier for the test (hash of test text)
|
|
465
|
+
- **testText**: Original test text (mimic template string)
|
|
466
|
+
- **stepsByHash**: Object mapping step hashes to step data (for efficient lookup and selective regeneration)
|
|
467
|
+
- **steps**: Array of executed steps in order (for backward compatibility and ordered replay)
|
|
468
|
+
- **stepHash**: Unique identifier for the step (hash of step text)
|
|
469
|
+
- **stepIndex**: Index of the step in the test (0-based)
|
|
470
|
+
- **stepText**: Original step text
|
|
471
|
+
- **actionKind**: Type of action ("click", "form update", "navigation")
|
|
472
|
+
- **actionDetails**: Complete details of what action was performed
|
|
473
|
+
- **targetElement**: Contains `SelectorDescriptor` (primary selector) and `mimicId` (reference identifier used during learning)
|
|
474
|
+
- **executedAt**: Timestamp when the step was executed
|
|
475
|
+
- **flags**: Metadata about the snapshot (needsRetry, hasErrors, troubleshootingEnabled, etc.)
|
|
476
|
+
|
|
477
|
+
**Note**: The `mimicId` values in snapshots reference `data-mimic-id` attributes that are dynamically injected into the page by Mimic at runtime. These markers are used during the learning phase to help align the LLM on which components to interact with — you don't need to add them to your application code.
|
|
478
|
+
|
|
479
|
+
## Configuration
|
|
480
|
+
|
|
481
|
+
### AI Model Selection
|
|
482
|
+
|
|
483
|
+
**OpenAI:**
|
|
484
|
+
```typescript
|
|
485
|
+
import { openai } from '@ai-sdk/openai';
|
|
486
|
+
const brains = openai('gpt-4o-mini'); // or 'gpt-4', 'gpt-4-turbo', etc.
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Ollama (Local Models):**
|
|
490
|
+
```typescript
|
|
491
|
+
import { ollama } from 'ollama-ai-provider-v2';
|
|
492
|
+
const brains = ollama('llama3.2') as LanguageModel;
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
**Note**: The `eyes` parameter is optional and may be removed in future versions. Currently, if not provided, the `brains` model is used for all operations.
|
|
496
|
+
|
|
497
|
+
### Playwright Configuration
|
|
498
|
+
|
|
499
|
+
Ensure your `playwright.config.ts` is set up correctly:
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import { defineConfig } from '@playwright/test';
|
|
503
|
+
|
|
504
|
+
export default defineConfig({
|
|
505
|
+
testDir: './tests', // or wherever your tests are
|
|
506
|
+
use: {
|
|
507
|
+
trace: 'on-first-retry',
|
|
508
|
+
},
|
|
509
|
+
// ... other config
|
|
510
|
+
});
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
## Best Practices
|
|
514
|
+
|
|
515
|
+
### 1. Use Descriptive Steps
|
|
516
|
+
|
|
517
|
+
Be specific in your instructions:
|
|
518
|
+
|
|
519
|
+
```typescript
|
|
520
|
+
// ✅ Good
|
|
521
|
+
await mimic`
|
|
522
|
+
click on the "Sign In" button in the header
|
|
523
|
+
type "admin@example.com" into the email input field
|
|
524
|
+
`;
|
|
525
|
+
|
|
526
|
+
// ❌ Less clear
|
|
527
|
+
await mimic`
|
|
528
|
+
click button
|
|
529
|
+
type email
|
|
530
|
+
`;
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
### 2. Combine with Assertions
|
|
534
|
+
|
|
535
|
+
Always verify the results:
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
await mimic`
|
|
539
|
+
navigate to /dashboard
|
|
540
|
+
click on "Create Project"
|
|
541
|
+
type "My Project" into the project name field
|
|
542
|
+
click on "Save"
|
|
543
|
+
`;
|
|
544
|
+
|
|
545
|
+
await expect(page.locator('text=My Project')).toBeVisible();
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
### 3. Use Test Steps for Debugging
|
|
549
|
+
|
|
550
|
+
Mimic automatically creates Playwright test steps, making it easy to debug:
|
|
551
|
+
|
|
552
|
+
```typescript
|
|
553
|
+
// Each line becomes a test step in Playwright's trace viewer
|
|
554
|
+
await mimic`
|
|
555
|
+
navigate to https://example.com
|
|
556
|
+
click on "Products"
|
|
557
|
+
click on "View Details"
|
|
558
|
+
`;
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
Mimic also captures an initial screenshot with markers and attaches it to the test report, making it easy to see the page state at the start of the test.
|
|
562
|
+
|
|
563
|
+
### 4. Handle Dynamic Content
|
|
564
|
+
|
|
565
|
+
For dynamic content, combine mimic with Playwright waits:
|
|
566
|
+
|
|
567
|
+
```typescript
|
|
568
|
+
await mimic`click on "Load More"`;
|
|
569
|
+
await page.waitForSelector('text=New Content');
|
|
570
|
+
await mimic`click on "New Content"`;
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Mimic automatically handles waiting for elements to be ready before interacting with them, but you may need additional waits for complex dynamic content.
|
|
574
|
+
|
|
575
|
+
### 5. Token Usage
|
|
576
|
+
|
|
577
|
+
Mimic tracks token usage automatically (early mode - we're working out the best way to report on usage). Monitor your AI provider's usage to optimize costs:
|
|
578
|
+
|
|
579
|
+
- Use smaller models (like `gpt-4o-mini`) for faster, cheaper tests
|
|
580
|
+
- Use larger models only when needed for complex reasoning
|
|
581
|
+
|
|
582
|
+
## Troubleshooting
|
|
583
|
+
|
|
584
|
+
### Element Not Found
|
|
585
|
+
|
|
586
|
+
If mimic can't find an element, try:
|
|
587
|
+
1. Be more specific: `click on "Submit" button` instead of `click on "Submit"`
|
|
588
|
+
2. Use unique identifiers: `click on the login button with id "submit-btn"`
|
|
589
|
+
3. Check if the element is visible: Add a wait before the action
|
|
590
|
+
4. **Check snapshots**: If a test was previously working, check the `.mimic.json` snapshot file to see what selector was used
|
|
591
|
+
|
|
592
|
+
### Slow Execution
|
|
593
|
+
|
|
594
|
+
AI model calls take time. To speed up:
|
|
595
|
+
1. Use faster models (e.g., `gpt-4o-mini` instead of `gpt-4`)
|
|
596
|
+
2. Batch related actions when possible
|
|
597
|
+
3. Use Playwright's native selectors for simple, stable elements
|
|
598
|
+
4. **Leverage snapshots**: Once a test passes, subsequent runs use snapshots and skip AI calls entirely
|
|
599
|
+
|
|
600
|
+
### Snapshot Issues
|
|
601
|
+
|
|
602
|
+
If snapshots aren't working as expected:
|
|
603
|
+
1. Check that `.mimic.json` files are being created in `__mimic__/` directories
|
|
604
|
+
2. Verify selector descriptors in snapshots are valid
|
|
605
|
+
3. If selectors become stale, Mimic will automatically regenerate the affected steps
|
|
606
|
+
4. Delete the snapshot file to force regeneration if needed
|
|
607
|
+
5. Use `--troubleshoot` flag to force regeneration: `npx playwright test --troubleshoot`
|
|
608
|
+
|
|
609
|
+
### Troubleshoot Mode
|
|
610
|
+
|
|
611
|
+
Troubleshoot mode can be enabled by passing the `--troubleshoot` flag when running tests:
|
|
612
|
+
|
|
613
|
+
```bash
|
|
614
|
+
npx playwright test --troubleshoot
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
This mode:
|
|
618
|
+
- Still attempts to use existing snapshots first
|
|
619
|
+
- Regenerates actions only if snapshot replay fails
|
|
620
|
+
- Useful for debugging and updating snapshots after fixing issues
|
|
621
|
+
|
|
622
|
+
### Storage System
|
|
623
|
+
|
|
624
|
+
The snapshot storage system provides:
|
|
625
|
+
- ✅ Automatic snapshot creation on successful test runs
|
|
626
|
+
- ✅ Selector descriptor storage for reliable element identification
|
|
627
|
+
- ✅ Fast replay without AI calls
|
|
628
|
+
- ✅ Selective regeneration: only regenerates steps that don't exist or have changed
|
|
629
|
+
- ✅ Multiple tests per snapshot file (organized by testHash)
|
|
630
|
+
- ✅ Efficient lookup using `stepsByHash` for fast step retrieval
|
|
631
|
+
|
|
632
|
+
### API Key Issues
|
|
633
|
+
|
|
634
|
+
Ensure your `.env` file is loaded:
|
|
635
|
+
```typescript
|
|
636
|
+
import "dotenv/config"; // At the top of your test-utils.ts
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
### Test Tags
|
|
640
|
+
|
|
641
|
+
Test tags like `@mimic` are used for internal reference and filtering during development. They are not part of the public API and may change.
|
|
642
|
+
|
|
643
|
+
## Examples
|
|
644
|
+
|
|
645
|
+
### E-commerce Checkout Flow
|
|
646
|
+
|
|
647
|
+
```typescript
|
|
648
|
+
test('complete checkout process', async ({ page, mimic }) => {
|
|
649
|
+
await mimic`
|
|
650
|
+
navigate to https://store.example.com
|
|
651
|
+
click on "Add to Cart" for "Product Name"
|
|
652
|
+
click on the shopping cart icon
|
|
653
|
+
click on "Proceed to Checkout"
|
|
654
|
+
type "john@example.com" into the email field
|
|
655
|
+
type "123 Main St" into the address field
|
|
656
|
+
type "New York" into the city field
|
|
657
|
+
select "United States" from the country dropdown
|
|
658
|
+
type "10001" into the zip code field
|
|
659
|
+
click on "Continue to Payment"
|
|
660
|
+
type "4242 4242 4242 4242" into the card number field
|
|
661
|
+
type "12/25" into the expiration field
|
|
662
|
+
type "123" into the CVV field
|
|
663
|
+
click on "Place Order"
|
|
664
|
+
`;
|
|
665
|
+
|
|
666
|
+
await expect(page.locator('text=Order Confirmed')).toBeVisible();
|
|
667
|
+
});
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
### Form Validation Testing
|
|
671
|
+
|
|
672
|
+
```typescript
|
|
673
|
+
test('validate required fields', async ({ page, mimic }) => {
|
|
674
|
+
await mimic`
|
|
675
|
+
navigate to https://example.com/contact
|
|
676
|
+
click on "Submit" without filling fields
|
|
677
|
+
`;
|
|
678
|
+
|
|
679
|
+
await expect(page.locator('text=Email is required')).toBeVisible();
|
|
680
|
+
await expect(page.locator('text=Name is required')).toBeVisible();
|
|
681
|
+
});
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
## Contributing
|
|
685
|
+
|
|
686
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
687
|
+
|
|
688
|
+
## License
|
|
689
|
+
|
|
690
|
+
ISC
|
|
691
|
+
|
|
692
|
+
## Support
|
|
693
|
+
|
|
694
|
+
For issues, questions, or contributions, please open an issue on the GitHub repository.
|
|
695
|
+
|