@browserflow-ai/core 0.0.6

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.
Files changed (57) hide show
  1. package/dist/config-schema.d.ts +354 -0
  2. package/dist/config-schema.d.ts.map +1 -0
  3. package/dist/config-schema.js +83 -0
  4. package/dist/config-schema.js.map +1 -0
  5. package/dist/config.d.ts +107 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/config.js +5 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/duration.d.ts +39 -0
  10. package/dist/duration.d.ts.map +1 -0
  11. package/dist/duration.js +111 -0
  12. package/dist/duration.js.map +1 -0
  13. package/dist/index.d.ts +12 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +20 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/locator-object.d.ts +556 -0
  18. package/dist/locator-object.d.ts.map +1 -0
  19. package/dist/locator-object.js +114 -0
  20. package/dist/locator-object.js.map +1 -0
  21. package/dist/lockfile.d.ts +1501 -0
  22. package/dist/lockfile.d.ts.map +1 -0
  23. package/dist/lockfile.js +86 -0
  24. package/dist/lockfile.js.map +1 -0
  25. package/dist/run-store.d.ts +81 -0
  26. package/dist/run-store.d.ts.map +1 -0
  27. package/dist/run-store.js +181 -0
  28. package/dist/run-store.js.map +1 -0
  29. package/dist/spec-loader.d.ts +17 -0
  30. package/dist/spec-loader.d.ts.map +1 -0
  31. package/dist/spec-loader.js +37 -0
  32. package/dist/spec-loader.js.map +1 -0
  33. package/dist/spec-schema.d.ts +1411 -0
  34. package/dist/spec-schema.d.ts.map +1 -0
  35. package/dist/spec-schema.js +239 -0
  36. package/dist/spec-schema.js.map +1 -0
  37. package/package.json +45 -0
  38. package/schemas/browserflow.schema.json +220 -0
  39. package/schemas/lockfile.schema.json +568 -0
  40. package/schemas/spec-v2.schema.json +413 -0
  41. package/src/config-schema.test.ts +190 -0
  42. package/src/config-schema.ts +111 -0
  43. package/src/config.ts +112 -0
  44. package/src/duration.test.ts +175 -0
  45. package/src/duration.ts +128 -0
  46. package/src/index.ts +136 -0
  47. package/src/json-schemas.test.ts +374 -0
  48. package/src/locator-object.test.ts +323 -0
  49. package/src/locator-object.ts +250 -0
  50. package/src/lockfile.test.ts +345 -0
  51. package/src/lockfile.ts +209 -0
  52. package/src/run-store.test.ts +232 -0
  53. package/src/run-store.ts +240 -0
  54. package/src/spec-loader.test.ts +181 -0
  55. package/src/spec-loader.ts +47 -0
  56. package/src/spec-schema.test.ts +360 -0
  57. package/src/spec-schema.ts +347 -0
