rrweb-browser-test 2.1.4 → 2.2.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/dist/index.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ MOBILE_FRAMEWORKS: () => MOBILE_FRAMEWORKS,
23
24
  TestFramework: () => TestFramework,
24
25
  generateBrowserTests: () => generateBrowserTests
25
26
  });
@@ -30,14 +31,34 @@ var TestFramework = {
30
31
  PLAYWRIGHT: "playwright",
31
32
  PUPPETEER: "puppeteer",
32
33
  CYPRESS: "cypress",
33
- SELENIUM: "selenium"
34
+ SELENIUM: "selenium",
35
+ APPIUM: "appium",
36
+ ESPRESSO: "espresso",
37
+ XCUITEST: "xcuitest",
38
+ DETOX: "detox"
34
39
  };
35
-
36
- // src/cypress/index.ts
37
- var import_types = require("@rrweb/types");
40
+ var MOBILE_FRAMEWORKS = [
41
+ "appium",
42
+ "espresso",
43
+ "xcuitest",
44
+ "detox"
45
+ ];
38
46
 
39
47
  // src/utils.ts
40
48
  var indent = (level) => " ".repeat(level);
49
+ var cssSelector = (node) => {
50
+ if (!node?.tagName) return void 0;
51
+ const attrs = node.attributes ?? {};
52
+ if (attrs.id) return `#${attrs.id}`;
53
+ const text = (node.childNodes ?? []).map((n) => n?.textContent).filter(Boolean).join(" ").trim();
54
+ if (node.tagName === "a" && text) return `a:has-text("${text}")`;
55
+ const cls = attrs.class?.trim();
56
+ if (cls) {
57
+ const chain = cls.split(/\s+/).filter(Boolean).map((c) => /^[A-Za-z_-][\w-]*$/.test(c) ? c : `[class~="${c}"]`).map((c) => c.startsWith("[") ? c : `.${c}`).join("");
58
+ return `${node.tagName}${chain}`;
59
+ }
60
+ return node.tagName;
61
+ };
41
62
  var buildNodeMapFromFullSnapshots = (fullSnapshots) => {
42
63
  const idMap = /* @__PURE__ */ new Map();
43
64
  fullSnapshots.forEach((snapshot) => {
@@ -55,7 +76,133 @@ var buildNodeMapFromFullSnapshots = (fullSnapshots) => {
55
76
  return idMap;
56
77
  };
57
78
 
79
+ // src/mobile/shared.ts
80
+ var import_types = require("@rrweb/types");
81
+ var resourceIdLeaf = (value) => {
82
+ const slash = value.lastIndexOf("/");
83
+ return slash >= 0 ? value.slice(slash + 1) : value;
84
+ };
85
+ var mobileLocator = (node) => {
86
+ if (!node) return void 0;
87
+ const a = node.attributes ?? {};
88
+ const id = a["resource-id"] ?? a["resourceId"] ?? a["testID"] ?? a["data-testid"] ?? a.id;
89
+ if (id) return { strategy: "id", value: String(id) };
90
+ const accessibility = a["content-desc"] ?? a["contentDescription"] ?? a["accessibilityIdentifier"] ?? a["accessibilityLabel"] ?? a["aria-label"] ?? a["name"];
91
+ if (accessibility)
92
+ return { strategy: "accessibility", value: String(accessibility) };
93
+ const text = a["text"] ?? (node.childNodes ?? []).map((n) => n?.textContent).filter(Boolean).join(" ").trim();
94
+ if (text) return { strategy: "text", value: String(text) };
95
+ return void 0;
96
+ };
97
+ var swipeDirection = (d) => {
98
+ const x = d.x ?? 0;
99
+ const y = d.y ?? 0;
100
+ if (Math.abs(y) >= Math.abs(x)) return y >= 0 ? "up" : "down";
101
+ return x >= 0 ? "left" : "right";
102
+ };
103
+ var extractMobileActions = (events) => {
104
+ const actions = [];
105
+ const fullSnapshots = events.filter(
106
+ (event) => event.type === import_types.EventType.FullSnapshot
107
+ );
108
+ const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshots);
109
+ events.forEach((event) => {
110
+ const e = event;
111
+ if (e.type === import_types.EventType.Meta) {
112
+ if (e.data?.href)
113
+ actions.push({ kind: "launch", url: e.data.href });
114
+ return;
115
+ }
116
+ if (e.type !== import_types.EventType.IncrementalSnapshot) return;
117
+ const data = e.data;
118
+ switch (data.source) {
119
+ case import_types.IncrementalSource.MouseInteraction: {
120
+ const d = data;
121
+ if (d.type === import_types.MouseInteractions.Click || d.type === import_types.MouseInteractions.TouchEnd) {
122
+ actions.push({
123
+ kind: "tap",
124
+ locator: mobileLocator(nodeMap.get(d.id))
125
+ });
126
+ }
127
+ break;
128
+ }
129
+ case import_types.IncrementalSource.Input: {
130
+ const d = data;
131
+ if (typeof d.text === "string") {
132
+ actions.push({
133
+ kind: "input",
134
+ locator: mobileLocator(nodeMap.get(d.id)),
135
+ text: d.text
136
+ });
137
+ }
138
+ break;
139
+ }
140
+ case import_types.IncrementalSource.Scroll:
141
+ case import_types.IncrementalSource.TouchMove: {
142
+ actions.push({
143
+ kind: "swipe",
144
+ direction: swipeDirection(data)
145
+ });
146
+ break;
147
+ }
148
+ default:
149
+ break;
150
+ }
151
+ });
152
+ return actions;
153
+ };
154
+
155
+ // src/appium/index.ts
156
+ var esc = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
157
+ var selector = (loc) => {
158
+ if (!loc) return `$('~TODO_add_accessibility_id')`;
159
+ switch (loc.strategy) {
160
+ case "id":
161
+ return `$('android=new UiSelector().resourceId("${esc(loc.value)}")')`;
162
+ case "accessibility":
163
+ return `$('~${esc(loc.value)}')`;
164
+ case "text":
165
+ return `$('android=new UiSelector().text("${esc(loc.value)}")')`;
166
+ }
167
+ };
168
+ var generateAppiumTests = (events) => {
169
+ const actions = extractMobileActions(events);
170
+ let code = "";
171
+ code += `// Appium + WebdriverIO \u2014 generated from a session recording
172
+ `;
173
+ code += `describe('replayed session', () => {
174
+ `;
175
+ code += `${indent(2)}it('replays the recorded user flow', async () => {
176
+ `;
177
+ actions.forEach((a) => {
178
+ switch (a.kind) {
179
+ case "launch":
180
+ code += `${indent(4)}await driver.launchApp();
181
+ `;
182
+ break;
183
+ case "tap":
184
+ code += `${indent(4)}await ${selector(a.locator)}.click();
185
+ `;
186
+ break;
187
+ case "input":
188
+ code += `${indent(4)}await ${selector(a.locator)}.setValue('${esc(a.text)}');
189
+ `;
190
+ break;
191
+ case "swipe":
192
+ code += `${indent(4)}await driver.execute('mobile: swipeGesture', { direction: '${a.direction}', percent: 0.75 });
193
+ `;
194
+ break;
195
+ }
196
+ });
197
+ code += `${indent(2)}});
198
+ `;
199
+ code += `});
200
+ `;
201
+ return code;
202
+ };
203
+
58
204
  // src/cypress/index.ts
205
+ var import_types2 = require("@rrweb/types");
59
206
  var generateCypressTests = (events) => {
60
207
  let code = "";
61
208
  code += `describe('TODO: name the test block', () => {
@@ -63,13 +210,13 @@ var generateCypressTests = (events) => {
63
210
  code += ` it('TODO: name the test case', () => {
64
211
  `;
65
212
  const fullSnapshotEvents = events.filter(
66
- (event) => event.type === import_types.EventType.FullSnapshot
213
+ (event) => event.type === import_types2.EventType.FullSnapshot
67
214
  );
68
215
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
69
216
  events.forEach((event) => {
70
217
  const e = event;
71
218
  switch (e.type) {
72
- case import_types.EventType.Meta:
219
+ case import_types2.EventType.Meta:
73
220
  if (e.data.href) {
74
221
  code += `${indent(3)}cy.visit('${e.data.href}');
75
222
  `;
@@ -81,27 +228,28 @@ var generateCypressTests = (events) => {
81
228
  `;
82
229
  }
83
230
  break;
84
- case import_types.EventType.IncrementalSnapshot:
231
+ case import_types2.EventType.IncrementalSnapshot:
85
232
  const data = e.data;
86
233
  const type = data.source;
87
234
  let d;
88
235
  switch (type) {
89
- case (import_types.IncrementalSource.MouseMove || import_types.IncrementalSource.TouchMove):
236
+ case import_types2.IncrementalSource.MouseMove:
237
+ case import_types2.IncrementalSource.TouchMove:
90
238
  d = data;
91
239
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
92
240
  code += `${indent(3)}cy.get('body').trigger('mousemove', { clientX: ${d.positions[0].x}, clientY: ${d.positions[0].y} });
93
241
  `;
94
242
  }
95
243
  break;
96
- case import_types.IncrementalSource.MouseInteraction:
244
+ case import_types2.IncrementalSource.MouseInteraction:
97
245
  d = data;
98
- if (d.type === import_types.MouseInteractions.Click) {
246
+ if (d.type === import_types2.MouseInteractions.Click) {
99
247
  const clickNode = nodeMap.get(d.id);
100
248
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
101
249
  (node) => node.childNodes?.map(
102
250
  (n1) => n1?.["textContent"]
103
251
  )
104
- ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? `${clickNode?.tagName}.${clickNode?.attributes?.class}` : void 0;
252
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
105
253
  if (id) {
106
254
  if (clickNode?.tagName === "nav") {
107
255
  code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();
@@ -113,21 +261,21 @@ var generateCypressTests = (events) => {
113
261
  }
114
262
  }
115
263
  break;
116
- case import_types.IncrementalSource.Scroll:
264
+ case import_types2.IncrementalSource.Scroll:
117
265
  d = data;
118
266
  if (d.x && d.y) {
119
267
  code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y});
120
268
  `;
121
269
  }
122
270
  break;
123
- case import_types.IncrementalSource.ViewportResize:
271
+ case import_types2.IncrementalSource.ViewportResize:
124
272
  d = data;
125
273
  if (d.width && d.height) {
126
274
  code += `${indent(3)}cy.viewport(${d.width}, ${d.height});
127
275
  `;
128
276
  }
129
277
  break;
130
- case import_types.IncrementalSource.Input:
278
+ case import_types2.IncrementalSource.Input:
131
279
  d = data;
132
280
  if (d.text) {
133
281
  code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').type('${d.text}');
@@ -136,7 +284,7 @@ var generateCypressTests = (events) => {
136
284
  `;
137
285
  }
138
286
  break;
139
- case import_types.IncrementalSource.MediaInteraction:
287
+ case import_types2.IncrementalSource.MediaInteraction:
140
288
  d = data;
141
289
  if (d.type) {
142
290
  code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').then((el) => el[0].${d.type}());
@@ -156,8 +304,110 @@ var generateCypressTests = (events) => {
156
304
  return code;
157
305
  };
158
306
 
307
+ // src/detox/index.ts
308
+ var esc2 = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
309
+ var matcher = (loc) => {
310
+ if (!loc) return `by.id('TODO_add_testID')`;
311
+ switch (loc.strategy) {
312
+ case "id":
313
+ return `by.id('${esc2(loc.value)}')`;
314
+ case "accessibility":
315
+ return `by.label('${esc2(loc.value)}')`;
316
+ case "text":
317
+ return `by.text('${esc2(loc.value)}')`;
318
+ }
319
+ };
320
+ var generateDetoxTests = (events) => {
321
+ const actions = extractMobileActions(events);
322
+ let code = "";
323
+ code += `// Detox \u2014 generated from a session recording
324
+ `;
325
+ code += `describe('replayed session', () => {
326
+ `;
327
+ code += `${indent(2)}it('replays the recorded user flow', async () => {
328
+ `;
329
+ actions.forEach((a) => {
330
+ switch (a.kind) {
331
+ case "launch":
332
+ code += `${indent(4)}await device.launchApp({ newInstance: true });
333
+ `;
334
+ break;
335
+ case "tap":
336
+ code += `${indent(4)}await element(${matcher(a.locator)}).tap();
337
+ `;
338
+ break;
339
+ case "input":
340
+ code += `${indent(4)}await element(${matcher(a.locator)}).typeText('${esc2(a.text)}');
341
+ `;
342
+ break;
343
+ case "swipe":
344
+ code += `${indent(4)}await element(by.id('scrollView')).swipe('${a.direction}');
345
+ `;
346
+ break;
347
+ }
348
+ });
349
+ code += `${indent(2)}});
350
+ `;
351
+ code += `});
352
+ `;
353
+ return code;
354
+ };
355
+
356
+ // src/espresso/index.ts
357
+ var esc3 = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
358
+ var matcher2 = (loc) => {
359
+ if (!loc) return `withContentDescription("TODO_add_content_description")`;
360
+ switch (loc.strategy) {
361
+ case "id":
362
+ return `withId(R.id.${resourceIdLeaf(loc.value)})`;
363
+ case "accessibility":
364
+ return `withContentDescription("${esc3(loc.value)}")`;
365
+ case "text":
366
+ return `withText("${esc3(loc.value)}")`;
367
+ }
368
+ };
369
+ var swipeFn = (direction) => ({
370
+ up: "swipeUp",
371
+ down: "swipeDown",
372
+ left: "swipeLeft",
373
+ right: "swipeRight"
374
+ })[direction];
375
+ var generateEspressoTests = (events) => {
376
+ const actions = extractMobileActions(events);
377
+ let code = "";
378
+ code += `// Espresso (Kotlin) \u2014 generated from a session recording
379
+ `;
380
+ code += `@Test
381
+ `;
382
+ code += `fun replaySession() {
383
+ `;
384
+ actions.forEach((a) => {
385
+ switch (a.kind) {
386
+ case "launch":
387
+ code += `${indent(2)}// App launch is handled by ActivityScenarioRule
388
+ `;
389
+ break;
390
+ case "tap":
391
+ code += `${indent(2)}onView(${matcher2(a.locator)}).perform(click())
392
+ `;
393
+ break;
394
+ case "input":
395
+ code += `${indent(2)}onView(${matcher2(a.locator)}).perform(typeText("${esc3(a.text)}"), closeSoftKeyboard())
396
+ `;
397
+ break;
398
+ case "swipe":
399
+ code += `${indent(2)}onView(isRoot()).perform(${swipeFn(a.direction)}())
400
+ `;
401
+ break;
402
+ }
403
+ });
404
+ code += `}
405
+ `;
406
+ return code;
407
+ };
408
+
159
409
  // src/playwright/index.ts
160
- var import_types2 = require("@rrweb/types");
410
+ var import_types3 = require("@rrweb/types");
161
411
  var generatePlaywrightTests = (events) => {
162
412
  let code = "";
163
413
  code += `import { test, expect } from '@playwright/test';
@@ -166,7 +416,7 @@ var generatePlaywrightTests = (events) => {
166
416
  code += `test('TODO: name the test block', async ({ page, context }) => {
167
417
  `;
168
418
  const fullSnapshotEvents = events.filter(
169
- (event) => event.type === import_types2.EventType.FullSnapshot
419
+ (event) => event.type === import_types3.EventType.FullSnapshot
170
420
  );
171
421
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
172
422
  code += `${indent(2)}const newTab = await context.newPage();
@@ -174,7 +424,7 @@ var generatePlaywrightTests = (events) => {
174
424
  events.forEach((event) => {
175
425
  const e = event;
176
426
  switch (e.type) {
177
- case import_types2.EventType.Meta:
427
+ case import_types3.EventType.Meta:
178
428
  if (e.data.href) {
179
429
  code += `${indent(2)}await page.goto('${e.data.href}');
180
430
  `;
@@ -188,27 +438,28 @@ var generatePlaywrightTests = (events) => {
188
438
  `;
189
439
  }
190
440
  break;
191
- case import_types2.EventType.IncrementalSnapshot:
441
+ case import_types3.EventType.IncrementalSnapshot:
192
442
  const data = e.data;
193
443
  const type = data.source;
194
444
  let d;
195
445
  switch (type) {
196
- case (import_types2.IncrementalSource.MouseMove || import_types2.IncrementalSource.TouchMove):
446
+ case import_types3.IncrementalSource.MouseMove:
447
+ case import_types3.IncrementalSource.TouchMove:
197
448
  d = data;
198
449
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
199
450
  code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});
200
451
  `;
201
452
  }
202
453
  break;
203
- case import_types2.IncrementalSource.MouseInteraction:
454
+ case import_types3.IncrementalSource.MouseInteraction:
204
455
  d = data;
205
- if (d.type === import_types2.MouseInteractions.Click) {
456
+ if (d.type === import_types3.MouseInteractions.Click) {
206
457
  const clickNode = nodeMap.get(d.id);
207
458
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
208
459
  (node) => node.childNodes?.map(
209
460
  (n1) => n1?.["textContent"]
210
461
  )
211
- ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? `${clickNode?.tagName}.${clickNode?.attributes?.class}` : void 0;
462
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
212
463
  if (id && d.x && d.y) {
213
464
  code += `${indent(2)}await page.locator(\`${id}\`).click();
214
465
  `;
@@ -218,7 +469,7 @@ var generatePlaywrightTests = (events) => {
218
469
  break;
219
470
  }
220
471
  break;
221
- case import_types2.IncrementalSource.Scroll:
472
+ case import_types3.IncrementalSource.Scroll:
222
473
  d = data;
223
474
  if (d.x && d.y) {
224
475
  code += `${indent(2)}await page.mouse.wheel(() => { document.querySelector('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y}); });
@@ -227,7 +478,7 @@ var generatePlaywrightTests = (events) => {
227
478
  `;
228
479
  }
229
480
  break;
230
- case import_types2.IncrementalSource.ViewportResize:
481
+ case import_types3.IncrementalSource.ViewportResize:
231
482
  d = data;
232
483
  if (d.width && d.height) {
233
484
  code += `${indent(2)}await page.setViewportSize({ width: ${d.width}, height: ${d.height} });
@@ -236,7 +487,7 @@ var generatePlaywrightTests = (events) => {
236
487
  `;
237
488
  }
238
489
  break;
239
- case import_types2.IncrementalSource.Input:
490
+ case import_types3.IncrementalSource.Input:
240
491
  d = data;
241
492
  if (d.text) {
242
493
  code += `${indent(2)}await page.fill('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', '${d.text}');
@@ -245,7 +496,7 @@ var generatePlaywrightTests = (events) => {
245
496
  `;
246
497
  }
247
498
  break;
248
- case import_types2.IncrementalSource.MediaInteraction:
499
+ case import_types3.IncrementalSource.MediaInteraction:
249
500
  d = data;
250
501
  if (d.type) {
251
502
  code += `${indent(2)}await page.$eval('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', el => el.${d.type}());
@@ -266,7 +517,7 @@ var generatePlaywrightTests = (events) => {
266
517
  };
267
518
 
268
519
  // src/puppeteer/index.ts
269
- var import_types3 = require("@rrweb/types");
520
+ var import_types4 = require("@rrweb/types");
270
521
  var generatePuppeteerTests = (events) => {
271
522
  let code = "";
272
523
  code += `const puppeteer = require('puppeteer');
@@ -296,13 +547,13 @@ var generatePuppeteerTests = (events) => {
296
547
  code += `${indent(1)}test('TODO: name the test case', async () => {
297
548
  `;
298
549
  const fullSnapshotEvents = events.filter(
299
- (event) => event.type === import_types3.EventType.FullSnapshot
550
+ (event) => event.type === import_types4.EventType.FullSnapshot
300
551
  );
301
552
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
302
553
  events.forEach((event) => {
303
554
  const e = event;
304
555
  switch (e.type) {
305
- case import_types3.EventType.Meta:
556
+ case import_types4.EventType.Meta:
306
557
  if (e.data.href) {
307
558
  code += `${indent(2)}await page.goto('${e.data.href}');
308
559
  `;
@@ -314,34 +565,35 @@ var generatePuppeteerTests = (events) => {
314
565
  `;
315
566
  }
316
567
  break;
317
- case import_types3.EventType.IncrementalSnapshot:
568
+ case import_types4.EventType.IncrementalSnapshot:
318
569
  const data = e.data;
319
570
  const type = data.source;
320
571
  let d;
321
572
  switch (type) {
322
- case (import_types3.IncrementalSource.MouseMove || import_types3.IncrementalSource.TouchMove):
573
+ case import_types4.IncrementalSource.MouseMove:
574
+ case import_types4.IncrementalSource.TouchMove:
323
575
  d = data;
324
576
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
325
577
  code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});
326
578
  `;
327
579
  }
328
580
  break;
329
- case import_types3.IncrementalSource.MouseInteraction:
581
+ case import_types4.IncrementalSource.MouseInteraction:
330
582
  d = data;
331
- if (d.type === import_types3.MouseInteractions.Click) {
583
+ if (d.type === import_types4.MouseInteractions.Click) {
332
584
  const clickNode = nodeMap.get(d.id);
333
585
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
334
586
  (node) => node.childNodes?.map(
335
587
  (n1) => n1?.["textContent"]
336
588
  )
337
- ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? `${clickNode?.tagName}.${clickNode?.attributes?.class}` : void 0;
589
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
338
590
  if (id) {
339
591
  code += `${indent(2)}await page.click('${id}');
340
592
  `;
341
593
  }
342
594
  }
343
595
  break;
344
- case import_types3.IncrementalSource.Scroll:
596
+ case import_types4.IncrementalSource.Scroll:
345
597
  d = data;
346
598
  if (d.x && d.y) {
347
599
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -353,14 +605,14 @@ var generatePuppeteerTests = (events) => {
353
605
  `;
354
606
  }
355
607
  break;
356
- case import_types3.IncrementalSource.ViewportResize:
608
+ case import_types4.IncrementalSource.ViewportResize:
357
609
  d = data;
358
610
  if (d.width && d.height) {
359
611
  code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });
360
612
  `;
361
613
  }
362
614
  break;
363
- case import_types3.IncrementalSource.Input:
615
+ case import_types4.IncrementalSource.Input:
364
616
  d = data;
365
617
  if (d.text) {
366
618
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -368,7 +620,7 @@ var generatePuppeteerTests = (events) => {
368
620
  `;
369
621
  }
370
622
  break;
371
- case import_types3.IncrementalSource.MediaInteraction:
623
+ case import_types4.IncrementalSource.MediaInteraction:
372
624
  d = data;
373
625
  if (d.type) {
374
626
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -394,7 +646,7 @@ var generatePuppeteerTests = (events) => {
394
646
  };
395
647
 
396
648
  // src/selenium/index.ts
397
- var import_types4 = require("@rrweb/types");
649
+ var import_types5 = require("@rrweb/types");
398
650
  var generateSeleniumTests = (events) => {
399
651
  let code = "";
400
652
  code += `const { Builder, By, until } = require('selenium-webdriver');
@@ -422,13 +674,13 @@ var generateSeleniumTests = (events) => {
422
674
  code += `${indent(1)}test('TODO: name the test case', async () => {
423
675
  `;
424
676
  const fullSnapshotEvents = events.filter(
425
- (event) => event.type === import_types4.EventType.FullSnapshot
677
+ (event) => event.type === import_types5.EventType.FullSnapshot
426
678
  );
427
679
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
428
680
  events.forEach((event) => {
429
681
  const e = event;
430
682
  switch (e.type) {
431
- case import_types4.EventType.Meta:
683
+ case import_types5.EventType.Meta:
432
684
  if (e.data.href) {
433
685
  code += `${indent(2)}await driver.get('${e.data.href}');
434
686
  `;
@@ -440,34 +692,35 @@ var generateSeleniumTests = (events) => {
440
692
  `;
441
693
  }
442
694
  break;
443
- case import_types4.EventType.IncrementalSnapshot:
695
+ case import_types5.EventType.IncrementalSnapshot:
444
696
  const data = e.data;
445
697
  const type = data.source;
446
698
  let d;
447
699
  switch (type) {
448
- case (import_types4.IncrementalSource.MouseMove || import_types4.IncrementalSource.TouchMove):
700
+ case import_types5.IncrementalSource.MouseMove:
701
+ case import_types5.IncrementalSource.TouchMove:
449
702
  d = data;
450
703
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
451
704
  code += `${indent(2)}await driver.actions().move({ x: ${d.positions[0].x}, y: ${d.positions[0].y} }).perform();
452
705
  `;
453
706
  }
454
707
  break;
455
- case import_types4.IncrementalSource.MouseInteraction:
708
+ case import_types5.IncrementalSource.MouseInteraction:
456
709
  d = data;
457
- if (d.type === import_types4.MouseInteractions.Click) {
710
+ if (d.type === import_types5.MouseInteractions.Click) {
458
711
  const clickNode = nodeMap.get(d.id);
459
712
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
460
713
  (node) => node.childNodes?.map(
461
714
  (n1) => n1?.["textContent"]
462
715
  )
463
- ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? `${clickNode?.tagName}.${clickNode?.attributes?.class}` : void 0;
716
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
464
717
  if (id) {
465
718
  code += `${indent(2)}await driver.findElement(By.css('${id}')).click();
466
719
  `;
467
720
  }
468
721
  }
469
722
  break;
470
- case import_types4.IncrementalSource.Scroll:
723
+ case import_types5.IncrementalSource.Scroll:
471
724
  d = data;
472
725
  if (d.x && d.y) {
473
726
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -475,14 +728,14 @@ var generateSeleniumTests = (events) => {
475
728
  `;
476
729
  }
477
730
  break;
478
- case import_types4.IncrementalSource.ViewportResize:
731
+ case import_types5.IncrementalSource.ViewportResize:
479
732
  d = data;
480
733
  if (d.width && d.height) {
481
734
  code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });
482
735
  `;
483
736
  }
484
737
  break;
485
- case import_types4.IncrementalSource.Input:
738
+ case import_types5.IncrementalSource.Input:
486
739
  d = data;
487
740
  if (d.text) {
488
741
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -494,7 +747,7 @@ var generateSeleniumTests = (events) => {
494
747
  `;
495
748
  }
496
749
  break;
497
- case import_types4.IncrementalSource.MediaInteraction:
750
+ case import_types5.IncrementalSource.MediaInteraction:
498
751
  d = data;
499
752
  if (d.type) {
500
753
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -515,6 +768,60 @@ var generateSeleniumTests = (events) => {
515
768
  return code;
516
769
  };
517
770
 
771
+ // src/xcuitest/index.ts
772
+ var esc4 = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
773
+ var tapTarget = (loc) => {
774
+ if (!loc) return `app.buttons["TODO_add_accessibility_identifier"]`;
775
+ if (loc.strategy === "text") return `app.staticTexts["${esc4(loc.value)}"]`;
776
+ return `app.buttons["${esc4(loc.value)}"]`;
777
+ };
778
+ var inputTarget = (loc) => {
779
+ if (!loc) return `app.textFields["TODO_add_accessibility_identifier"]`;
780
+ return `app.textFields["${esc4(loc.value)}"]`;
781
+ };
782
+ var swipeFn2 = (direction) => ({
783
+ up: "swipeUp",
784
+ down: "swipeDown",
785
+ left: "swipeLeft",
786
+ right: "swipeRight"
787
+ })[direction];
788
+ var generateXcuiTests = (events) => {
789
+ const actions = extractMobileActions(events);
790
+ let code = "";
791
+ code += `// XCUITest (Swift) \u2014 generated from a session recording
792
+ `;
793
+ code += `func testReplaySession() {
794
+ `;
795
+ code += `${indent(2)}let app = XCUIApplication()
796
+ `;
797
+ code += `${indent(2)}app.launch()
798
+ `;
799
+ actions.forEach((a) => {
800
+ switch (a.kind) {
801
+ case "launch":
802
+ break;
803
+ // already launched above
804
+ case "tap":
805
+ code += `${indent(2)}${tapTarget(a.locator)}.tap()
806
+ `;
807
+ break;
808
+ case "input":
809
+ code += `${indent(2)}${inputTarget(a.locator)}.tap()
810
+ `;
811
+ code += `${indent(2)}${inputTarget(a.locator)}.typeText("${esc4(a.text)}")
812
+ `;
813
+ break;
814
+ case "swipe":
815
+ code += `${indent(2)}app.${swipeFn2(a.direction)}()
816
+ `;
817
+ break;
818
+ }
819
+ });
820
+ code += `}
821
+ `;
822
+ return code;
823
+ };
824
+
518
825
  // src/core.ts
519
826
  var generateTests = (events, options) => {
520
827
  switch (options?.framework) {
@@ -526,6 +833,14 @@ var generateTests = (events, options) => {
526
833
  return generateSeleniumTests(events);
527
834
  case TestFramework.PUPPETEER:
528
835
  return generatePuppeteerTests(events);
836
+ case TestFramework.APPIUM:
837
+ return generateAppiumTests(events);
838
+ case TestFramework.ESPRESSO:
839
+ return generateEspressoTests(events);
840
+ case TestFramework.XCUITEST:
841
+ return generateXcuiTests(events);
842
+ case TestFramework.DETOX:
843
+ return generateDetoxTests(events);
529
844
  default:
530
845
  return generatePlaywrightTests(events);
531
846
  }
@@ -535,6 +850,7 @@ var generateBrowserTests = (events, options) => {
535
850
  };
536
851
  // Annotate the CommonJS export names for ESM import in node:
537
852
  0 && (module.exports = {
853
+ MOBILE_FRAMEWORKS,
538
854
  TestFramework,
539
855
  generateBrowserTests
540
856
  });