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/.claude/settings.local.json +7 -0
- package/CHANGELOG.md +17 -0
- package/dist/index.cjs +367 -51
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +380 -61
- package/example/index.js +13 -13
- package/package.json +2 -1
- package/src/appium/index.ts +50 -0
- package/src/core.ts +12 -0
- package/src/cypress/index.ts +4 -3
- package/src/detox/index.ts +50 -0
- package/src/espresso/index.ts +61 -0
- package/src/index.ts +2 -1
- package/src/mobile/shared.ts +146 -0
- package/src/playwright/index.ts +4 -3
- package/src/puppeteer/index.ts +4 -3
- package/src/selenium/index.ts +4 -3
- package/src/types.ts +22 -2
- package/src/utils.ts +35 -0
- package/src/xcuitest/index.ts +58 -0
- package/events.json +0 -31924
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 ===
|
|
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
|
|
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
|
|
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
|
|
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
|
|
224
|
+
case IncrementalSource2.MouseInteraction:
|
|
74
225
|
d = data;
|
|
75
|
-
if (d.type ===
|
|
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 ?
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
139
|
-
IncrementalSource as
|
|
140
|
-
MouseInteractions as
|
|
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 ===
|
|
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
|
|
411
|
+
case EventType3.Meta:
|
|
159
412
|
if (e.data.href) {
|
|
160
413
|
code += `${indent(2)}await page.goto('${e.data.href}');
|
|
161
414
|
`;
|
|
@@ -169,27 +422,28 @@ var generatePlaywrightTests = (events) => {
|
|
|
169
422
|
`;
|
|
170
423
|
}
|
|
171
424
|
break;
|
|
172
|
-
case
|
|
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
|
|
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
|
|
438
|
+
case IncrementalSource3.MouseInteraction:
|
|
185
439
|
d = data;
|
|
186
|
-
if (d.type ===
|
|
440
|
+
if (d.type === MouseInteractions3.Click) {
|
|
187
441
|
const clickNode = nodeMap.get(d.id);
|
|
188
442
|
const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
|
|
189
443
|
(node) => node.childNodes?.map(
|
|
190
444
|
(n1) => n1?.["textContent"]
|
|
191
445
|
)
|
|
192
|
-
).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== 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;
|
|
193
447
|
if (id && d.x && d.y) {
|
|
194
448
|
code += `${indent(2)}await page.locator(\`${id}\`).click();
|
|
195
449
|
`;
|
|
@@ -199,7 +453,7 @@ var generatePlaywrightTests = (events) => {
|
|
|
199
453
|
break;
|
|
200
454
|
}
|
|
201
455
|
break;
|
|
202
|
-
case
|
|
456
|
+
case IncrementalSource3.Scroll:
|
|
203
457
|
d = data;
|
|
204
458
|
if (d.x && d.y) {
|
|
205
459
|
code += `${indent(2)}await page.mouse.wheel(() => { document.querySelector('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y}); });
|
|
@@ -208,7 +462,7 @@ var generatePlaywrightTests = (events) => {
|
|
|
208
462
|
`;
|
|
209
463
|
}
|
|
210
464
|
break;
|
|
211
|
-
case
|
|
465
|
+
case IncrementalSource3.ViewportResize:
|
|
212
466
|
d = data;
|
|
213
467
|
if (d.width && d.height) {
|
|
214
468
|
code += `${indent(2)}await page.setViewportSize({ width: ${d.width}, height: ${d.height} });
|
|
@@ -217,7 +471,7 @@ var generatePlaywrightTests = (events) => {
|
|
|
217
471
|
`;
|
|
218
472
|
}
|
|
219
473
|
break;
|
|
220
|
-
case
|
|
474
|
+
case IncrementalSource3.Input:
|
|
221
475
|
d = data;
|
|
222
476
|
if (d.text) {
|
|
223
477
|
code += `${indent(2)}await page.fill('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', '${d.text}');
|
|
@@ -226,7 +480,7 @@ var generatePlaywrightTests = (events) => {
|
|
|
226
480
|
`;
|
|
227
481
|
}
|
|
228
482
|
break;
|
|
229
|
-
case
|
|
483
|
+
case IncrementalSource3.MediaInteraction:
|
|
230
484
|
d = data;
|
|
231
485
|
if (d.type) {
|
|
232
486
|
code += `${indent(2)}await page.$eval('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', el => el.${d.type}());
|
|
@@ -248,9 +502,9 @@ var generatePlaywrightTests = (events) => {
|
|
|
248
502
|
|
|
249
503
|
// src/puppeteer/index.ts
|
|
250
504
|
import {
|
|
251
|
-
EventType as
|
|
252
|
-
IncrementalSource as
|
|
253
|
-
MouseInteractions as
|
|
505
|
+
EventType as EventType4,
|
|
506
|
+
IncrementalSource as IncrementalSource4,
|
|
507
|
+
MouseInteractions as MouseInteractions4
|
|
254
508
|
} from "@rrweb/types";
|
|
255
509
|
var generatePuppeteerTests = (events) => {
|
|
256
510
|
let code = "";
|
|
@@ -281,13 +535,13 @@ var generatePuppeteerTests = (events) => {
|
|
|
281
535
|
code += `${indent(1)}test('TODO: name the test case', async () => {
|
|
282
536
|
`;
|
|
283
537
|
const fullSnapshotEvents = events.filter(
|
|
284
|
-
(event) => event.type ===
|
|
538
|
+
(event) => event.type === EventType4.FullSnapshot
|
|
285
539
|
);
|
|
286
540
|
const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
|
|
287
541
|
events.forEach((event) => {
|
|
288
542
|
const e = event;
|
|
289
543
|
switch (e.type) {
|
|
290
|
-
case
|
|
544
|
+
case EventType4.Meta:
|
|
291
545
|
if (e.data.href) {
|
|
292
546
|
code += `${indent(2)}await page.goto('${e.data.href}');
|
|
293
547
|
`;
|
|
@@ -299,34 +553,35 @@ var generatePuppeteerTests = (events) => {
|
|
|
299
553
|
`;
|
|
300
554
|
}
|
|
301
555
|
break;
|
|
302
|
-
case
|
|
556
|
+
case EventType4.IncrementalSnapshot:
|
|
303
557
|
const data = e.data;
|
|
304
558
|
const type = data.source;
|
|
305
559
|
let d;
|
|
306
560
|
switch (type) {
|
|
307
|
-
case
|
|
561
|
+
case IncrementalSource4.MouseMove:
|
|
562
|
+
case IncrementalSource4.TouchMove:
|
|
308
563
|
d = data;
|
|
309
564
|
if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
|
|
310
565
|
code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});
|
|
311
566
|
`;
|
|
312
567
|
}
|
|
313
568
|
break;
|
|
314
|
-
case
|
|
569
|
+
case IncrementalSource4.MouseInteraction:
|
|
315
570
|
d = data;
|
|
316
|
-
if (d.type ===
|
|
571
|
+
if (d.type === MouseInteractions4.Click) {
|
|
317
572
|
const clickNode = nodeMap.get(d.id);
|
|
318
573
|
const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
|
|
319
574
|
(node) => node.childNodes?.map(
|
|
320
575
|
(n1) => n1?.["textContent"]
|
|
321
576
|
)
|
|
322
|
-
).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== 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;
|
|
323
578
|
if (id) {
|
|
324
579
|
code += `${indent(2)}await page.click('${id}');
|
|
325
580
|
`;
|
|
326
581
|
}
|
|
327
582
|
}
|
|
328
583
|
break;
|
|
329
|
-
case
|
|
584
|
+
case IncrementalSource4.Scroll:
|
|
330
585
|
d = data;
|
|
331
586
|
if (d.x && d.y) {
|
|
332
587
|
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
@@ -338,14 +593,14 @@ var generatePuppeteerTests = (events) => {
|
|
|
338
593
|
`;
|
|
339
594
|
}
|
|
340
595
|
break;
|
|
341
|
-
case
|
|
596
|
+
case IncrementalSource4.ViewportResize:
|
|
342
597
|
d = data;
|
|
343
598
|
if (d.width && d.height) {
|
|
344
599
|
code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });
|
|
345
600
|
`;
|
|
346
601
|
}
|
|
347
602
|
break;
|
|
348
|
-
case
|
|
603
|
+
case IncrementalSource4.Input:
|
|
349
604
|
d = data;
|
|
350
605
|
if (d.text) {
|
|
351
606
|
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
@@ -353,7 +608,7 @@ var generatePuppeteerTests = (events) => {
|
|
|
353
608
|
`;
|
|
354
609
|
}
|
|
355
610
|
break;
|
|
356
|
-
case
|
|
611
|
+
case IncrementalSource4.MediaInteraction:
|
|
357
612
|
d = data;
|
|
358
613
|
if (d.type) {
|
|
359
614
|
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
@@ -380,9 +635,9 @@ var generatePuppeteerTests = (events) => {
|
|
|
380
635
|
|
|
381
636
|
// src/selenium/index.ts
|
|
382
637
|
import {
|
|
383
|
-
EventType as
|
|
384
|
-
IncrementalSource as
|
|
385
|
-
MouseInteractions as
|
|
638
|
+
EventType as EventType5,
|
|
639
|
+
IncrementalSource as IncrementalSource5,
|
|
640
|
+
MouseInteractions as MouseInteractions5
|
|
386
641
|
} from "@rrweb/types";
|
|
387
642
|
var generateSeleniumTests = (events) => {
|
|
388
643
|
let code = "";
|
|
@@ -411,13 +666,13 @@ var generateSeleniumTests = (events) => {
|
|
|
411
666
|
code += `${indent(1)}test('TODO: name the test case', async () => {
|
|
412
667
|
`;
|
|
413
668
|
const fullSnapshotEvents = events.filter(
|
|
414
|
-
(event) => event.type ===
|
|
669
|
+
(event) => event.type === EventType5.FullSnapshot
|
|
415
670
|
);
|
|
416
671
|
const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
|
|
417
672
|
events.forEach((event) => {
|
|
418
673
|
const e = event;
|
|
419
674
|
switch (e.type) {
|
|
420
|
-
case
|
|
675
|
+
case EventType5.Meta:
|
|
421
676
|
if (e.data.href) {
|
|
422
677
|
code += `${indent(2)}await driver.get('${e.data.href}');
|
|
423
678
|
`;
|
|
@@ -429,34 +684,35 @@ var generateSeleniumTests = (events) => {
|
|
|
429
684
|
`;
|
|
430
685
|
}
|
|
431
686
|
break;
|
|
432
|
-
case
|
|
687
|
+
case EventType5.IncrementalSnapshot:
|
|
433
688
|
const data = e.data;
|
|
434
689
|
const type = data.source;
|
|
435
690
|
let d;
|
|
436
691
|
switch (type) {
|
|
437
|
-
case
|
|
692
|
+
case IncrementalSource5.MouseMove:
|
|
693
|
+
case IncrementalSource5.TouchMove:
|
|
438
694
|
d = data;
|
|
439
695
|
if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
|
|
440
696
|
code += `${indent(2)}await driver.actions().move({ x: ${d.positions[0].x}, y: ${d.positions[0].y} }).perform();
|
|
441
697
|
`;
|
|
442
698
|
}
|
|
443
699
|
break;
|
|
444
|
-
case
|
|
700
|
+
case IncrementalSource5.MouseInteraction:
|
|
445
701
|
d = data;
|
|
446
|
-
if (d.type ===
|
|
702
|
+
if (d.type === MouseInteractions5.Click) {
|
|
447
703
|
const clickNode = nodeMap.get(d.id);
|
|
448
704
|
const id = clickNode?.attributes?.id ? `#${clickNode?.attributes?.id}` : clickNode?.tagName === "nav" ? `${clickNode?.tagName}:text-is("${clickNode.childNodes?.filter((f) => f.tagName === "a")?.map(
|
|
449
705
|
(node) => node.childNodes?.map(
|
|
450
706
|
(n1) => n1?.["textContent"]
|
|
451
707
|
)
|
|
452
|
-
).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== 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;
|
|
453
709
|
if (id) {
|
|
454
710
|
code += `${indent(2)}await driver.findElement(By.css('${id}')).click();
|
|
455
711
|
`;
|
|
456
712
|
}
|
|
457
713
|
}
|
|
458
714
|
break;
|
|
459
|
-
case
|
|
715
|
+
case IncrementalSource5.Scroll:
|
|
460
716
|
d = data;
|
|
461
717
|
if (d.x && d.y) {
|
|
462
718
|
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
@@ -464,14 +720,14 @@ var generateSeleniumTests = (events) => {
|
|
|
464
720
|
`;
|
|
465
721
|
}
|
|
466
722
|
break;
|
|
467
|
-
case
|
|
723
|
+
case IncrementalSource5.ViewportResize:
|
|
468
724
|
d = data;
|
|
469
725
|
if (d.width && d.height) {
|
|
470
726
|
code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });
|
|
471
727
|
`;
|
|
472
728
|
}
|
|
473
729
|
break;
|
|
474
|
-
case
|
|
730
|
+
case IncrementalSource5.Input:
|
|
475
731
|
d = data;
|
|
476
732
|
if (d.text) {
|
|
477
733
|
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
@@ -483,7 +739,7 @@ var generateSeleniumTests = (events) => {
|
|
|
483
739
|
`;
|
|
484
740
|
}
|
|
485
741
|
break;
|
|
486
|
-
case
|
|
742
|
+
case IncrementalSource5.MediaInteraction:
|
|
487
743
|
d = data;
|
|
488
744
|
if (d.type) {
|
|
489
745
|
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
@@ -504,6 +760,60 @@ var generateSeleniumTests = (events) => {
|
|
|
504
760
|
return code;
|
|
505
761
|
};
|
|
506
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
|
+
|
|
507
817
|
// src/core.ts
|
|
508
818
|
var generateTests = (events, options) => {
|
|
509
819
|
switch (options?.framework) {
|
|
@@ -515,6 +825,14 @@ var generateTests = (events, options) => {
|
|
|
515
825
|
return generateSeleniumTests(events);
|
|
516
826
|
case TestFramework.PUPPETEER:
|
|
517
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);
|
|
518
836
|
default:
|
|
519
837
|
return generatePlaywrightTests(events);
|
|
520
838
|
}
|
|
@@ -523,6 +841,7 @@ var generateBrowserTests = (events, options) => {
|
|
|
523
841
|
return generateTests(events, options);
|
|
524
842
|
};
|
|
525
843
|
export {
|
|
844
|
+
MOBILE_FRAMEWORKS,
|
|
526
845
|
TestFramework,
|
|
527
846
|
generateBrowserTests
|
|
528
847
|
};
|