@@ -0,0 +1,556 @@
1
+ /**
2
+ * LocatorObject types and resolution utilities
3
+ *
4
+ * @see bf-6ig for implementation task
5
+ */
6
+ import { z } from 'zod';
7
+ import type { Page, Locator } from 'playwright-core';
8
+ /**
9
+ * Supported locator strategy types
10
+ */
11
+ export type LocatorStrategyType = 'testid' | 'role' | 'label' | 'placeholder' | 'text' | 'css';
12
+ /**
13
+ * Locator strategy definition
14
+ */
15
+ export interface LocatorStrategy {
16
+ type: LocatorStrategyType;
17
+ value?: string;
18
+ attribute?: string;
19
+ role?: string;
20
+ name?: string;
21
+ exact?: boolean;
22
+ text?: string;
23
+ selector?: string;
24
+ }
25
+ /**
26
+ * DOM fingerprint for element verification
27
+ */
28
+ export interface DOMFingerprint {
29
+ tag: string;
30
+ classes: string[];
31
+ attributes?: Record<string, string>;
32
+ }
33
+ /**
34
+ * Bounding box for element position
35
+ */
36
+ export interface BoundingBox {
37
+ x: number;
38
+ y: number;
39
+ width: number;
40
+ height: number;
41
+ }
42
+ /**
43
+ * Proof data for element verification
44
+ */
45
+ export interface LocatorProof {
46
+ a11y_role?: string;
47
+ a11y_name?: string;
48
+ dom_fingerprint?: DOMFingerprint;
49
+ bounding_box?: BoundingBox;
50
+ }
51
+ /**
52
+ * Scoping constraints for locator
53
+ */
54
+ export interface LocatorScoping {
55
+ within?: LocatorStrategy[];
56
+ nth?: number;
57
+ }
58
+ /**
59
+ * Complete LocatorObject - core primitive for deterministic element selection
60
+ */
61
+ export interface LocatorObject {
62
+ locator_id: string;
63
+ preferred: LocatorStrategy;
64
+ fallbacks: LocatorStrategy[];
65
+ scoping?: LocatorScoping;
66
+ proof: LocatorProof;
67
+ }
68
+ /**
69
+ * Options for resolving locators
70
+ */
71
+ export interface ResolveOptions {
72
+ useFallbacks: boolean;
73
+ timeout?: number;
74
+ }
75
+ export declare const locatorStrategyTypeSchema: z.ZodEnum<["testid", "role", "label", "placeholder", "text", "css"]>;
76
+ export declare const locatorStrategySchema: z.ZodObject<{
77
+ type: z.ZodEnum<["testid", "role", "label", "placeholder", "text", "css"]>;
78
+ value: z.ZodOptional<z.ZodString>;
79
+ attribute: z.ZodOptional<z.ZodString>;
80
+ role: z.ZodOptional<z.ZodString>;
81
+ name: z.ZodOptional<z.ZodString>;
82
+ exact: z.ZodOptional<z.ZodBoolean>;
83
+ text: z.ZodOptional<z.ZodString>;
84
+ selector: z.ZodOptional<z.ZodString>;
85
+ }, "strip", z.ZodTypeAny, {
86
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
87
+ value?: string | undefined;
88
+ exact?: boolean | undefined;
89
+ role?: string | undefined;
90
+ name?: string | undefined;
91
+ text?: string | undefined;
92
+ selector?: string | undefined;
93
+ attribute?: string | undefined;
94
+ }, {
95
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
96
+ value?: string | undefined;
97
+ exact?: boolean | undefined;
98
+ role?: string | undefined;
99
+ name?: string | undefined;
100
+ text?: string | undefined;
101
+ selector?: string | undefined;
102
+ attribute?: string | undefined;
103
+ }>;
104
+ export declare const domFingerprintSchema: z.ZodObject<{
105
+ tag: z.ZodString;
106
+ classes: z.ZodArray<z.ZodString, "many">;
107
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ tag: string;
110
+ classes: string[];
111
+ attributes?: Record<string, string> | undefined;
112
+ }, {
113
+ tag: string;
114
+ classes: string[];
115
+ attributes?: Record<string, string> | undefined;
116
+ }>;
117
+ export declare const boundingBoxSchema: z.ZodObject<{
118
+ x: z.ZodNumber;
119
+ y: z.ZodNumber;
120
+ width: z.ZodNumber;
121
+ height: z.ZodNumber;
122
+ }, "strip", z.ZodTypeAny, {
123
+ x: number;
124
+ y: number;
125
+ width: number;
126
+ height: number;
127
+ }, {
128
+ x: number;
129
+ y: number;
130
+ width: number;
131
+ height: number;
132
+ }>;
133
+ export declare const locatorProofSchema: z.ZodObject<{
134
+ a11y_role: z.ZodOptional<z.ZodString>;
135
+ a11y_name: z.ZodOptional<z.ZodString>;
136
+ dom_fingerprint: z.ZodOptional<z.ZodObject<{
137
+ tag: z.ZodString;
138
+ classes: z.ZodArray<z.ZodString, "many">;
139
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
140
+ }, "strip", z.ZodTypeAny, {
141
+ tag: string;
142
+ classes: string[];
143
+ attributes?: Record<string, string> | undefined;
144
+ }, {
145
+ tag: string;
146
+ classes: string[];
147
+ attributes?: Record<string, string> | undefined;
148
+ }>>;
149
+ bounding_box: z.ZodOptional<z.ZodObject<{
150
+ x: z.ZodNumber;
151
+ y: z.ZodNumber;
152
+ width: z.ZodNumber;
153
+ height: z.ZodNumber;
154
+ }, "strip", z.ZodTypeAny, {
155
+ x: number;
156
+ y: number;
157
+ width: number;
158
+ height: number;
159
+ }, {
160
+ x: number;
161
+ y: number;
162
+ width: number;
163
+ height: number;
164
+ }>>;
165
+ }, "strip", z.ZodTypeAny, {
166
+ a11y_role?: string | undefined;
167
+ a11y_name?: string | undefined;
168
+ dom_fingerprint?: {
169
+ tag: string;
170
+ classes: string[];
171
+ attributes?: Record<string, string> | undefined;
172
+ } | undefined;
173
+ bounding_box?: {
174
+ x: number;
175
+ y: number;
176
+ width: number;
177
+ height: number;
178
+ } | undefined;
179
+ }, {
180
+ a11y_role?: string | undefined;
181
+ a11y_name?: string | undefined;
182
+ dom_fingerprint?: {
183
+ tag: string;
184
+ classes: string[];
185
+ attributes?: Record<string, string> | undefined;
186
+ } | undefined;
187
+ bounding_box?: {
188
+ x: number;
189
+ y: number;
190
+ width: number;
191
+ height: number;
192
+ } | undefined;
193
+ }>;
194
+ export declare const locatorScopingSchema: z.ZodObject<{
195
+ within: z.ZodOptional<z.ZodArray<z.ZodObject<{
196
+ type: z.ZodEnum<["testid", "role", "label", "placeholder", "text", "css"]>;
197
+ value: z.ZodOptional<z.ZodString>;
198
+ attribute: z.ZodOptional<z.ZodString>;
199
+ role: z.ZodOptional<z.ZodString>;
200
+ name: z.ZodOptional<z.ZodString>;
201
+ exact: z.ZodOptional<z.ZodBoolean>;
202
+ text: z.ZodOptional<z.ZodString>;
203
+ selector: z.ZodOptional<z.ZodString>;
204
+ }, "strip", z.ZodTypeAny, {
205
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
206
+ value?: string | undefined;
207
+ exact?: boolean | undefined;
208
+ role?: string | undefined;
209
+ name?: string | undefined;
210
+ text?: string | undefined;
211
+ selector?: string | undefined;
212
+ attribute?: string | undefined;
213
+ }, {
214
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
215
+ value?: string | undefined;
216
+ exact?: boolean | undefined;
217
+ role?: string | undefined;
218
+ name?: string | undefined;
219
+ text?: string | undefined;
220
+ selector?: string | undefined;
221
+ attribute?: string | undefined;
222
+ }>, "many">>;
223
+ nth: z.ZodOptional<z.ZodNumber>;
224
+ }, "strip", z.ZodTypeAny, {
225
+ within?: {
226
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
227
+ value?: string | undefined;
228
+ exact?: boolean | undefined;
229
+ role?: string | undefined;
230
+ name?: string | undefined;
231
+ text?: string | undefined;
232
+ selector?: string | undefined;
233
+ attribute?: string | undefined;
234
+ }[] | undefined;
235
+ nth?: number | undefined;
236
+ }, {
237
+ within?: {
238
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
239
+ value?: string | undefined;
240
+ exact?: boolean | undefined;
241
+ role?: string | undefined;
242
+ name?: string | undefined;
243
+ text?: string | undefined;
244
+ selector?: string | undefined;
245
+ attribute?: string | undefined;
246
+ }[] | undefined;
247
+ nth?: number | undefined;
248
+ }>;
249
+ export declare const locatorObjectSchema: z.ZodObject<{
250
+ locator_id: z.ZodString;
251
+ preferred: z.ZodObject<{
252
+ type: z.ZodEnum<["testid", "role", "label", "placeholder", "text", "css"]>;
253
+ value: z.ZodOptional<z.ZodString>;
254
+ attribute: z.ZodOptional<z.ZodString>;
255
+ role: z.ZodOptional<z.ZodString>;
256
+ name: z.ZodOptional<z.ZodString>;
257
+ exact: z.ZodOptional<z.ZodBoolean>;
258
+ text: z.ZodOptional<z.ZodString>;
259
+ selector: z.ZodOptional<z.ZodString>;
260
+ }, "strip", z.ZodTypeAny, {
261
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
262
+ value?: string | undefined;
263
+ exact?: boolean | undefined;
264
+ role?: string | undefined;
265
+ name?: string | undefined;
266
+ text?: string | undefined;
267
+ selector?: string | undefined;
268
+ attribute?: string | undefined;
269
+ }, {
270
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
271
+ value?: string | undefined;
272
+ exact?: boolean | undefined;
273
+ role?: string | undefined;
274
+ name?: string | undefined;
275
+ text?: string | undefined;
276
+ selector?: string | undefined;
277
+ attribute?: string | undefined;
278
+ }>;
279
+ fallbacks: z.ZodArray<z.ZodObject<{
280
+ type: z.ZodEnum<["testid", "role", "label", "placeholder", "text", "css"]>;
281
+ value: z.ZodOptional<z.ZodString>;
282
+ attribute: z.ZodOptional<z.ZodString>;
283
+ role: z.ZodOptional<z.ZodString>;
284
+ name: z.ZodOptional<z.ZodString>;
285
+ exact: z.ZodOptional<z.ZodBoolean>;
286
+ text: z.ZodOptional<z.ZodString>;
287
+ selector: z.ZodOptional<z.ZodString>;
288
+ }, "strip", z.ZodTypeAny, {
289
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
290
+ value?: string | undefined;
291
+ exact?: boolean | undefined;
292
+ role?: string | undefined;
293
+ name?: string | undefined;
294
+ text?: string | undefined;
295
+ selector?: string | undefined;
296
+ attribute?: string | undefined;
297
+ }, {
298
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
299
+ value?: string | undefined;
300
+ exact?: boolean | undefined;
301
+ role?: string | undefined;
302
+ name?: string | undefined;
303
+ text?: string | undefined;
304
+ selector?: string | undefined;
305
+ attribute?: string | undefined;
306
+ }>, "many">;
307
+ scoping: z.ZodOptional<z.ZodObject<{
308
+ within: z.ZodOptional<z.ZodArray<z.ZodObject<{
309
+ type: z.ZodEnum<["testid", "role", "label", "placeholder", "text", "css"]>;
310
+ value: z.ZodOptional<z.ZodString>;
311
+ attribute: z.ZodOptional<z.ZodString>;
312
+ role: z.ZodOptional<z.ZodString>;
313
+ name: z.ZodOptional<z.ZodString>;
314
+ exact: z.ZodOptional<z.ZodBoolean>;
315
+ text: z.ZodOptional<z.ZodString>;
316
+ selector: z.ZodOptional<z.ZodString>;
317
+ }, "strip", z.ZodTypeAny, {
318
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
319
+ value?: string | undefined;
320
+ exact?: boolean | undefined;
321
+ role?: string | undefined;
322
+ name?: string | undefined;
323
+ text?: string | undefined;
324
+ selector?: string | undefined;
325
+ attribute?: string | undefined;
326
+ }, {
327
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
328
+ value?: string | undefined;
329
+ exact?: boolean | undefined;
330
+ role?: string | undefined;
331
+ name?: string | undefined;
332
+ text?: string | undefined;
333
+ selector?: string | undefined;
334
+ attribute?: string | undefined;
335
+ }>, "many">>;
336
+ nth: z.ZodOptional<z.ZodNumber>;
337
+ }, "strip", z.ZodTypeAny, {
338
+ within?: {
339
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
340
+ value?: string | undefined;
341
+ exact?: boolean | undefined;
342
+ role?: string | undefined;
343
+ name?: string | undefined;
344
+ text?: string | undefined;
345
+ selector?: string | undefined;
346
+ attribute?: string | undefined;
347
+ }[] | undefined;
348
+ nth?: number | undefined;
349
+ }, {
350
+ within?: {
351
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
352
+ value?: string | undefined;
353
+ exact?: boolean | undefined;
354
+ role?: string | undefined;
355
+ name?: string | undefined;
356
+ text?: string | undefined;
357
+ selector?: string | undefined;
358
+ attribute?: string | undefined;
359
+ }[] | undefined;
360
+ nth?: number | undefined;
361
+ }>>;
362
+ proof: z.ZodObject<{
363
+ a11y_role: z.ZodOptional<z.ZodString>;
364
+ a11y_name: z.ZodOptional<z.ZodString>;
365
+ dom_fingerprint: z.ZodOptional<z.ZodObject<{
366
+ tag: z.ZodString;
367
+ classes: z.ZodArray<z.ZodString, "many">;
368
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
369
+ }, "strip", z.ZodTypeAny, {
370
+ tag: string;
371
+ classes: string[];
372
+ attributes?: Record<string, string> | undefined;
373
+ }, {
374
+ tag: string;
375
+ classes: string[];
376
+ attributes?: Record<string, string> | undefined;
377
+ }>>;
378
+ bounding_box: z.ZodOptional<z.ZodObject<{
379
+ x: z.ZodNumber;
380
+ y: z.ZodNumber;
381
+ width: z.ZodNumber;
382
+ height: z.ZodNumber;
383
+ }, "strip", z.ZodTypeAny, {
384
+ x: number;
385
+ y: number;
386
+ width: number;
387
+ height: number;
388
+ }, {
389
+ x: number;
390
+ y: number;
391
+ width: number;
392
+ height: number;
393
+ }>>;
394
+ }, "strip", z.ZodTypeAny, {
395
+ a11y_role?: string | undefined;
396
+ a11y_name?: string | undefined;
397
+ dom_fingerprint?: {
398
+ tag: string;
399
+ classes: string[];
400
+ attributes?: Record<string, string> | undefined;
401
+ } | undefined;
402
+ bounding_box?: {
403
+ x: number;
404
+ y: number;
405
+ width: number;
406
+ height: number;
407
+ } | undefined;
408
+ }, {
409
+ a11y_role?: string | undefined;
410
+ a11y_name?: string | undefined;
411
+ dom_fingerprint?: {
412
+ tag: string;
413
+ classes: string[];
414
+ attributes?: Record<string, string> | undefined;
415
+ } | undefined;
416
+ bounding_box?: {
417
+ x: number;
418
+ y: number;
419
+ width: number;
420
+ height: number;
421
+ } | undefined;
422
+ }>;
423
+ }, "strip", z.ZodTypeAny, {
424
+ locator_id: string;
425
+ preferred: {
426
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
427
+ value?: string | undefined;
428
+ exact?: boolean | undefined;
429
+ role?: string | undefined;
430
+ name?: string | undefined;
431
+ text?: string | undefined;
432
+ selector?: string | undefined;
433
+ attribute?: string | undefined;
434
+ };
435
+ fallbacks: {
436
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
437
+ value?: string | undefined;
438
+ exact?: boolean | undefined;
439
+ role?: string | undefined;
440
+ name?: string | undefined;
441
+ text?: string | undefined;
442
+ selector?: string | undefined;
443
+ attribute?: string | undefined;
444
+ }[];
445
+ proof: {
446
+ a11y_role?: string | undefined;
447
+ a11y_name?: string | undefined;
448
+ dom_fingerprint?: {
449
+ tag: string;
450
+ classes: string[];
451
+ attributes?: Record<string, string> | undefined;
452
+ } | undefined;
453
+ bounding_box?: {
454
+ x: number;
455
+ y: number;
456
+ width: number;
457
+ height: number;
458
+ } | undefined;
459
+ };
460
+ scoping?: {
461
+ within?: {
462
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
463
+ value?: string | undefined;
464
+ exact?: boolean | undefined;
465
+ role?: string | undefined;
466
+ name?: string | undefined;
467
+ text?: string | undefined;
468
+ selector?: string | undefined;
469
+ attribute?: string | undefined;
470
+ }[] | undefined;
471
+ nth?: number | undefined;
472
+ } | undefined;
473
+ }, {
474
+ locator_id: string;
475
+ preferred: {
476
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
477
+ value?: string | undefined;
478
+ exact?: boolean | undefined;
479
+ role?: string | undefined;
480
+ name?: string | undefined;
481
+ text?: string | undefined;
482
+ selector?: string | undefined;
483
+ attribute?: string | undefined;
484
+ };
485
+ fallbacks: {
486
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
487
+ value?: string | undefined;
488
+ exact?: boolean | undefined;
489
+ role?: string | undefined;
490
+ name?: string | undefined;
491
+ text?: string | undefined;
492
+ selector?: string | undefined;
493
+ attribute?: string | undefined;
494
+ }[];
495
+ proof: {
496
+ a11y_role?: string | undefined;
497
+ a11y_name?: string | undefined;
498
+ dom_fingerprint?: {
499
+ tag: string;
500
+ classes: string[];
501
+ attributes?: Record<string, string> | undefined;
502
+ } | undefined;
503
+ bounding_box?: {
504
+ x: number;
505
+ y: number;
506
+ width: number;
507
+ height: number;
508
+ } | undefined;
509
+ };
510
+ scoping?: {
511
+ within?: {
512
+ type: "testid" | "role" | "label" | "placeholder" | "text" | "css";
513
+ value?: string | undefined;
514
+ exact?: boolean | undefined;
515
+ role?: string | undefined;
516
+ name?: string | undefined;
517
+ text?: string | undefined;
518
+ selector?: string | undefined;
519
+ attribute?: string | undefined;
520
+ }[] | undefined;
521
+ nth?: number | undefined;
522
+ } | undefined;
523
+ }>;
524
+ /**
525
+ * Converts a LocatorStrategy to a Playwright Locator
526
+ */
527
+ export declare function strategyToLocator(strategy: LocatorStrategy, page: Page): Locator;
528
+ /**
529
+ * Resolves a LocatorObject to a Playwright Locator
530
+ */
531
+ export declare function resolveLocator(locatorObj: LocatorObject, page: Page, options: ResolveOptions): Locator;
532
+ export type LocatorMethod = 'getByRole' | 'getByText' | 'getByLabel' | 'getByPlaceholder' | 'getByTestId' | 'getByAltText' | 'getByTitle' | 'locator';
533
+ export interface LocatorArgs {
534
+ role?: string;
535
+ name?: string | RegExp;
536
+ text?: string | RegExp;
537
+ testId?: string;
538
+ exact?: boolean;
539
+ selector?: string;
540
+ [key: string]: unknown;
541
+ }
542
+ /**
543
+ * Legacy LocatorObject interface (for backwards compatibility)
544
+ */
545
+ export interface LegacyLocatorObject {
546
+ ref?: string;
547
+ selector?: string;
548
+ method?: LocatorMethod;
549
+ args?: LocatorArgs;
550
+ description?: string;
551
+ }
552
+ /**
553
+ * Legacy function - resolves a LegacyLocatorObject to a string representation
554
+ */
555
+ export declare function resolveLegacyLocator(locator: LegacyLocatorObject): string;
556
+ //# sourceMappingURL=locator-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator-object.d.ts","sourceRoot":"","sources":["../src/locator-object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,GAAG,MAAM,GAAG,KAAK,CAAC;AAE/F;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAE1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAM9B,CAAC;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAgChF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,cAAc,GACtB,OAAO,CAoBT;AAGD,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,WAAW,GACX,YAAY,GACZ,kBAAkB,GAClB,aAAa,GACb,cAAc,GACd,YAAY,GACZ,SAAS,CAAC;AAEd,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CASzE"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * LocatorObject types and resolution utilities
3
+ *
4
+ * @see bf-6ig for implementation task
5
+ */
6
+ import { z } from 'zod';
7
+ // Zod schemas
8
+ export const locatorStrategyTypeSchema = z.enum(['testid', 'role', 'label', 'placeholder', 'text', 'css']);
9
+ export const locatorStrategySchema = z.object({
10
+ type: locatorStrategyTypeSchema,
11
+ // For testid
12
+ value: z.string().optional(),
13
+ attribute: z.string().optional(),
14
+ // For role
15
+ role: z.string().optional(),
16
+ name: z.string().optional(),
17
+ exact: z.boolean().optional(),
18
+ // For label/placeholder/text
19
+ text: z.string().optional(),
20
+ // For css
21
+ selector: z.string().optional(),
22
+ });
23
+ export const domFingerprintSchema = z.object({
24
+ tag: z.string(),
25
+ classes: z.array(z.string()),
26
+ attributes: z.record(z.string()).optional(),
27
+ });
28
+ export const boundingBoxSchema = z.object({
29
+ x: z.number(),
30
+ y: z.number(),
31
+ width: z.number(),
32
+ height: z.number(),
33
+ });
34
+ export const locatorProofSchema = z.object({
35
+ a11y_role: z.string().optional(),
36
+ a11y_name: z.string().optional(),
37
+ dom_fingerprint: domFingerprintSchema.optional(),
38
+ bounding_box: boundingBoxSchema.optional(),
39
+ });
40
+ export const locatorScopingSchema = z.object({
41
+ within: z.array(locatorStrategySchema).optional(),
42
+ nth: z.number().int().optional(),
43
+ });
44
+ export const locatorObjectSchema = z.object({
45
+ locator_id: z.string().min(1),
46
+ preferred: locatorStrategySchema,
47
+ fallbacks: z.array(locatorStrategySchema),
48
+ scoping: locatorScopingSchema.optional(),
49
+ proof: locatorProofSchema,
50
+ });
51
+ /**
52
+ * Converts a LocatorStrategy to a Playwright Locator
53
+ */
54
+ export function strategyToLocator(strategy, page) {
55
+ switch (strategy.type) {
56
+ case 'testid':
57
+ if (strategy.attribute && strategy.attribute !== 'data-testid') {
58
+ // Custom testid attribute
59
+ return page.locator(`[${strategy.attribute}="${strategy.value}"]`);
60
+ }
61
+ return page.getByTestId(strategy.value);
62
+ case 'role':
63
+ const roleOptions = {};
64
+ if (strategy.name) {
65
+ roleOptions.name = strategy.name;
66
+ roleOptions.exact = strategy.exact ?? true;
67
+ }
68
+ return page.getByRole(strategy.role, roleOptions);
69
+ case 'label':
70
+ return page.getByLabel(strategy.text);
71
+ case 'placeholder':
72
+ return page.getByPlaceholder(strategy.text);
73
+ case 'text':
74
+ return page.getByText(strategy.text);
75
+ case 'css':
76
+ return page.locator(strategy.selector);
77
+ default:
78
+ throw new Error(`Unknown locator strategy type: ${strategy.type}`);
79
+ }
80
+ }
81
+ /**
82
+ * Resolves a LocatorObject to a Playwright Locator
83
+ */
84
+ export function resolveLocator(locatorObj, page, options) {
85
+ // Start with preferred strategy
86
+ let locator = strategyToLocator(locatorObj.preferred, page);
87
+ // Apply scoping constraints
88
+ if (locatorObj.scoping?.within) {
89
+ for (const scope of locatorObj.scoping.within) {
90
+ const scopeLocator = strategyToLocator(scope, page);
91
+ locator = scopeLocator.locator(locator);
92
+ }
93
+ }
94
+ if (locatorObj.scoping?.nth !== undefined) {
95
+ locator = locator.nth(locatorObj.scoping.nth);
96
+ }
97
+ // TODO: If useFallbacks is true and locator doesn't find element,
98
+ // iterate through fallbacks. This requires async operation.
99
+ return locator;
100
+ }
101
+ /**
102
+ * Legacy function - resolves a LegacyLocatorObject to a string representation
103
+ */
104
+ export function resolveLegacyLocator(locator) {
105
+ if (locator.selector) {
106
+ return `locator(${JSON.stringify(locator.selector)})`;
107
+ }
108
+ if (locator.method && locator.args) {
109
+ const argsStr = JSON.stringify(locator.args);
110
+ return `${locator.method}(${argsStr})`;
111
+ }
112
+ return 'locator("body")';
113
+ }
114
+ //# sourceMappingURL=locator-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locator-object.js","sourceRoot":"","sources":["../src/locator-object.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkFxB,cAAc;AACd,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3G,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IA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