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.js CHANGED
@@ -3,18 +3,34 @@ var TestFramework = {
3
3
  PLAYWRIGHT: "playwright",
4
4
  PUPPETEER: "puppeteer",
5
5
  CYPRESS: "cypress",
6
- SELENIUM: "selenium"
6
+ SELENIUM: "selenium",
7
+ APPIUM: "appium",
8
+ ESPRESSO: "espresso",
9
+ XCUITEST: "xcuitest",
10
+ DETOX: "detox"
7
11
  };
8
-
9
- // src/cypress/index.ts
10
- import {
11
- EventType,
12
- IncrementalSource,
13
- MouseInteractions
14
- } from "@rrweb/types";
12
+ var MOBILE_FRAMEWORKS = [
13
+ "appium",
14
+ "espresso",
15
+ "xcuitest",
16
+ "detox"
17
+ ];
15
18
 
16
19
  // src/utils.ts
17
20
  var indent = (level) => " ".repeat(level);
21
+ var cssSelector = (node) => {
22
+ if (!node?.tagName) return void 0;
23
+ const attrs = node.attributes ?? {};
24
+ if (attrs.id) return `#${attrs.id}`;
25
+ const text = (node.childNodes ?? []).map((n) => n?.textContent).filter(Boolean).join(" ").trim();
26
+ if (node.tagName === "a" && text) return `a:has-text("${text}")`;
27
+ const cls = attrs.class?.trim();
28
+ if (cls) {
29
+ 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("");
30
+ return `${node.tagName}${chain}`;
31
+ }
32
+ return node.tagName;
33
+ };
18
34
  var buildNodeMapFromFullSnapshots = (fullSnapshots) => {
19
35
  const idMap = /* @__PURE__ */ new Map();
20
36
  fullSnapshots.forEach((snapshot) => {
@@ -32,7 +48,141 @@ var buildNodeMapFromFullSnapshots = (fullSnapshots) => {
32
48
  return idMap;
33
49
  };
34
50
 
51
+ // src/mobile/shared.ts
52
+ import {
53
+ EventType,
54
+ IncrementalSource,
55
+ MouseInteractions
56
+ } from "@rrweb/types";
57
+ var resourceIdLeaf = (value) => {
58
+ const slash = value.lastIndexOf("/");
59
+ return slash >= 0 ? value.slice(slash + 1) : value;
60
+ };
61
+ var mobileLocator = (node) => {
62
+ if (!node) return void 0;
63
+ const a = node.attributes ?? {};
64
+ const id = a["resource-id"] ?? a["resourceId"] ?? a["testID"] ?? a["data-testid"] ?? a.id;
65
+ if (id) return { strategy: "id", value: String(id) };
66
+ const accessibility = a["content-desc"] ?? a["contentDescription"] ?? a["accessibilityIdentifier"] ?? a["accessibilityLabel"] ?? a["aria-label"] ?? a["name"];
67
+ if (accessibility)
68
+ return { strategy: "accessibility", value: String(accessibility) };
69
+ const text = a["text"] ?? (node.childNodes ?? []).map((n) => n?.textContent).filter(Boolean).join(" ").trim();
70
+ if (text) return { strategy: "text", value: String(text) };
71
+ return void 0;
72
+ };
73
+ var swipeDirection = (d) => {
74
+ const x = d.x ?? 0;
75
+ const y = d.y ?? 0;
76
+ if (Math.abs(y) >= Math.abs(x)) return y >= 0 ? "up" : "down";
77
+ return x >= 0 ? "left" : "right";
78
+ };
79
+ var extractMobileActions = (events) => {
80
+ const actions = [];
81
+ const fullSnapshots = events.filter(
82
+ (event) => event.type === EventType.FullSnapshot
83
+ );
84
+ const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshots);
85
+ events.forEach((event) => {
86
+ const e = event;
87
+ if (e.type === EventType.Meta) {
88
+ if (e.data?.href)
89
+ actions.push({ kind: "launch", url: e.data.href });
90
+ return;
91
+ }
92
+ if (e.type !== EventType.IncrementalSnapshot) return;
93
+ const data = e.data;
94
+ switch (data.source) {
95
+ case IncrementalSource.MouseInteraction: {
96
+ const d = data;
97
+ if (d.type === MouseInteractions.Click || d.type === MouseInteractions.TouchEnd) {
98
+ actions.push({
99
+ kind: "tap",
100
+ locator: mobileLocator(nodeMap.get(d.id))
101
+ });
102
+ }
103
+ break;
104
+ }
105
+ case IncrementalSource.Input: {
106
+ const d = data;
107
+ if (typeof d.text === "string") {
108
+ actions.push({
109
+ kind: "input",
110
+ locator: mobileLocator(nodeMap.get(d.id)),
111
+ text: d.text
112
+ });
113
+ }
114
+ break;
115
+ }
116
+ case IncrementalSource.Scroll:
117
+ case IncrementalSource.TouchMove: {
118
+ actions.push({
119
+ kind: "swipe",
120
+ direction: swipeDirection(data)
121
+ });
122
+ break;
123
+ }
124
+ default:
125
+ break;
126
+ }
127
+ });
128
+ return actions;
129
+ };
130
+
131
+ // src/appium/index.ts
132
+ var esc = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
133
+ var selector = (loc) => {
134
+ if (!loc) return `$('~TODO_add_accessibility_id')`;
135
+ switch (loc.strategy) {
136
+ case "id":
137
+ return `$('android=new UiSelector().resourceId("${esc(loc.value)}")')`;
138
+ case "accessibility":
139
+ return `$('~${esc(loc.value)}')`;
140
+ case "text":
141
+ return `$('android=new UiSelector().text("${esc(loc.value)}")')`;
142
+ }
143
+ };
144
+ var generateAppiumTests = (events) => {
145
+ const actions = extractMobileActions(events);
146
+ let code = "";
147
+ code += `// Appium + WebdriverIO \u2014 generated from a session recording
148
+ `;
149
+ code += `describe('replayed session', () => {
150
+ `;
151
+ code += `${indent(2)}it('replays the recorded user flow', async () => {
152
+ `;
153
+ actions.forEach((a) => {
154
+ switch (a.kind) {
155
+ case "launch":
156
+ code += `${indent(4)}await driver.launchApp();
157
+ `;
158
+ break;
159
+ case "tap":
160
+ code += `${indent(4)}await ${selector(a.locator)}.click();
161
+ `;
162
+ break;
163
+ case "input":
164
+ code += `${indent(4)}await ${selector(a.locator)}.setValue('${esc(a.text)}');
165
+ `;
166
+ break;
167
+ case "swipe":
168
+ code += `${indent(4)}await driver.execute('mobile: swipeGesture', { direction: '${a.direction}', percent: 0.75 });
169
+ `;
170
+ break;
171
+ }
172
+ });
173
+ code += `${indent(2)}});
174
+ `;
175
+ code += `});
176
+ `;
177
+ return code;
178
+ };
179
+
35
180
  // src/cypress/index.ts
181
+ import {
182
+ EventType as EventType2,
183
+ IncrementalSource as IncrementalSource2,
184
+ MouseInteractions as MouseInteractions2
185
+ } from "@rrweb/types";
36
186
  var generateCypressTests = (events) => {
37
187
  let code = "";
38
188
  code += `describe('TODO: name the test block', () => {
@@ -40,13 +190,13 @@ var generateCypressTests = (events) => {
40
190
  code += ` it('TODO: name the test case', () => {
41
191
  `;
42
192
  const fullSnapshotEvents = events.filter(
43
- (event) => event.type === EventType.FullSnapshot
193
+ (event) => event.type === EventType2.FullSnapshot
44
194
  );
45
195
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
46
196
  events.forEach((event) => {
47
197
  const e = event;
48
198
  switch (e.type) {
49
- case EventType.Meta:
199
+ case EventType2.Meta:
50
200
  if (e.data.href) {
51
201
  code += `${indent(3)}cy.visit('${e.data.href}');
52
202
  `;
@@ -58,27 +208,28 @@ var generateCypressTests = (events) => {
58
208
  `;
59
209
  }
60
210
  break;
61
- case EventType.IncrementalSnapshot:
211
+ case EventType2.IncrementalSnapshot:
62
212
  const data = e.data;
63
213
  const type = data.source;
64
214
  let d;
65
215
  switch (type) {
66
- case (IncrementalSource.MouseMove || IncrementalSource.TouchMove):
216
+ case IncrementalSource2.MouseMove:
217
+ case IncrementalSource2.TouchMove:
67
218
  d = data;
68
219
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
69
220
  code += `${indent(3)}cy.get('body').trigger('mousemove', { clientX: ${d.positions[0].x}, clientY: ${d.positions[0].y} });
70
221
  `;
71
222
  }
72
223
  break;
73
- case IncrementalSource.MouseInteraction:
224
+ case IncrementalSource2.MouseInteraction:
74
225
  d = data;
75
- if (d.type === MouseInteractions.Click) {
226
+ if (d.type === MouseInteractions2.Click) {
76
227
  const clickNode = nodeMap.get(d.id);
77
228
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
78
229
  (node) => node.childNodes?.map(
79
230
  (n1) => n1?.["textContent"]
80
231
  )
81
- ).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;
232
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
82
233
  if (id) {
83
234
  if (clickNode?.tagName === "nav") {
84
235
  code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();
@@ -90,21 +241,21 @@ var generateCypressTests = (events) => {
90
241
  }
91
242
  }
92
243
  break;
93
- case IncrementalSource.Scroll:
244
+ case IncrementalSource2.Scroll:
94
245
  d = data;
95
246
  if (d.x && d.y) {
96
247
  code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y});
97
248
  `;
98
249
  }
99
250
  break;
100
- case IncrementalSource.ViewportResize:
251
+ case IncrementalSource2.ViewportResize:
101
252
  d = data;
102
253
  if (d.width && d.height) {
103
254
  code += `${indent(3)}cy.viewport(${d.width}, ${d.height});
104
255
  `;
105
256
  }
106
257
  break;
107
- case IncrementalSource.Input:
258
+ case IncrementalSource2.Input:
108
259
  d = data;
109
260
  if (d.text) {
110
261
  code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').type('${d.text}');
@@ -113,7 +264,7 @@ var generateCypressTests = (events) => {
113
264
  `;
114
265
  }
115
266
  break;
116
- case IncrementalSource.MediaInteraction:
267
+ case IncrementalSource2.MediaInteraction:
117
268
  d = data;
118
269
  if (d.type) {
119
270
  code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').then((el) => el[0].${d.type}());
@@ -133,11 +284,113 @@ var generateCypressTests = (events) => {
133
284
  return code;
134
285
  };
135
286
 
287
+ // src/detox/index.ts
288
+ var esc2 = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
289
+ var matcher = (loc) => {
290
+ if (!loc) return `by.id('TODO_add_testID')`;
291
+ switch (loc.strategy) {
292
+ case "id":
293
+ return `by.id('${esc2(loc.value)}')`;
294
+ case "accessibility":
295
+ return `by.label('${esc2(loc.value)}')`;
296
+ case "text":
297
+ return `by.text('${esc2(loc.value)}')`;
298
+ }
299
+ };
300
+ var generateDetoxTests = (events) => {
301
+ const actions = extractMobileActions(events);
302
+ let code = "";
303
+ code += `// Detox \u2014 generated from a session recording
304
+ `;
305
+ code += `describe('replayed session', () => {
306
+ `;
307
+ code += `${indent(2)}it('replays the recorded user flow', async () => {
308
+ `;
309
+ actions.forEach((a) => {
310
+ switch (a.kind) {
311
+ case "launch":
312
+ code += `${indent(4)}await device.launchApp({ newInstance: true });
313
+ `;
314
+ break;
315
+ case "tap":
316
+ code += `${indent(4)}await element(${matcher(a.locator)}).tap();
317
+ `;
318
+ break;
319
+ case "input":
320
+ code += `${indent(4)}await element(${matcher(a.locator)}).typeText('${esc2(a.text)}');
321
+ `;
322
+ break;
323
+ case "swipe":
324
+ code += `${indent(4)}await element(by.id('scrollView')).swipe('${a.direction}');
325
+ `;
326
+ break;
327
+ }
328
+ });
329
+ code += `${indent(2)}});
330
+ `;
331
+ code += `});
332
+ `;
333
+ return code;
334
+ };
335
+
336
+ // src/espresso/index.ts
337
+ var esc3 = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
338
+ var matcher2 = (loc) => {
339
+ if (!loc) return `withContentDescription("TODO_add_content_description")`;
340
+ switch (loc.strategy) {
341
+ case "id":
342
+ return `withId(R.id.${resourceIdLeaf(loc.value)})`;
343
+ case "accessibility":
344
+ return `withContentDescription("${esc3(loc.value)}")`;
345
+ case "text":
346
+ return `withText("${esc3(loc.value)}")`;
347
+ }
348
+ };
349
+ var swipeFn = (direction) => ({
350
+ up: "swipeUp",
351
+ down: "swipeDown",
352
+ left: "swipeLeft",
353
+ right: "swipeRight"
354
+ })[direction];
355
+ var generateEspressoTests = (events) => {
356
+ const actions = extractMobileActions(events);
357
+ let code = "";
358
+ code += `// Espresso (Kotlin) \u2014 generated from a session recording
359
+ `;
360
+ code += `@Test
361
+ `;
362
+ code += `fun replaySession() {
363
+ `;
364
+ actions.forEach((a) => {
365
+ switch (a.kind) {
366
+ case "launch":
367
+ code += `${indent(2)}// App launch is handled by ActivityScenarioRule
368
+ `;
369
+ break;
370
+ case "tap":
371
+ code += `${indent(2)}onView(${matcher2(a.locator)}).perform(click())
372
+ `;
373
+ break;
374
+ case "input":
375
+ code += `${indent(2)}onView(${matcher2(a.locator)}).perform(typeText("${esc3(a.text)}"), closeSoftKeyboard())
376
+ `;
377
+ break;
378
+ case "swipe":
379
+ code += `${indent(2)}onView(isRoot()).perform(${swipeFn(a.direction)}())
380
+ `;
381
+ break;
382
+ }
383
+ });
384
+ code += `}
385
+ `;
386
+ return code;
387
+ };
388
+
136
389
  // src/playwright/index.ts
137
390
  import {
138
- EventType as EventType2,
139
- IncrementalSource as IncrementalSource2,
140
- MouseInteractions as MouseInteractions2
391
+ EventType as EventType3,
392
+ IncrementalSource as IncrementalSource3,
393
+ MouseInteractions as MouseInteractions3
141
394
  } from "@rrweb/types";
142
395
  var generatePlaywrightTests = (events) => {
143
396
  let code = "";
@@ -147,7 +400,7 @@ var generatePlaywrightTests = (events) => {
147
400
  code += `test('TODO: name the test block', async ({ page, context }) => {
148
401
  `;
149
402
  const fullSnapshotEvents = events.filter(
150
- (event) => event.type === EventType2.FullSnapshot
403
+ (event) => event.type === EventType3.FullSnapshot
151
404
  );
152
405
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
153
406
  code += `${indent(2)}const newTab = await context.newPage();
@@ -155,7 +408,7 @@ var generatePlaywrightTests = (events) => {
155
408
  events.forEach((event) => {
156
409
  const e = event;
157
410
  switch (e.type) {
158
- case EventType2.Meta:
411
+ case EventType3.Meta:
159
412
  if (e.data.href) {
160
413
  code += `${indent(2)}await page.goto('${e.data.href}');
161
414
  `;
@@ -169,28 +422,28 @@ var generatePlaywrightTests = (events) => {
169
422
  `;
170
423
  }
171
424
  break;
172
- case EventType2.IncrementalSnapshot:
425
+ case EventType3.IncrementalSnapshot:
173
426
  const data = e.data;
174
427
  const type = data.source;
175
428
  let d;
176
429
  switch (type) {
177
- case (IncrementalSource2.MouseMove || IncrementalSource2.TouchMove):
430
+ case IncrementalSource3.MouseMove:
431
+ case IncrementalSource3.TouchMove:
178
432
  d = data;
179
433
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
180
434
  code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});
181
435
  `;
182
436
  }
183
437
  break;
184
- case IncrementalSource2.MouseInteraction:
438
+ case IncrementalSource3.MouseInteraction:
185
439
  d = data;
186
- if (d.type === MouseInteractions2.Click) {
440
+ if (d.type === MouseInteractions3.Click) {
187
441
  const clickNode = nodeMap.get(d.id);
188
- console.log(clickNode);
189
442
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
190
443
  (node) => node.childNodes?.map(
191
444
  (n1) => n1?.["textContent"]
192
445
  )
193
- ).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;
446
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
194
447
  if (id && d.x && d.y) {
195
448
  code += `${indent(2)}await page.locator(\`${id}\`).click();
196
449
  `;
@@ -200,7 +453,7 @@ var generatePlaywrightTests = (events) => {
200
453
  break;
201
454
  }
202
455
  break;
203
- case IncrementalSource2.Scroll:
456
+ case IncrementalSource3.Scroll:
204
457
  d = data;
205
458
  if (d.x && d.y) {
206
459
  code += `${indent(2)}await page.mouse.wheel(() => { document.querySelector('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y}); });
@@ -209,7 +462,7 @@ var generatePlaywrightTests = (events) => {
209
462
  `;
210
463
  }
211
464
  break;
212
- case IncrementalSource2.ViewportResize:
465
+ case IncrementalSource3.ViewportResize:
213
466
  d = data;
214
467
  if (d.width && d.height) {
215
468
  code += `${indent(2)}await page.setViewportSize({ width: ${d.width}, height: ${d.height} });
@@ -218,7 +471,7 @@ var generatePlaywrightTests = (events) => {
218
471
  `;
219
472
  }
220
473
  break;
221
- case IncrementalSource2.Input:
474
+ case IncrementalSource3.Input:
222
475
  d = data;
223
476
  if (d.text) {
224
477
  code += `${indent(2)}await page.fill('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', '${d.text}');
@@ -227,7 +480,7 @@ var generatePlaywrightTests = (events) => {
227
480
  `;
228
481
  }
229
482
  break;
230
- case IncrementalSource2.MediaInteraction:
483
+ case IncrementalSource3.MediaInteraction:
231
484
  d = data;
232
485
  if (d.type) {
233
486
  code += `${indent(2)}await page.$eval('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', el => el.${d.type}());
@@ -249,9 +502,9 @@ var generatePlaywrightTests = (events) => {
249
502
 
250
503
  // src/puppeteer/index.ts
251
504
  import {
252
- EventType as EventType3,
253
- IncrementalSource as IncrementalSource3,
254
- MouseInteractions as MouseInteractions3
505
+ EventType as EventType4,
506
+ IncrementalSource as IncrementalSource4,
507
+ MouseInteractions as MouseInteractions4
255
508
  } from "@rrweb/types";
256
509
  var generatePuppeteerTests = (events) => {
257
510
  let code = "";
@@ -282,13 +535,13 @@ var generatePuppeteerTests = (events) => {
282
535
  code += `${indent(1)}test('TODO: name the test case', async () => {
283
536
  `;
284
537
  const fullSnapshotEvents = events.filter(
285
- (event) => event.type === EventType3.FullSnapshot
538
+ (event) => event.type === EventType4.FullSnapshot
286
539
  );
287
540
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
288
541
  events.forEach((event) => {
289
542
  const e = event;
290
543
  switch (e.type) {
291
- case EventType3.Meta:
544
+ case EventType4.Meta:
292
545
  if (e.data.href) {
293
546
  code += `${indent(2)}await page.goto('${e.data.href}');
294
547
  `;
@@ -300,35 +553,35 @@ var generatePuppeteerTests = (events) => {
300
553
  `;
301
554
  }
302
555
  break;
303
- case EventType3.IncrementalSnapshot:
556
+ case EventType4.IncrementalSnapshot:
304
557
  const data = e.data;
305
558
  const type = data.source;
306
559
  let d;
307
560
  switch (type) {
308
- case (IncrementalSource3.MouseMove || IncrementalSource3.TouchMove):
561
+ case IncrementalSource4.MouseMove:
562
+ case IncrementalSource4.TouchMove:
309
563
  d = data;
310
564
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
311
565
  code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});
312
566
  `;
313
567
  }
314
568
  break;
315
- case IncrementalSource3.MouseInteraction:
569
+ case IncrementalSource4.MouseInteraction:
316
570
  d = data;
317
- if (d.type === MouseInteractions3.Click) {
571
+ if (d.type === MouseInteractions4.Click) {
318
572
  const clickNode = nodeMap.get(d.id);
319
- console.log(clickNode);
320
573
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
321
574
  (node) => node.childNodes?.map(
322
575
  (n1) => n1?.["textContent"]
323
576
  )
324
- ).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;
577
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
325
578
  if (id) {
326
579
  code += `${indent(2)}await page.click('${id}');
327
580
  `;
328
581
  }
329
582
  }
330
583
  break;
331
- case IncrementalSource3.Scroll:
584
+ case IncrementalSource4.Scroll:
332
585
  d = data;
333
586
  if (d.x && d.y) {
334
587
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -340,14 +593,14 @@ var generatePuppeteerTests = (events) => {
340
593
  `;
341
594
  }
342
595
  break;
343
- case IncrementalSource3.ViewportResize:
596
+ case IncrementalSource4.ViewportResize:
344
597
  d = data;
345
598
  if (d.width && d.height) {
346
599
  code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });
347
600
  `;
348
601
  }
349
602
  break;
350
- case IncrementalSource3.Input:
603
+ case IncrementalSource4.Input:
351
604
  d = data;
352
605
  if (d.text) {
353
606
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -355,7 +608,7 @@ var generatePuppeteerTests = (events) => {
355
608
  `;
356
609
  }
357
610
  break;
358
- case IncrementalSource3.MediaInteraction:
611
+ case IncrementalSource4.MediaInteraction:
359
612
  d = data;
360
613
  if (d.type) {
361
614
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -382,9 +635,9 @@ var generatePuppeteerTests = (events) => {
382
635
 
383
636
  // src/selenium/index.ts
384
637
  import {
385
- EventType as EventType4,
386
- IncrementalSource as IncrementalSource4,
387
- MouseInteractions as MouseInteractions4
638
+ EventType as EventType5,
639
+ IncrementalSource as IncrementalSource5,
640
+ MouseInteractions as MouseInteractions5
388
641
  } from "@rrweb/types";
389
642
  var generateSeleniumTests = (events) => {
390
643
  let code = "";
@@ -413,13 +666,13 @@ var generateSeleniumTests = (events) => {
413
666
  code += `${indent(1)}test('TODO: name the test case', async () => {
414
667
  `;
415
668
  const fullSnapshotEvents = events.filter(
416
- (event) => event.type === EventType4.FullSnapshot
669
+ (event) => event.type === EventType5.FullSnapshot
417
670
  );
418
671
  const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
419
672
  events.forEach((event) => {
420
673
  const e = event;
421
674
  switch (e.type) {
422
- case EventType4.Meta:
675
+ case EventType5.Meta:
423
676
  if (e.data.href) {
424
677
  code += `${indent(2)}await driver.get('${e.data.href}');
425
678
  `;
@@ -431,34 +684,35 @@ var generateSeleniumTests = (events) => {
431
684
  `;
432
685
  }
433
686
  break;
434
- case EventType4.IncrementalSnapshot:
687
+ case EventType5.IncrementalSnapshot:
435
688
  const data = e.data;
436
689
  const type = data.source;
437
690
  let d;
438
691
  switch (type) {
439
- case (IncrementalSource4.MouseMove || IncrementalSource4.TouchMove):
692
+ case IncrementalSource5.MouseMove:
693
+ case IncrementalSource5.TouchMove:
440
694
  d = data;
441
695
  if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
442
696
  code += `${indent(2)}await driver.actions().move({ x: ${d.positions[0].x}, y: ${d.positions[0].y} }).perform();
443
697
  `;
444
698
  }
445
699
  break;
446
- case IncrementalSource4.MouseInteraction:
700
+ case IncrementalSource5.MouseInteraction:
447
701
  d = data;
448
- if (d.type === MouseInteractions4.Click) {
702
+ if (d.type === MouseInteractions5.Click) {
449
703
  const clickNode = nodeMap.get(d.id);
450
704
  const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
451
705
  (node) => node.childNodes?.map(
452
706
  (n1) => n1?.["textContent"]
453
707
  )
454
- ).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;
708
+ ).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
455
709
  if (id) {
456
710
  code += `${indent(2)}await driver.findElement(By.css('${id}')).click();
457
711
  `;
458
712
  }
459
713
  }
460
714
  break;
461
- case IncrementalSource4.Scroll:
715
+ case IncrementalSource5.Scroll:
462
716
  d = data;
463
717
  if (d.x && d.y) {
464
718
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -466,14 +720,14 @@ var generateSeleniumTests = (events) => {
466
720
  `;
467
721
  }
468
722
  break;
469
- case IncrementalSource4.ViewportResize:
723
+ case IncrementalSource5.ViewportResize:
470
724
  d = data;
471
725
  if (d.width && d.height) {
472
726
  code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });
473
727
  `;
474
728
  }
475
729
  break;
476
- case IncrementalSource4.Input:
730
+ case IncrementalSource5.Input:
477
731
  d = data;
478
732
  if (d.text) {
479
733
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -485,7 +739,7 @@ var generateSeleniumTests = (events) => {
485
739
  `;
486
740
  }
487
741
  break;
488
- case IncrementalSource4.MediaInteraction:
742
+ case IncrementalSource5.MediaInteraction:
489
743
  d = data;
490
744
  if (d.type) {
491
745
  const elementId = nodeMap.get(d.id)?.attributes?.id || "";
@@ -506,6 +760,60 @@ var generateSeleniumTests = (events) => {
506
760
  return code;
507
761
  };
508
762
 
763
+ // src/xcuitest/index.ts
764
+ var esc4 = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
765
+ var tapTarget = (loc) => {
766
+ if (!loc) return `app.buttons["TODO_add_accessibility_identifier"]`;
767
+ if (loc.strategy === "text") return `app.staticTexts["${esc4(loc.value)}"]`;
768
+ return `app.buttons["${esc4(loc.value)}"]`;
769
+ };
770
+ var inputTarget = (loc) => {
771
+ if (!loc) return `app.textFields["TODO_add_accessibility_identifier"]`;
772
+ return `app.textFields["${esc4(loc.value)}"]`;
773
+ };
774
+ var swipeFn2 = (direction) => ({
775
+ up: "swipeUp",
776
+ down: "swipeDown",
777
+ left: "swipeLeft",
778
+ right: "swipeRight"
779
+ })[direction];
780
+ var generateXcuiTests = (events) => {
781
+ const actions = extractMobileActions(events);
782
+ let code = "";
783
+ code += `// XCUITest (Swift) \u2014 generated from a session recording
784
+ `;
785
+ code += `func testReplaySession() {
786
+ `;
787
+ code += `${indent(2)}let app = XCUIApplication()
788
+ `;
789
+ code += `${indent(2)}app.launch()
790
+ `;
791
+ actions.forEach((a) => {
792
+ switch (a.kind) {
793
+ case "launch":
794
+ break;
795
+ // already launched above
796
+ case "tap":
797
+ code += `${indent(2)}${tapTarget(a.locator)}.tap()
798
+ `;
799
+ break;
800
+ case "input":
801
+ code += `${indent(2)}${inputTarget(a.locator)}.tap()
802
+ `;
803
+ code += `${indent(2)}${inputTarget(a.locator)}.typeText("${esc4(a.text)}")
804
+ `;
805
+ break;
806
+ case "swipe":
807
+ code += `${indent(2)}app.${swipeFn2(a.direction)}()
808
+ `;
809
+ break;
810
+ }
811
+ });
812
+ code += `}
813
+ `;
814
+ return code;
815
+ };
816
+
509
817
  // src/core.ts
510
818
  var generateTests = (events, options) => {
511
819
  switch (options?.framework) {
@@ -517,6 +825,14 @@ var generateTests = (events, options) => {
517
825
  return generateSeleniumTests(events);
518
826
  case TestFramework.PUPPETEER:
519
827
  return generatePuppeteerTests(events);
828
+ case TestFramework.APPIUM:
829
+ return generateAppiumTests(events);
830
+ case TestFramework.ESPRESSO:
831
+ return generateEspressoTests(events);
832
+ case TestFramework.XCUITEST:
833
+ return generateXcuiTests(events);
834
+ case TestFramework.DETOX:
835
+ return generateDetoxTests(events);
520
836
  default:
521
837
  return generatePlaywrightTests(events);
522
838
  }
@@ -525,6 +841,7 @@ var generateBrowserTests = (events, options) => {
525
841
  return generateTests(events, options);
526
842
  };
527
843
  export {
844
+ MOBILE_FRAMEWORKS,
528
845
  TestFramework,
529
846
  generateBrowserTests
530
847
  };