rrweb-browser-test 2.1.3 → 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,28 +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
- console.log(clickNode);
208
458
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
209
459
  (node) => node.childNodes?.map(
210
460
  (n1) => n1?.["textContent"]
211
461
  )
212
- ).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;
213
463
  if (id && d.x && d.y) {
214
464
  code += `${indent(2)}await page.locator(\`${id}\`).click();
215
465
  `;
@@ -219,7 +469,7 @@ var generatePlaywrightTests = (events) => {
219
469
  break;
220
470
  }
221
471
  break;
222
- case import_types2.IncrementalSource.Scroll:
472
+ case import_types3.IncrementalSource.Scroll:
223
473
  d = data;
224
474
  if (d.x && d.y) {
225
475
  code += `${indent(2)}await page.mouse.wheel(() => { document.querySelector('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y}); });
@@ -228,7 +478,7 @@ var generatePlaywrightTests = (events) => {
228
478
  `;
229
479
  }
230
480
  break;
231
- case import_types2.IncrementalSource.ViewportResize:
481
+ case import_types3.IncrementalSource.ViewportResize:
232
482
  d = data;
233
483
  if (d.width && d.height) {
234
484
  code += `${indent(2)}await page.setViewportSize({ width: ${d.width}, height: ${d.height} });
@@ -237,7 +487,7 @@ var generatePlaywrightTests = (events) => {
237
487
  `;
238
488
  }
239
489
  break;
240
- case import_types2.IncrementalSource.Input:
490
+ case import_types3.IncrementalSource.Input:
241
491
  d = data;
242
492
  if (d.text) {
243
493
  code += `${indent(2)}await page.fill('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', '${d.text}');
@@ -246,7 +496,7 @@ var generatePlaywrightTests = (events) => {
246
496
  `;
247
497
  }
248
498
  break;
249
- case import_types2.IncrementalSource.MediaInteraction:
499
+ case import_types3.IncrementalSource.MediaInteraction:
250
500
  d = data;
251
501
  if (d.type) {
252
502
  code += `${indent(2)}await page.$eval('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', el => el.${d.type}());
@@ -267,7 +517,7 @@ var generatePlaywrightTests = (events) => {
267
517
  };
268
518
 
269
519
  // src/puppeteer/index.ts
270
- var import_types3 = require("@rrweb/types");
520
+ var import_types4 = require("@rrweb/types");
271
521
  var generatePuppeteerTests = (events) => {
272
522
  let code = "";
273
523
  code += `const puppeteer = require('puppeteer');
@@ -297,13 +547,13 @@ var generatePuppeteerTests = (events) => {
297
547
  code += `${indent(1)}test('TODO: name the test case', async () => {
298
548
  `;
299
549
  const fullSnapshotEvents = events.filter(
300
- (event) => event.type === import_types3.EventType.FullSnapshot
550
+ (event) => event.type === import_types4.EventType.FullSnapshot
301
551
  );
302
552
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
303
553
  events.forEach((event) => {
304
554
  const e = event;
305
555
  switch (e.type) {
306
- case import_types3.EventType.Meta:
556
+ case import_types4.EventType.Meta:
307
557
  if (e.data.href) {
308
558
  code += `${indent(2)}await page.goto('${e.data.href}');
309
559
  `;
@@ -315,35 +565,35 @@ var generatePuppeteerTests = (events) => {
315
565
  `;
316
566
  }
317
567
  break;
318
- case import_types3.EventType.IncrementalSnapshot:
568
+ case import_types4.EventType.IncrementalSnapshot:
319
569
  const data = e.data;
320
570
  const type = data.source;
321
571
  let d;
322
572
  switch (type) {
323
- case (import_types3.IncrementalSource.MouseMove || import_types3.IncrementalSource.TouchMove):
573
+ case import_types4.IncrementalSource.MouseMove:
574
+ case import_types4.IncrementalSource.TouchMove:
324
575
  d = data;
325
576
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
326
577
  code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});
327
578
  `;
328
579
  }
329
580
  break;
330
- case import_types3.IncrementalSource.MouseInteraction:
581
+ case import_types4.IncrementalSource.MouseInteraction:
331
582
  d = data;
332
- if (d.type === import_types3.MouseInteractions.Click) {
583
+ if (d.type === import_types4.MouseInteractions.Click) {
333
584
  const clickNode = nodeMap.get(d.id);
334
- console.log(clickNode);
335
585
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
336
586
  (node) => node.childNodes?.map(
337
587
  (n1) => n1?.["textContent"]
338
588
  )
339
- ).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;
340
590
  if (id) {
341
591
  code += `${indent(2)}await page.click('${id}');
342
592
  `;
343
593
  }
344
594
  }
345
595
  break;
346
- case import_types3.IncrementalSource.Scroll:
596
+ case import_types4.IncrementalSource.Scroll:
347
597
  d = data;
348
598
  if (d.x && d.y) {
349
599
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -355,14 +605,14 @@ var generatePuppeteerTests = (events) => {
355
605
  `;
356
606
  }
357
607
  break;
358
- case import_types3.IncrementalSource.ViewportResize:
608
+ case import_types4.IncrementalSource.ViewportResize:
359
609
  d = data;
360
610
  if (d.width && d.height) {
361
611
  code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });
362
612
  `;
363
613
  }
364
614
  break;
365
- case import_types3.IncrementalSource.Input:
615
+ case import_types4.IncrementalSource.Input:
366
616
  d = data;
367
617
  if (d.text) {
368
618
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -370,7 +620,7 @@ var generatePuppeteerTests = (events) => {
370
620
  `;
371
621
  }
372
622
  break;
373
- case import_types3.IncrementalSource.MediaInteraction:
623
+ case import_types4.IncrementalSource.MediaInteraction:
374
624
  d = data;
375
625
  if (d.type) {
376
626
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -396,7 +646,7 @@ var generatePuppeteerTests = (events) => {
396
646
  };
397
647
 
398
648
  // src/selenium/index.ts
399
- var import_types4 = require("@rrweb/types");
649
+ var import_types5 = require("@rrweb/types");
400
650
  var generateSeleniumTests = (events) => {
401
651
  let code = "";
402
652
  code += `const { Builder, By, until } = require('selenium-webdriver');
@@ -424,13 +674,13 @@ var generateSeleniumTests = (events) => {
424
674
  code += `${indent(1)}test('TODO: name the test case', async () => {
425
675
  `;
426
676
  const fullSnapshotEvents = events.filter(
427
- (event) => event.type === import_types4.EventType.FullSnapshot
677
+ (event) => event.type === import_types5.EventType.FullSnapshot
428
678
  );
429
679
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
430
680
  events.forEach((event) => {
431
681
  const e = event;
432
682
  switch (e.type) {
433
- case import_types4.EventType.Meta:
683
+ case import_types5.EventType.Meta:
434
684
  if (e.data.href) {
435
685
  code += `${indent(2)}await driver.get('${e.data.href}');
436
686
  `;
@@ -442,34 +692,35 @@ var generateSeleniumTests = (events) => {
442
692
  `;
443
693
  }
444
694
  break;
445
- case import_types4.EventType.IncrementalSnapshot:
695
+ case import_types5.EventType.IncrementalSnapshot:
446
696
  const data = e.data;
447
697
  const type = data.source;
448
698
  let d;
449
699
  switch (type) {
450
- case (import_types4.IncrementalSource.MouseMove || import_types4.IncrementalSource.TouchMove):
700
+ case import_types5.IncrementalSource.MouseMove:
701
+ case import_types5.IncrementalSource.TouchMove:
451
702
  d = data;
452
703
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
453
704
  code += `${indent(2)}await driver.actions().move({ x: ${d.positions[0].x}, y: ${d.positions[0].y} }).perform();
454
705
  `;
455
706
  }
456
707
  break;
457
- case import_types4.IncrementalSource.MouseInteraction:
708
+ case import_types5.IncrementalSource.MouseInteraction:
458
709
  d = data;
459
- if (d.type === import_types4.MouseInteractions.Click) {
710
+ if (d.type === import_types5.MouseInteractions.Click) {
460
711
  const clickNode = nodeMap.get(d.id);
461
712
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
462
713
  (node) => node.childNodes?.map(
463
714
  (n1) => n1?.["textContent"]
464
715
  )
465
- ).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;
466
717
  if (id) {
467
718
  code += `${indent(2)}await driver.findElement(By.css('${id}')).click();
468
719
  `;
469
720
  }
470
721
  }
471
722
  break;
472
- case import_types4.IncrementalSource.Scroll:
723
+ case import_types5.IncrementalSource.Scroll:
473
724
  d = data;
474
725
  if (d.x && d.y) {
475
726
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -477,14 +728,14 @@ var generateSeleniumTests = (events) => {
477
728
  `;
478
729
  }
479
730
  break;
480
- case import_types4.IncrementalSource.ViewportResize:
731
+ case import_types5.IncrementalSource.ViewportResize:
481
732
  d = data;
482
733
  if (d.width && d.height) {
483
734
  code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });
484
735
  `;
485
736
  }
486
737
  break;
487
- case import_types4.IncrementalSource.Input:
738
+ case import_types5.IncrementalSource.Input:
488
739
  d = data;
489
740
  if (d.text) {
490
741
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -496,7 +747,7 @@ var generateSeleniumTests = (events) => {
496
747
  `;
497
748
  }
498
749
  break;
499
- case import_types4.IncrementalSource.MediaInteraction:
750
+ case import_types5.IncrementalSource.MediaInteraction:
500
751
  d = data;
501
752
  if (d.type) {
502
753
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -517,6 +768,60 @@ var generateSeleniumTests = (events) => {
517
768
  return code;
518
769
  };
519
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
+
520
825
  // src/core.ts
521
826
  var generateTests = (events, options) => {
522
827
  switch (options?.framework) {
@@ -528,6 +833,14 @@ var generateTests = (events, options) => {
528
833
  return generateSeleniumTests(events);
529
834
  case TestFramework.PUPPETEER:
530
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);
531
844
  default:
532
845
  return generatePlaywrightTests(events);
533
846
  }
@@ -537,6 +850,7 @@ var generateBrowserTests = (events, options) => {
537
850
  };
538
851
  // Annotate the CommonJS export names for ESM import in node:
539
852
  0 && (module.exports = {
853
+ MOBILE_FRAMEWORKS,
540
854
  TestFramework,
541
855
  generateBrowserTests
542
856
  });