rrweb-browser-test 2.1.4 → 2.3.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/README.md +131 -30
- package/dist/index.cjs +1110 -361
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +1119 -375
- package/package.json +61 -36
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.github/workflows/ci.yml +0 -29
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -49
- package/events.json +0 -31924
- package/example/index.js +0 -18
- package/src/core.ts +0 -31
- package/src/cypress/index.ts +0 -126
- package/src/index.ts +0 -2
- package/src/playwright/index.ts +0 -130
- package/src/puppeteer/index.ts +0 -139
- package/src/selenium/index.ts +0 -135
- package/src/types.ts +0 -17
- package/src/utils.test.ts +0 -6
- package/src/utils.ts +0 -36
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -9
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,122 +31,770 @@ 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
|
-
|
|
37
|
-
|
|
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);
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
var q = (value) => `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r").split(String.fromCharCode(8232)).join("\\u2028").split(String.fromCharCode(8233)).join("\\u2029")}'`;
|
|
50
|
+
var escapeDoubleQuoted = (value) => value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
51
|
+
var kotlinString = (value) => `"${escapeDoubleQuoted(value).replace(/\$/g, "\\$")}"`;
|
|
52
|
+
var swiftString = (value) => `"${escapeDoubleQuoted(value)}"`;
|
|
53
|
+
var doubleQuoted = (value) => `"${escapeDoubleQuoted(value)}"`;
|
|
54
|
+
var SCRIPT_VALUE_TYPES = /* @__PURE__ */ new Set([
|
|
55
|
+
"range",
|
|
56
|
+
"color",
|
|
57
|
+
"date",
|
|
58
|
+
"time",
|
|
59
|
+
"datetime-local",
|
|
60
|
+
"month",
|
|
61
|
+
"week"
|
|
62
|
+
]);
|
|
63
|
+
var isScriptValueInput = (t) => !!t.inputType && SCRIPT_VALUE_TYPES.has(t.inputType);
|
|
64
|
+
var MASKED_VALUE_TODO = "// TODO: this value was masked in the recording \u2014 replace with test data";
|
|
65
|
+
var MASKED_PLACEHOLDER = "TODO_MASKED_VALUE";
|
|
66
|
+
|
|
67
|
+
// src/mobile/shared.ts
|
|
68
|
+
var import_types2 = require("@rrweb/types");
|
|
69
|
+
|
|
70
|
+
// src/mirror.ts
|
|
71
|
+
var import_types = require("@rrweb/types");
|
|
72
|
+
var NodeKind = {
|
|
73
|
+
Document: 0,
|
|
74
|
+
DocumentType: 1,
|
|
75
|
+
Element: 2,
|
|
76
|
+
Text: 3,
|
|
77
|
+
CDATA: 4,
|
|
78
|
+
Comment: 5
|
|
79
|
+
};
|
|
80
|
+
var DomMirror = class {
|
|
81
|
+
nodes = /* @__PURE__ */ new Map();
|
|
82
|
+
get(id) {
|
|
83
|
+
return this.nodes.get(id);
|
|
84
|
+
}
|
|
85
|
+
parent(node) {
|
|
86
|
+
return node.parentId === void 0 ? void 0 : this.nodes.get(node.parentId);
|
|
87
|
+
}
|
|
88
|
+
children(node) {
|
|
89
|
+
return node.children.map((id) => this.nodes.get(id)).filter((n) => n !== void 0);
|
|
90
|
+
}
|
|
91
|
+
elements() {
|
|
92
|
+
return this.nodes.values();
|
|
93
|
+
}
|
|
94
|
+
/** Apply a single event. Only FullSnapshot and Mutation change the DOM. */
|
|
95
|
+
apply(event) {
|
|
96
|
+
if (event.type === import_types.EventType.FullSnapshot) {
|
|
97
|
+
this.nodes.clear();
|
|
98
|
+
this.register(event.data.node, void 0);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (event.type === import_types.EventType.IncrementalSnapshot && event.data.source === import_types.IncrementalSource.Mutation) {
|
|
102
|
+
this.mutate(event.data);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
register(raw, parentId) {
|
|
106
|
+
const node = {
|
|
107
|
+
id: raw.id,
|
|
108
|
+
type: raw.type,
|
|
109
|
+
tagName: raw.tagName?.toLowerCase(),
|
|
110
|
+
attributes: { ...raw.attributes ?? {} },
|
|
111
|
+
textContent: raw.textContent,
|
|
112
|
+
isSVG: raw.isSVG,
|
|
113
|
+
parentId,
|
|
114
|
+
children: (raw.childNodes ?? []).map((c) => c.id)
|
|
115
|
+
};
|
|
116
|
+
this.nodes.set(node.id, node);
|
|
117
|
+
(raw.childNodes ?? []).forEach((c) => this.register(c, raw.id));
|
|
118
|
+
}
|
|
119
|
+
removeSubtree(id) {
|
|
120
|
+
const node = this.nodes.get(id);
|
|
121
|
+
if (!node) return;
|
|
122
|
+
node.children.forEach((c) => this.removeSubtree(c));
|
|
123
|
+
this.nodes.delete(id);
|
|
124
|
+
}
|
|
125
|
+
detach(node) {
|
|
126
|
+
const parent = this.parent(node);
|
|
127
|
+
if (parent) parent.children = parent.children.filter((c) => c !== node.id);
|
|
128
|
+
}
|
|
129
|
+
// Same order the rrweb replayer uses: removes, adds, texts, attributes.
|
|
130
|
+
mutate(m) {
|
|
131
|
+
m.removes?.forEach(({ id }) => {
|
|
132
|
+
const node = this.nodes.get(id);
|
|
133
|
+
if (!node) return;
|
|
134
|
+
this.detach(node);
|
|
135
|
+
this.removeSubtree(id);
|
|
136
|
+
});
|
|
137
|
+
m.adds?.forEach((add) => {
|
|
138
|
+
const existing = this.nodes.get(add.node.id);
|
|
139
|
+
if (existing) this.detach(existing);
|
|
140
|
+
this.register(add.node, add.parentId);
|
|
141
|
+
});
|
|
142
|
+
m.adds?.forEach((add) => {
|
|
143
|
+
const parent = this.nodes.get(add.parentId);
|
|
144
|
+
if (!parent || parent.children.includes(add.node.id)) return;
|
|
145
|
+
const at = add.nextId === null || add.nextId === void 0 ? -1 : parent.children.indexOf(add.nextId);
|
|
146
|
+
if (at >= 0) parent.children.splice(at, 0, add.node.id);
|
|
147
|
+
else parent.children.push(add.node.id);
|
|
148
|
+
});
|
|
149
|
+
m.texts?.forEach(({ id, value }) => {
|
|
150
|
+
const node = this.nodes.get(id);
|
|
151
|
+
if (node) node.textContent = value ?? "";
|
|
152
|
+
});
|
|
153
|
+
m.attributes?.forEach(({ id, attributes }) => {
|
|
154
|
+
const node = this.nodes.get(id);
|
|
155
|
+
if (!node) return;
|
|
156
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
157
|
+
if (value === null) delete node.attributes[key];
|
|
158
|
+
else if (typeof value !== "object") node.attributes[key] = value;
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var normalizeEvents = (events) => {
|
|
164
|
+
const out = [];
|
|
165
|
+
events.forEach((raw) => {
|
|
166
|
+
let e = raw;
|
|
167
|
+
if (typeof e === "string") {
|
|
168
|
+
try {
|
|
169
|
+
e = JSON.parse(e);
|
|
170
|
+
} catch {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!e || typeof e !== "object") return;
|
|
175
|
+
let data = e.data;
|
|
176
|
+
if (typeof data === "string") {
|
|
177
|
+
try {
|
|
178
|
+
data = JSON.parse(data);
|
|
179
|
+
} catch {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const type = Number(e.type);
|
|
184
|
+
const timestamp = Number(e.timestamp);
|
|
185
|
+
if (!Number.isFinite(type) || data === void 0) return;
|
|
186
|
+
out.push({ ...e, type, timestamp, data });
|
|
187
|
+
});
|
|
188
|
+
return out.sort((a, b) => (a.timestamp || 0) - (b.timestamp || 0));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/mobile/shared.ts
|
|
192
|
+
var resourceIdLeaf = (value) => {
|
|
193
|
+
const slash = value.lastIndexOf("/");
|
|
194
|
+
return slash >= 0 ? value.slice(slash + 1) : value;
|
|
195
|
+
};
|
|
196
|
+
var mobileLocator = (node) => {
|
|
197
|
+
if (!node) return void 0;
|
|
198
|
+
const a = node.attributes ?? {};
|
|
199
|
+
const id = a["resource-id"] ?? a["resourceId"] ?? a["testID"] ?? a["data-testid"] ?? a.id;
|
|
200
|
+
if (id) return { strategy: "id", value: String(id) };
|
|
201
|
+
const accessibility = a["content-desc"] ?? a["contentDescription"] ?? a["accessibilityIdentifier"] ?? a["accessibilityLabel"] ?? a["aria-label"] ?? a["name"];
|
|
202
|
+
if (accessibility)
|
|
203
|
+
return { strategy: "accessibility", value: String(accessibility) };
|
|
204
|
+
const text = a["text"] ?? (node.childNodes ?? []).map((n) => n?.textContent).filter(Boolean).join(" ").trim();
|
|
205
|
+
if (text) return { strategy: "text", value: String(text) };
|
|
206
|
+
return void 0;
|
|
207
|
+
};
|
|
208
|
+
var swipeDirection = (d) => {
|
|
209
|
+
const x = d.x ?? 0;
|
|
210
|
+
const y = d.y ?? 0;
|
|
211
|
+
if (Math.abs(y) >= Math.abs(x)) return y >= 0 ? "up" : "down";
|
|
212
|
+
return x >= 0 ? "left" : "right";
|
|
213
|
+
};
|
|
214
|
+
var extractMobileActions = (events) => {
|
|
215
|
+
const actions = [];
|
|
216
|
+
const mirror = new DomMirror();
|
|
217
|
+
const nodeAt = (id) => {
|
|
218
|
+
const node = mirror.get(id);
|
|
219
|
+
if (!node) return void 0;
|
|
220
|
+
return {
|
|
221
|
+
id: node.id,
|
|
222
|
+
tagName: node.tagName,
|
|
223
|
+
attributes: node.attributes,
|
|
224
|
+
childNodes: mirror.children(node).map((c) => ({ id: c.id, textContent: c.textContent }))
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
normalizeEvents(events).forEach((e) => {
|
|
228
|
+
mirror.apply(e);
|
|
229
|
+
if (e.type === import_types2.EventType.Meta) {
|
|
230
|
+
if (e.data?.href)
|
|
231
|
+
actions.push({ kind: "launch", url: e.data.href });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (e.type !== import_types2.EventType.IncrementalSnapshot) return;
|
|
235
|
+
const data = e.data;
|
|
236
|
+
switch (data.source) {
|
|
237
|
+
case import_types2.IncrementalSource.MouseInteraction: {
|
|
238
|
+
const d = data;
|
|
239
|
+
if (d.type === import_types2.MouseInteractions.Click || d.type === import_types2.MouseInteractions.TouchEnd) {
|
|
240
|
+
actions.push({
|
|
241
|
+
kind: "tap",
|
|
242
|
+
locator: mobileLocator(nodeAt(d.id))
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
case import_types2.IncrementalSource.Input: {
|
|
248
|
+
const d = data;
|
|
249
|
+
if (typeof d.text === "string") {
|
|
250
|
+
actions.push({
|
|
251
|
+
kind: "input",
|
|
252
|
+
locator: mobileLocator(nodeAt(d.id)),
|
|
253
|
+
text: d.text
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case import_types2.IncrementalSource.Scroll:
|
|
259
|
+
case import_types2.IncrementalSource.TouchMove: {
|
|
260
|
+
actions.push({
|
|
261
|
+
kind: "swipe",
|
|
262
|
+
direction: swipeDirection(data)
|
|
50
263
|
});
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
default:
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return actions;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/appium/index.ts
|
|
274
|
+
var selector = (loc) => {
|
|
275
|
+
if (!loc) return `$('~TODO_add_accessibility_id')`;
|
|
276
|
+
switch (loc.strategy) {
|
|
277
|
+
case "id":
|
|
278
|
+
return `$(${q(`android=new UiSelector().resourceId(${doubleQuoted(loc.value)})`)})`;
|
|
279
|
+
case "accessibility":
|
|
280
|
+
return `$(${q(`~${loc.value}`)})`;
|
|
281
|
+
case "text":
|
|
282
|
+
return `$(${q(`android=new UiSelector().text(${doubleQuoted(loc.value)})`)})`;
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
var generateAppiumTests = (events) => {
|
|
286
|
+
const actions = extractMobileActions(events);
|
|
287
|
+
let code = "";
|
|
288
|
+
code += `// Appium + WebdriverIO \u2014 generated from a session recording
|
|
289
|
+
`;
|
|
290
|
+
code += `describe('replayed session', () => {
|
|
291
|
+
`;
|
|
292
|
+
code += `${indent(2)}it('replays the recorded user flow', async () => {
|
|
293
|
+
`;
|
|
294
|
+
actions.forEach((a) => {
|
|
295
|
+
switch (a.kind) {
|
|
296
|
+
case "launch":
|
|
297
|
+
code += `${indent(4)}await driver.launchApp();
|
|
298
|
+
`;
|
|
299
|
+
break;
|
|
300
|
+
case "tap":
|
|
301
|
+
code += `${indent(4)}await ${selector(a.locator)}.click();
|
|
302
|
+
`;
|
|
303
|
+
break;
|
|
304
|
+
case "input":
|
|
305
|
+
code += `${indent(4)}await ${selector(a.locator)}.setValue(${q(a.text)});
|
|
306
|
+
`;
|
|
307
|
+
break;
|
|
308
|
+
case "swipe":
|
|
309
|
+
code += `${indent(4)}await driver.execute('mobile: swipeGesture', { direction: '${a.direction}', percent: 0.75 });
|
|
310
|
+
`;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
code += `${indent(2)}});
|
|
315
|
+
`;
|
|
316
|
+
code += `});
|
|
317
|
+
`;
|
|
318
|
+
return code;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
// src/web/actions.ts
|
|
322
|
+
var import_types3 = require("@rrweb/types");
|
|
323
|
+
|
|
324
|
+
// src/selector.ts
|
|
325
|
+
var TEST_ATTRS = [
|
|
326
|
+
"data-testid",
|
|
327
|
+
"data-test-id",
|
|
328
|
+
"data-test",
|
|
329
|
+
"data-cy",
|
|
330
|
+
"data-qa"
|
|
331
|
+
];
|
|
332
|
+
var LABEL_ATTRS = ["name", "placeholder", "aria-label", "title", "alt"];
|
|
333
|
+
var INTERACTIVE_TAGS = /* @__PURE__ */ new Set([
|
|
334
|
+
"a",
|
|
335
|
+
"button",
|
|
336
|
+
"input",
|
|
337
|
+
"select",
|
|
338
|
+
"textarea",
|
|
339
|
+
"label",
|
|
340
|
+
"summary",
|
|
341
|
+
"option"
|
|
342
|
+
]);
|
|
343
|
+
var INTERACTIVE_ROLES = /* @__PURE__ */ new Set([
|
|
344
|
+
"button",
|
|
345
|
+
"link",
|
|
346
|
+
"checkbox",
|
|
347
|
+
"radio",
|
|
348
|
+
"switch",
|
|
349
|
+
"tab",
|
|
350
|
+
"menuitem",
|
|
351
|
+
"menuitemcheckbox",
|
|
352
|
+
"menuitemradio",
|
|
353
|
+
"option",
|
|
354
|
+
"combobox",
|
|
355
|
+
"treeitem"
|
|
356
|
+
]);
|
|
357
|
+
var SKIPPED_TEXT_TAGS = /* @__PURE__ */ new Set(["script", "style", "noscript", "template"]);
|
|
358
|
+
var MAX_TEXT = 60;
|
|
359
|
+
var MAX_CLIMB = 6;
|
|
360
|
+
var str = (v) => typeof v === "string" || typeof v === "number" ? String(v) : void 0;
|
|
361
|
+
var isGeneratedId = (id) => /^:r[0-9a-z]*:?$|^«r|^rc[-_]|^mui-\d|^ember\d|^headlessui-|^radix-|[0-9a-f]{8}-[0-9a-f]{4}|\d{5,}/i.test(
|
|
362
|
+
id
|
|
363
|
+
);
|
|
364
|
+
var isUnstableClass = (c) => /^css-[0-9a-z]+$|^sc-|^jsx-\d|^_[0-9a-z]{5,}$|^[a-z]+_[0-9a-z]{5,}$/i.test(
|
|
365
|
+
c
|
|
366
|
+
) || /(^|[-_])(active|selected|focus|focused|hover|hovered|open|opened|disabled|checked|visible|hidden|has-value|loading|expanded|collapsed)$/i.test(
|
|
367
|
+
c
|
|
368
|
+
) || /^(is|has)-/.test(c) || /--after-open$|--before-close$/.test(c);
|
|
369
|
+
var stableClasses = (node) => (str(node.attributes.class) ?? "").split(/\s+/).filter((c) => c && !isUnstableClass(c)).slice(0, 3);
|
|
370
|
+
var cssString = (v) => v.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
371
|
+
var isIdent = (v) => /^-?[A-Za-z_][\w-]*$/.test(v);
|
|
372
|
+
var renderStep = (s) => {
|
|
373
|
+
let out = s.tag;
|
|
374
|
+
s.attrs.forEach(([k, v]) => {
|
|
375
|
+
out += k === "id" && isIdent(v) ? `#${v}` : `[${k}="${cssString(v)}"]`;
|
|
376
|
+
});
|
|
377
|
+
s.classes.forEach((c) => {
|
|
378
|
+
out += isIdent(c) ? `.${c}` : `[class~="${cssString(c)}"]`;
|
|
379
|
+
});
|
|
380
|
+
if (s.nth !== void 0) out += `:nth-of-type(${s.nth})`;
|
|
381
|
+
return out;
|
|
382
|
+
};
|
|
383
|
+
var renderSelector = (steps) => steps.map((s, i) => (i > 0 && s.child ? "> " : "") + renderStep(s)).join(" ");
|
|
384
|
+
var rawText = (mirror, node) => {
|
|
385
|
+
if (node.type === NodeKind.Text) return node.textContent ?? "";
|
|
386
|
+
if (node.tagName && SKIPPED_TEXT_TAGS.has(node.tagName)) return "";
|
|
387
|
+
return mirror.children(node).map((c) => rawText(mirror, c)).join("");
|
|
388
|
+
};
|
|
389
|
+
var elementText = (mirror, node) => rawText(mirror, node).replace(/\s+/g, " ").trim();
|
|
390
|
+
var nthOfType = (mirror, node) => {
|
|
391
|
+
const parent = mirror.parent(node);
|
|
392
|
+
if (!parent) return 1;
|
|
393
|
+
const same = mirror.children(parent).filter((c) => c.type === NodeKind.Element && c.tagName === node.tagName);
|
|
394
|
+
return same.findIndex((c) => c.id === node.id) + 1;
|
|
395
|
+
};
|
|
396
|
+
var matchesStep = (mirror, node, s) => {
|
|
397
|
+
if (node.type !== NodeKind.Element || node.tagName !== s.tag) return false;
|
|
398
|
+
for (const [k, v] of s.attrs) if (str(node.attributes[k]) !== v) return false;
|
|
399
|
+
if (s.classes.length) {
|
|
400
|
+
const own = new Set((str(node.attributes.class) ?? "").split(/\s+/));
|
|
401
|
+
if (!s.classes.every((c) => own.has(c))) return false;
|
|
402
|
+
}
|
|
403
|
+
if (s.nth !== void 0 && nthOfType(mirror, node) !== s.nth) return false;
|
|
404
|
+
return true;
|
|
405
|
+
};
|
|
406
|
+
var matchesChain = (mirror, node, steps, i) => {
|
|
407
|
+
const step = steps[i];
|
|
408
|
+
if (!step || !matchesStep(mirror, node, step)) return false;
|
|
409
|
+
if (i === 0) return true;
|
|
410
|
+
let anc = mirror.parent(node);
|
|
411
|
+
if (step.child) return !!anc && matchesChain(mirror, anc, steps, i - 1);
|
|
412
|
+
while (anc) {
|
|
413
|
+
if (matchesChain(mirror, anc, steps, i - 1)) return true;
|
|
414
|
+
anc = mirror.parent(anc);
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
};
|
|
418
|
+
var countMatches = (mirror, steps, text) => {
|
|
419
|
+
let n = 0;
|
|
420
|
+
for (const node of mirror.elements()) {
|
|
421
|
+
if (!matchesChain(mirror, node, steps, steps.length - 1)) continue;
|
|
422
|
+
if (text !== void 0 && !elementText(mirror, node).includes(text))
|
|
423
|
+
continue;
|
|
424
|
+
if (++n > 1) return n;
|
|
425
|
+
}
|
|
426
|
+
return n;
|
|
427
|
+
};
|
|
428
|
+
var attributeSteps = (node) => {
|
|
429
|
+
const tag = node.tagName;
|
|
430
|
+
const a = node.attributes;
|
|
431
|
+
const steps = [];
|
|
432
|
+
const add = (k, v) => {
|
|
433
|
+
if (v && v.length <= 120) steps.push({ tag, attrs: [[k, v]], classes: [] });
|
|
434
|
+
};
|
|
435
|
+
TEST_ATTRS.forEach((k) => add(k, str(a[k])));
|
|
436
|
+
const id = str(a.id);
|
|
437
|
+
if (id && !isGeneratedId(id)) add("id", id);
|
|
438
|
+
LABEL_ATTRS.forEach((k) => add(k, str(a[k])));
|
|
439
|
+
if (tag === "a") {
|
|
440
|
+
const href = str(a.href);
|
|
441
|
+
if (href && !href.startsWith("javascript:")) add("href", href);
|
|
442
|
+
}
|
|
443
|
+
if (tag === "label") add("for", str(a.for));
|
|
444
|
+
const role = str(a.role);
|
|
445
|
+
const label = str(a["aria-label"]);
|
|
446
|
+
if (role && label)
|
|
447
|
+
steps.push({
|
|
448
|
+
tag,
|
|
449
|
+
attrs: [
|
|
450
|
+
["role", role],
|
|
451
|
+
["aria-label", label]
|
|
452
|
+
],
|
|
453
|
+
classes: []
|
|
454
|
+
});
|
|
455
|
+
const type = str(a.type);
|
|
456
|
+
if (tag === "input" && type)
|
|
457
|
+
steps.slice().forEach(
|
|
458
|
+
(s) => steps.push({ ...s, attrs: [...s.attrs, ["type", type]] })
|
|
459
|
+
);
|
|
460
|
+
return steps;
|
|
461
|
+
};
|
|
462
|
+
var structuralStep = (node) => {
|
|
463
|
+
const classes = stableClasses(node);
|
|
464
|
+
const role = str(node.attributes.role);
|
|
465
|
+
const type = str(node.attributes.type);
|
|
466
|
+
const attrs = [];
|
|
467
|
+
if (role) attrs.push(["role", role]);
|
|
468
|
+
if (node.tagName === "input" && type) attrs.push(["type", type]);
|
|
469
|
+
return { tag: node.tagName, attrs, classes };
|
|
470
|
+
};
|
|
471
|
+
var bestStep = (node) => attributeSteps(node)[0] ?? structuralStep(node);
|
|
472
|
+
var isElement = (n) => !!n && n.type === NodeKind.Element && !!n.tagName;
|
|
473
|
+
var isSvgPart = (n) => !!n.isSVG || n.tagName === "svg";
|
|
474
|
+
var isInteractive = (n) => INTERACTIVE_TAGS.has(n.tagName) || INTERACTIVE_ROLES.has(str(n.attributes.role) ?? "") || TEST_ATTRS.some((k) => n.attributes[k] !== void 0);
|
|
475
|
+
var clickableAncestor = (mirror, node) => {
|
|
476
|
+
let cur = node;
|
|
477
|
+
while (cur && !isElement(cur)) cur = mirror.parent(cur);
|
|
478
|
+
while (cur && isSvgPart(cur) && isElement(mirror.parent(cur)))
|
|
479
|
+
cur = mirror.parent(cur);
|
|
480
|
+
if (!cur) return void 0;
|
|
481
|
+
let probe = cur;
|
|
482
|
+
for (let i = 0; probe && isElement(probe) && i <= MAX_CLIMB; i++) {
|
|
483
|
+
if (isInteractive(probe)) return probe;
|
|
484
|
+
if (probe.tagName === "body") break;
|
|
485
|
+
probe = mirror.parent(probe);
|
|
486
|
+
}
|
|
487
|
+
return cur;
|
|
488
|
+
};
|
|
489
|
+
var buildTarget = (mirror, node) => {
|
|
490
|
+
if (!isElement(node)) return void 0;
|
|
491
|
+
const base = {
|
|
492
|
+
tagName: node.tagName,
|
|
493
|
+
inputType: str(node.attributes.type)?.toLowerCase()
|
|
494
|
+
};
|
|
495
|
+
for (const s of attributeSteps(node))
|
|
496
|
+
if (countMatches(mirror, [s]) === 1)
|
|
497
|
+
return { ...base, css: renderSelector([s]) };
|
|
498
|
+
const own = bestStep(node);
|
|
499
|
+
if (countMatches(mirror, [own]) === 1)
|
|
500
|
+
return { ...base, css: renderSelector([own]) };
|
|
501
|
+
const text = elementText(mirror, node);
|
|
502
|
+
let withText;
|
|
503
|
+
if (text && text.length <= MAX_TEXT) {
|
|
504
|
+
const parent = mirror.parent(node);
|
|
505
|
+
const candidates = [[own]];
|
|
506
|
+
if (isElement(parent) && parent.tagName !== "body")
|
|
507
|
+
candidates.push([bestStep(parent), { ...own, child: true }]);
|
|
508
|
+
const unique = candidates.find((c) => countMatches(mirror, c, text) === 1);
|
|
509
|
+
if (unique) withText = { css: renderSelector(unique), text };
|
|
510
|
+
}
|
|
511
|
+
let anc = mirror.parent(node);
|
|
512
|
+
for (let i = 0; isElement(anc) && i < MAX_CLIMB; i++) {
|
|
513
|
+
if (anc.tagName === "body" || anc.tagName === "html") break;
|
|
514
|
+
for (const s of attributeSteps(anc)) {
|
|
515
|
+
if (countMatches(mirror, [s]) !== 1) continue;
|
|
516
|
+
const steps = [s, own];
|
|
517
|
+
if (countMatches(mirror, steps) === 1)
|
|
518
|
+
return { ...base, css: renderSelector(steps), withText };
|
|
519
|
+
}
|
|
520
|
+
anc = mirror.parent(anc);
|
|
521
|
+
}
|
|
522
|
+
const path = [];
|
|
523
|
+
let cur = node;
|
|
524
|
+
while (isElement(cur) && cur.tagName !== "html") {
|
|
525
|
+
const step = {
|
|
526
|
+
...path.length === 0 ? own : bestStep(cur),
|
|
527
|
+
child: true
|
|
528
|
+
};
|
|
529
|
+
path.unshift(step);
|
|
530
|
+
if (countMatches(mirror, path) === 1) break;
|
|
531
|
+
step.nth = nthOfType(mirror, cur);
|
|
532
|
+
if (countMatches(mirror, path) === 1) break;
|
|
533
|
+
cur = mirror.parent(cur);
|
|
534
|
+
}
|
|
535
|
+
if (path[0]) path[0].child = false;
|
|
536
|
+
else path.push(own);
|
|
537
|
+
return { ...base, css: renderSelector(path), withText };
|
|
538
|
+
};
|
|
539
|
+
var isDocumentScroller = (node) => !node || node.type === NodeKind.Document || node.tagName === "html" || node.tagName === "body";
|
|
540
|
+
|
|
541
|
+
// src/web/actions.ts
|
|
542
|
+
var isMasked = (v) => v.length > 0 && /^\*+$/.test(v);
|
|
543
|
+
var num = (v) => typeof v === "number" && Number.isFinite(v);
|
|
544
|
+
var extractWebActions = (events) => {
|
|
545
|
+
const mirror = new DomMirror();
|
|
546
|
+
const actions = [];
|
|
547
|
+
const keys = [];
|
|
548
|
+
let generation = 0;
|
|
549
|
+
let href;
|
|
550
|
+
let viewport;
|
|
551
|
+
let touched = /* @__PURE__ */ new Set();
|
|
552
|
+
let touchedHtmlIds = /* @__PURE__ */ new Set();
|
|
553
|
+
const keyOf = (node) => `${generation}:${node.id}`;
|
|
554
|
+
const lastMeaningful = () => {
|
|
555
|
+
let i = actions.length - 1;
|
|
556
|
+
while (i >= 0 && actions[i].kind === "mousemove") i--;
|
|
557
|
+
return i;
|
|
558
|
+
};
|
|
559
|
+
const dropIfLast = (key) => {
|
|
560
|
+
const i = lastMeaningful();
|
|
561
|
+
if (i < 0 || keys[i] !== key) return false;
|
|
562
|
+
actions.splice(i, 1);
|
|
563
|
+
keys.splice(i, 1);
|
|
564
|
+
return true;
|
|
565
|
+
};
|
|
566
|
+
const push = (action, key, collapse = false) => {
|
|
567
|
+
if (collapse && key !== void 0) dropIfLast(key);
|
|
568
|
+
actions.push(action);
|
|
569
|
+
keys.push(key);
|
|
570
|
+
};
|
|
571
|
+
const markTouched = (node) => {
|
|
572
|
+
if (!node) return;
|
|
573
|
+
touched.add(node.id);
|
|
574
|
+
const forId = node.tagName === "label" ? node.attributes.for : void 0;
|
|
575
|
+
if (typeof forId === "string") touchedHtmlIds.add(forId);
|
|
576
|
+
};
|
|
577
|
+
const isUserInput = (d, node) => {
|
|
578
|
+
if (d.userTriggered !== void 0) return d.userTriggered;
|
|
579
|
+
if (touched.has(node.id)) return true;
|
|
580
|
+
const htmlId = node.attributes.id;
|
|
581
|
+
if (typeof htmlId === "string" && touchedHtmlIds.has(htmlId)) return true;
|
|
582
|
+
let anc = mirror.parent(node);
|
|
583
|
+
for (let i = 0; anc && i < 4; i++, anc = mirror.parent(anc))
|
|
584
|
+
if (anc.tagName === "label" && touched.has(anc.id)) return true;
|
|
585
|
+
return false;
|
|
586
|
+
};
|
|
587
|
+
const setViewport = (width, height) => {
|
|
588
|
+
if (!num(width) || !num(height) || width <= 0 || height <= 0) return;
|
|
589
|
+
const v = `${width}x${height}`;
|
|
590
|
+
if (v === viewport) return;
|
|
591
|
+
viewport = v;
|
|
592
|
+
push({ kind: "viewport", width, height });
|
|
593
|
+
};
|
|
594
|
+
normalizeEvents(events).forEach((e) => {
|
|
595
|
+
switch (e.type) {
|
|
596
|
+
case import_types3.EventType.Meta: {
|
|
597
|
+
if (e.data.href && e.data.href !== href) {
|
|
598
|
+
href = e.data.href;
|
|
599
|
+
push({ kind: "navigate", href });
|
|
600
|
+
}
|
|
601
|
+
setViewport(e.data.width, e.data.height);
|
|
602
|
+
return;
|
|
51
603
|
}
|
|
604
|
+
case import_types3.EventType.FullSnapshot:
|
|
605
|
+
generation++;
|
|
606
|
+
touched = /* @__PURE__ */ new Set();
|
|
607
|
+
touchedHtmlIds = /* @__PURE__ */ new Set();
|
|
608
|
+
mirror.apply(e);
|
|
609
|
+
return;
|
|
610
|
+
case import_types3.EventType.IncrementalSnapshot:
|
|
611
|
+
break;
|
|
612
|
+
default:
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const data = e.data;
|
|
616
|
+
switch (data.source) {
|
|
617
|
+
case import_types3.IncrementalSource.Mutation:
|
|
618
|
+
mirror.apply(e);
|
|
619
|
+
break;
|
|
620
|
+
case import_types3.IncrementalSource.MouseMove:
|
|
621
|
+
case import_types3.IncrementalSource.TouchMove: {
|
|
622
|
+
const p = data.positions?.[0];
|
|
623
|
+
if (p && num(p.x) && num(p.y))
|
|
624
|
+
push({ kind: "mousemove", x: p.x, y: p.y });
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
case import_types3.IncrementalSource.MouseInteraction: {
|
|
628
|
+
const d = data;
|
|
629
|
+
const raw = mirror.get(d.id);
|
|
630
|
+
if (d.type === import_types3.MouseInteractions.Focus || d.type === import_types3.MouseInteractions.MouseDown || d.type === import_types3.MouseInteractions.TouchStart) {
|
|
631
|
+
markTouched(raw);
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
if (d.type !== import_types3.MouseInteractions.Click && d.type !== import_types3.MouseInteractions.DblClick)
|
|
635
|
+
break;
|
|
636
|
+
const node = clickableAncestor(mirror, raw);
|
|
637
|
+
markTouched(raw);
|
|
638
|
+
markTouched(node);
|
|
639
|
+
const target = buildTarget(mirror, node);
|
|
640
|
+
if (!node || !target) break;
|
|
641
|
+
const key = `click:${keyOf(node)}`;
|
|
642
|
+
if (d.type === import_types3.MouseInteractions.DblClick) {
|
|
643
|
+
if (dropIfLast(key)) dropIfLast(key);
|
|
644
|
+
push({ kind: "dblclick", target }, key);
|
|
645
|
+
} else {
|
|
646
|
+
push({ kind: "click", target }, key);
|
|
647
|
+
}
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
case import_types3.IncrementalSource.Input: {
|
|
651
|
+
const d = data;
|
|
652
|
+
const node = mirror.get(d.id);
|
|
653
|
+
if (!node || node.type !== NodeKind.Element) break;
|
|
654
|
+
if (!isUserInput(d, node)) break;
|
|
655
|
+
const target = buildTarget(mirror, node);
|
|
656
|
+
if (!target) break;
|
|
657
|
+
const key = `input:${keyOf(node)}`;
|
|
658
|
+
const text = typeof d.text === "string" ? d.text : "";
|
|
659
|
+
if (target.inputType === "checkbox" || target.inputType === "radio") {
|
|
660
|
+
if (target.inputType === "radio" && !d.isChecked) break;
|
|
661
|
+
push({ kind: "check", target, checked: !!d.isChecked }, key, true);
|
|
662
|
+
} else if (target.tagName === "select") {
|
|
663
|
+
push(
|
|
664
|
+
{ kind: "select", target, value: text, masked: isMasked(text) },
|
|
665
|
+
key,
|
|
666
|
+
true
|
|
667
|
+
);
|
|
668
|
+
} else {
|
|
669
|
+
push(
|
|
670
|
+
{ kind: "fill", target, value: text, masked: isMasked(text) },
|
|
671
|
+
key,
|
|
672
|
+
true
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case import_types3.IncrementalSource.Scroll: {
|
|
678
|
+
const d = data;
|
|
679
|
+
if (!num(d.x) || !num(d.y)) break;
|
|
680
|
+
const node = mirror.get(d.id);
|
|
681
|
+
if (isDocumentScroller(node)) {
|
|
682
|
+
push(
|
|
683
|
+
{ kind: "scroll", x: d.x, y: d.y },
|
|
684
|
+
`scroll:${generation}:doc`,
|
|
685
|
+
true
|
|
686
|
+
);
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
if (node?.tagName === "input") break;
|
|
690
|
+
const target = buildTarget(mirror, node);
|
|
691
|
+
if (target)
|
|
692
|
+
push(
|
|
693
|
+
{ kind: "scroll", target, x: d.x, y: d.y },
|
|
694
|
+
`scroll:${keyOf(node)}`,
|
|
695
|
+
true
|
|
696
|
+
);
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
case import_types3.IncrementalSource.ViewportResize: {
|
|
700
|
+
const d = data;
|
|
701
|
+
setViewport(d.width, d.height);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
case import_types3.IncrementalSource.MediaInteraction: {
|
|
705
|
+
const d = data;
|
|
706
|
+
const target = buildTarget(mirror, mirror.get(d.id));
|
|
707
|
+
if (!target) break;
|
|
708
|
+
if (d.type === import_types3.MediaInteractions.Play)
|
|
709
|
+
push({ kind: "media", target, action: "play" });
|
|
710
|
+
else if (d.type === import_types3.MediaInteractions.Pause)
|
|
711
|
+
push({ kind: "media", target, action: "pause" });
|
|
712
|
+
else if (d.type === import_types3.MediaInteractions.Seeked && num(d.currentTime))
|
|
713
|
+
push({ kind: "seek", target, currentTime: d.currentTime });
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
716
|
+
default:
|
|
717
|
+
break;
|
|
52
718
|
}
|
|
53
|
-
processNode(rootNode);
|
|
54
719
|
});
|
|
55
|
-
return
|
|
720
|
+
return actions;
|
|
56
721
|
};
|
|
57
722
|
|
|
58
723
|
// src/cypress/index.ts
|
|
724
|
+
var get = (t) => t.withText ? `cy.contains(${q(t.withText.css)}, ${q(t.withText.text)})` : `cy.get(${q(t.css)})`;
|
|
725
|
+
var typeText = (v) => v.replace(/\{/g, "{{}");
|
|
59
726
|
var generateCypressTests = (events) => {
|
|
727
|
+
const i = indent(4);
|
|
60
728
|
let code = "";
|
|
61
729
|
code += `describe('TODO: name the test block', () => {
|
|
62
730
|
`;
|
|
63
731
|
code += ` it('TODO: name the test case', () => {
|
|
64
732
|
`;
|
|
65
|
-
|
|
66
|
-
(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
events.forEach((event) => {
|
|
70
|
-
const e = event;
|
|
71
|
-
switch (e.type) {
|
|
72
|
-
case import_types.EventType.Meta:
|
|
73
|
-
if (e.data.href) {
|
|
74
|
-
code += `${indent(3)}cy.visit('${e.data.href}');
|
|
733
|
+
extractWebActions(events).forEach((a) => {
|
|
734
|
+
switch (a.kind) {
|
|
735
|
+
case "navigate":
|
|
736
|
+
code += `${i}cy.visit(${q(a.href)});
|
|
75
737
|
`;
|
|
76
|
-
|
|
738
|
+
code += `${i}cy.url().should('include', ${q(a.href)});
|
|
77
739
|
`;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
740
|
+
break;
|
|
741
|
+
case "viewport":
|
|
742
|
+
code += `${i}cy.viewport(${a.width}, ${a.height});
|
|
743
|
+
`;
|
|
744
|
+
break;
|
|
745
|
+
case "mousemove":
|
|
746
|
+
code += `${i}cy.get('body').trigger('mousemove', { clientX: ${a.x}, clientY: ${a.y} });
|
|
747
|
+
`;
|
|
748
|
+
break;
|
|
749
|
+
case "click":
|
|
750
|
+
code += `${i}${get(a.target)}.click();
|
|
81
751
|
`;
|
|
82
|
-
}
|
|
83
752
|
break;
|
|
84
|
-
case
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
(node) => node.childNodes?.map(
|
|
102
|
-
(n1) => n1?.["textContent"]
|
|
103
|
-
)
|
|
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;
|
|
105
|
-
if (id) {
|
|
106
|
-
if (clickNode?.tagName === "nav") {
|
|
107
|
-
code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();
|
|
108
|
-
`;
|
|
109
|
-
} else {
|
|
110
|
-
code += `${indent(3)}cy.get('${id}').click();
|
|
111
|
-
`;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
break;
|
|
116
|
-
case import_types.IncrementalSource.Scroll:
|
|
117
|
-
d = data;
|
|
118
|
-
if (d.x && d.y) {
|
|
119
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y});
|
|
120
|
-
`;
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
case import_types.IncrementalSource.ViewportResize:
|
|
124
|
-
d = data;
|
|
125
|
-
if (d.width && d.height) {
|
|
126
|
-
code += `${indent(3)}cy.viewport(${d.width}, ${d.height});
|
|
127
|
-
`;
|
|
128
|
-
}
|
|
129
|
-
break;
|
|
130
|
-
case import_types.IncrementalSource.Input:
|
|
131
|
-
d = data;
|
|
132
|
-
if (d.text) {
|
|
133
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').type('${d.text}');
|
|
134
|
-
`;
|
|
135
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').should('have.value', '${d.text}');
|
|
136
|
-
`;
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
case import_types.IncrementalSource.MediaInteraction:
|
|
140
|
-
d = data;
|
|
141
|
-
if (d.type) {
|
|
142
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').then((el) => el[0].${d.type}());
|
|
143
|
-
`;
|
|
144
|
-
}
|
|
145
|
-
break;
|
|
753
|
+
case "dblclick":
|
|
754
|
+
code += `${i}${get(a.target)}.dblclick();
|
|
755
|
+
`;
|
|
756
|
+
break;
|
|
757
|
+
case "fill": {
|
|
758
|
+
const value = a.masked ? MASKED_PLACEHOLDER : a.value;
|
|
759
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
760
|
+
`;
|
|
761
|
+
if (isScriptValueInput(a.target)) {
|
|
762
|
+
code += `${i}${get(a.target)}.invoke('val', ${q(value)}).trigger('input').trigger('change');
|
|
763
|
+
`;
|
|
764
|
+
} else if (value === "") {
|
|
765
|
+
code += `${i}${get(a.target)}.clear();
|
|
766
|
+
`;
|
|
767
|
+
} else {
|
|
768
|
+
code += `${i}${get(a.target)}.clear().type(${q(typeText(value))});
|
|
769
|
+
`;
|
|
146
770
|
}
|
|
771
|
+
if (!a.masked)
|
|
772
|
+
code += `${i}${get(a.target)}.should('have.value', ${q(value)});
|
|
773
|
+
`;
|
|
147
774
|
break;
|
|
148
|
-
|
|
775
|
+
}
|
|
776
|
+
case "check":
|
|
777
|
+
code += `${i}${get(a.target)}.${a.checked ? "check" : "uncheck"}({ force: true });
|
|
778
|
+
`;
|
|
779
|
+
break;
|
|
780
|
+
case "select":
|
|
781
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
782
|
+
`;
|
|
783
|
+
code += `${i}${get(a.target)}.select(${q(a.masked ? MASKED_PLACEHOLDER : a.value)});
|
|
784
|
+
`;
|
|
785
|
+
break;
|
|
786
|
+
case "scroll":
|
|
787
|
+
code += a.target ? `${i}${get(a.target)}.scrollTo(${a.x}, ${a.y});
|
|
788
|
+
` : `${i}cy.scrollTo(${a.x}, ${a.y});
|
|
789
|
+
`;
|
|
790
|
+
break;
|
|
791
|
+
case "media":
|
|
792
|
+
code += `${i}${get(a.target)}.then(($el) => $el[0].${a.action}());
|
|
793
|
+
`;
|
|
794
|
+
break;
|
|
795
|
+
case "seek":
|
|
796
|
+
code += `${i}${get(a.target)}.then(($el) => { $el[0].currentTime = ${a.currentTime}; });
|
|
797
|
+
`;
|
|
149
798
|
break;
|
|
150
799
|
}
|
|
151
800
|
});
|
|
@@ -156,237 +805,287 @@ var generateCypressTests = (events) => {
|
|
|
156
805
|
return code;
|
|
157
806
|
};
|
|
158
807
|
|
|
808
|
+
// src/detox/index.ts
|
|
809
|
+
var matcher = (loc) => {
|
|
810
|
+
if (!loc) return `by.id('TODO_add_testID')`;
|
|
811
|
+
switch (loc.strategy) {
|
|
812
|
+
case "id":
|
|
813
|
+
return `by.id(${q(loc.value)})`;
|
|
814
|
+
case "accessibility":
|
|
815
|
+
return `by.label(${q(loc.value)})`;
|
|
816
|
+
case "text":
|
|
817
|
+
return `by.text(${q(loc.value)})`;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
var generateDetoxTests = (events) => {
|
|
821
|
+
const actions = extractMobileActions(events);
|
|
822
|
+
let code = "";
|
|
823
|
+
code += `// Detox \u2014 generated from a session recording
|
|
824
|
+
`;
|
|
825
|
+
code += `describe('replayed session', () => {
|
|
826
|
+
`;
|
|
827
|
+
code += `${indent(2)}it('replays the recorded user flow', async () => {
|
|
828
|
+
`;
|
|
829
|
+
actions.forEach((a) => {
|
|
830
|
+
switch (a.kind) {
|
|
831
|
+
case "launch":
|
|
832
|
+
code += `${indent(4)}await device.launchApp({ newInstance: true });
|
|
833
|
+
`;
|
|
834
|
+
break;
|
|
835
|
+
case "tap":
|
|
836
|
+
code += `${indent(4)}await element(${matcher(a.locator)}).tap();
|
|
837
|
+
`;
|
|
838
|
+
break;
|
|
839
|
+
case "input":
|
|
840
|
+
code += `${indent(4)}await element(${matcher(a.locator)}).typeText(${q(a.text)});
|
|
841
|
+
`;
|
|
842
|
+
break;
|
|
843
|
+
case "swipe":
|
|
844
|
+
code += `${indent(4)}await element(by.id('scrollView')).swipe('${a.direction}');
|
|
845
|
+
`;
|
|
846
|
+
break;
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
code += `${indent(2)}});
|
|
850
|
+
`;
|
|
851
|
+
code += `});
|
|
852
|
+
`;
|
|
853
|
+
return code;
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/espresso/index.ts
|
|
857
|
+
var matcher2 = (loc) => {
|
|
858
|
+
if (!loc) return `withContentDescription("TODO_add_content_description")`;
|
|
859
|
+
switch (loc.strategy) {
|
|
860
|
+
case "id": {
|
|
861
|
+
const leaf = resourceIdLeaf(loc.value);
|
|
862
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(leaf) ? `withId(R.id.${leaf})` : `withResourceName(${kotlinString(leaf)})`;
|
|
863
|
+
}
|
|
864
|
+
case "accessibility":
|
|
865
|
+
return `withContentDescription(${kotlinString(loc.value)})`;
|
|
866
|
+
case "text":
|
|
867
|
+
return `withText(${kotlinString(loc.value)})`;
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
var swipeFn = (direction) => ({
|
|
871
|
+
up: "swipeUp",
|
|
872
|
+
down: "swipeDown",
|
|
873
|
+
left: "swipeLeft",
|
|
874
|
+
right: "swipeRight"
|
|
875
|
+
})[direction];
|
|
876
|
+
var generateEspressoTests = (events) => {
|
|
877
|
+
const actions = extractMobileActions(events);
|
|
878
|
+
let code = "";
|
|
879
|
+
code += `// Espresso (Kotlin) \u2014 generated from a session recording
|
|
880
|
+
`;
|
|
881
|
+
code += `@Test
|
|
882
|
+
`;
|
|
883
|
+
code += `fun replaySession() {
|
|
884
|
+
`;
|
|
885
|
+
actions.forEach((a) => {
|
|
886
|
+
switch (a.kind) {
|
|
887
|
+
case "launch":
|
|
888
|
+
code += `${indent(2)}// App launch is handled by ActivityScenarioRule
|
|
889
|
+
`;
|
|
890
|
+
break;
|
|
891
|
+
case "tap":
|
|
892
|
+
code += `${indent(2)}onView(${matcher2(a.locator)}).perform(click())
|
|
893
|
+
`;
|
|
894
|
+
break;
|
|
895
|
+
case "input":
|
|
896
|
+
code += `${indent(2)}onView(${matcher2(a.locator)}).perform(typeText(${kotlinString(a.text)}), closeSoftKeyboard())
|
|
897
|
+
`;
|
|
898
|
+
break;
|
|
899
|
+
case "swipe":
|
|
900
|
+
code += `${indent(2)}onView(isRoot()).perform(${swipeFn(a.direction)}())
|
|
901
|
+
`;
|
|
902
|
+
break;
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
code += `}
|
|
906
|
+
`;
|
|
907
|
+
return code;
|
|
908
|
+
};
|
|
909
|
+
|
|
159
910
|
// src/playwright/index.ts
|
|
160
|
-
var
|
|
911
|
+
var locator = (t) => t.withText ? `page.locator(${q(t.withText.css)}, { hasText: ${q(t.withText.text)} })` : `page.locator(${q(t.css)})`;
|
|
161
912
|
var generatePlaywrightTests = (events) => {
|
|
913
|
+
const i = indent(2);
|
|
162
914
|
let code = "";
|
|
163
915
|
code += `import { test, expect } from '@playwright/test';
|
|
164
916
|
|
|
165
917
|
`;
|
|
166
|
-
code += `test('TODO: name the test block', async ({ page
|
|
918
|
+
code += `test('TODO: name the test block', async ({ page }) => {
|
|
167
919
|
`;
|
|
168
|
-
|
|
169
|
-
(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
code += `${indent(2)}const newTab = await context.newPage();
|
|
920
|
+
extractWebActions(events).forEach((a) => {
|
|
921
|
+
switch (a.kind) {
|
|
922
|
+
case "navigate":
|
|
923
|
+
code += `${i}await page.goto(${q(a.href)});
|
|
173
924
|
`;
|
|
174
|
-
|
|
175
|
-
const e = event;
|
|
176
|
-
switch (e.type) {
|
|
177
|
-
case import_types2.EventType.Meta:
|
|
178
|
-
if (e.data.href) {
|
|
179
|
-
code += `${indent(2)}await page.goto('${e.data.href}');
|
|
925
|
+
code += `${i}await expect(page).toHaveURL(${q(a.href)});
|
|
180
926
|
`;
|
|
181
|
-
|
|
927
|
+
break;
|
|
928
|
+
case "viewport":
|
|
929
|
+
code += `${i}await page.setViewportSize({ width: ${a.width}, height: ${a.height} });
|
|
182
930
|
`;
|
|
183
|
-
}
|
|
184
|
-
if (e.data.width && e.data.height) {
|
|
185
|
-
code += `${indent(2)}await page.setViewportSize({ width: ${e.data.width}, height: ${e.data.height} });
|
|
931
|
+
code += `${i}await expect(page).toHaveViewportSize({ width: ${a.width}, height: ${a.height} });
|
|
186
932
|
`;
|
|
187
|
-
|
|
933
|
+
break;
|
|
934
|
+
case "mousemove":
|
|
935
|
+
code += `${i}await page.mouse.move(${a.x}, ${a.y});
|
|
188
936
|
`;
|
|
189
|
-
}
|
|
190
937
|
break;
|
|
191
|
-
case
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
)
|
|
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;
|
|
212
|
-
if (id && d.x && d.y) {
|
|
213
|
-
code += `${indent(2)}await page.locator(\`${id}\`).click();
|
|
214
|
-
`;
|
|
215
|
-
code += `${indent(2)}await expect(page.locator(\`${id}\`)).toBeVisible();
|
|
216
|
-
`;
|
|
217
|
-
}
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
case import_types2.IncrementalSource.Scroll:
|
|
222
|
-
d = data;
|
|
223
|
-
if (d.x && d.y) {
|
|
224
|
-
code += `${indent(2)}await page.mouse.wheel(() => { document.querySelector('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y}); });
|
|
225
|
-
`;
|
|
226
|
-
code += `${indent(2)}await expect(page.locator('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]')).toBeVisible();
|
|
227
|
-
`;
|
|
228
|
-
}
|
|
229
|
-
break;
|
|
230
|
-
case import_types2.IncrementalSource.ViewportResize:
|
|
231
|
-
d = data;
|
|
232
|
-
if (d.width && d.height) {
|
|
233
|
-
code += `${indent(2)}await page.setViewportSize({ width: ${d.width}, height: ${d.height} });
|
|
234
|
-
`;
|
|
235
|
-
code += `${indent(2)}await expect(page).toHaveViewportSize({ width: ${d.width}, height: ${d.height} });
|
|
236
|
-
`;
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
239
|
-
case import_types2.IncrementalSource.Input:
|
|
240
|
-
d = data;
|
|
241
|
-
if (d.text) {
|
|
242
|
-
code += `${indent(2)}await page.fill('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', '${d.text}');
|
|
243
|
-
`;
|
|
244
|
-
code += `${indent(2)}await expect(page.locator('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]')).toHaveValue('${d.text}');
|
|
245
|
-
`;
|
|
246
|
-
}
|
|
247
|
-
break;
|
|
248
|
-
case import_types2.IncrementalSource.MediaInteraction:
|
|
249
|
-
d = data;
|
|
250
|
-
if (d.type) {
|
|
251
|
-
code += `${indent(2)}await page.$eval('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', el => el.${d.type}());
|
|
252
|
-
`;
|
|
253
|
-
code += `${indent(2)}await expect(page.locator('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]')).toBeVisible();
|
|
254
|
-
`;
|
|
255
|
-
}
|
|
256
|
-
break;
|
|
938
|
+
case "click":
|
|
939
|
+
code += `${i}await ${locator(a.target)}.click();
|
|
940
|
+
`;
|
|
941
|
+
break;
|
|
942
|
+
case "dblclick":
|
|
943
|
+
code += `${i}await ${locator(a.target)}.dblclick();
|
|
944
|
+
`;
|
|
945
|
+
break;
|
|
946
|
+
case "fill":
|
|
947
|
+
if (a.masked) {
|
|
948
|
+
code += `${i}${MASKED_VALUE_TODO}
|
|
949
|
+
`;
|
|
950
|
+
code += `${i}await ${locator(a.target)}.fill(${q(MASKED_PLACEHOLDER)});
|
|
951
|
+
`;
|
|
952
|
+
} else {
|
|
953
|
+
code += `${i}await ${locator(a.target)}.fill(${q(a.value)});
|
|
954
|
+
`;
|
|
955
|
+
code += `${i}await expect(${locator(a.target)}).toHaveValue(${q(a.value)});
|
|
956
|
+
`;
|
|
257
957
|
}
|
|
258
958
|
break;
|
|
259
|
-
|
|
959
|
+
case "check":
|
|
960
|
+
code += `${i}await ${locator(a.target)}.setChecked(${a.checked}, { force: true });
|
|
961
|
+
`;
|
|
962
|
+
code += `${i}await expect(${locator(a.target)}).toBeChecked({ checked: ${a.checked} });
|
|
963
|
+
`;
|
|
964
|
+
break;
|
|
965
|
+
case "select":
|
|
966
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
967
|
+
`;
|
|
968
|
+
code += `${i}await ${locator(a.target)}.selectOption(${q(a.masked ? MASKED_PLACEHOLDER : a.value)});
|
|
969
|
+
`;
|
|
970
|
+
break;
|
|
971
|
+
case "scroll":
|
|
972
|
+
code += a.target ? `${i}await ${locator(a.target)}.evaluate((el) => el.scrollTo(${a.x}, ${a.y}));
|
|
973
|
+
` : `${i}await page.evaluate(() => window.scrollTo(${a.x}, ${a.y}));
|
|
974
|
+
`;
|
|
975
|
+
break;
|
|
976
|
+
case "media":
|
|
977
|
+
code += `${i}await ${locator(a.target)}.evaluate('(el) => el.${a.action}()');
|
|
978
|
+
`;
|
|
979
|
+
break;
|
|
980
|
+
case "seek":
|
|
981
|
+
code += `${i}await ${locator(a.target)}.evaluate('(el) => { el.currentTime = ${a.currentTime}; }');
|
|
982
|
+
`;
|
|
260
983
|
break;
|
|
261
984
|
}
|
|
262
985
|
});
|
|
263
|
-
code +=
|
|
986
|
+
code += `});
|
|
264
987
|
`;
|
|
265
988
|
return code;
|
|
266
989
|
};
|
|
267
990
|
|
|
268
991
|
// src/puppeteer/index.ts
|
|
269
|
-
var import_types3 = require("@rrweb/types");
|
|
270
992
|
var generatePuppeteerTests = (events) => {
|
|
993
|
+
const i = indent(4);
|
|
271
994
|
let code = "";
|
|
272
995
|
code += `const puppeteer = require('puppeteer');
|
|
273
996
|
|
|
274
997
|
`;
|
|
275
998
|
code += `describe('TODO: name the test block', () => {
|
|
276
999
|
`;
|
|
277
|
-
code += `${indent(
|
|
1000
|
+
code += `${indent(2)}let browser, page;
|
|
278
1001
|
|
|
279
1002
|
`;
|
|
280
|
-
code += `${indent(
|
|
1003
|
+
code += `${indent(2)}beforeAll(async () => {
|
|
281
1004
|
`;
|
|
282
|
-
code += `${
|
|
1005
|
+
code += `${i}browser = await puppeteer.launch();
|
|
283
1006
|
`;
|
|
284
|
-
code += `${
|
|
1007
|
+
code += `${i}page = await browser.newPage();
|
|
285
1008
|
`;
|
|
286
|
-
code += `${indent(
|
|
1009
|
+
code += `${indent(2)}});
|
|
287
1010
|
|
|
288
1011
|
`;
|
|
289
|
-
code += `${indent(
|
|
1012
|
+
code += `${indent(2)}afterAll(async () => {
|
|
290
1013
|
`;
|
|
291
|
-
code += `${
|
|
1014
|
+
code += `${i}await browser.close();
|
|
292
1015
|
`;
|
|
293
|
-
code += `${indent(
|
|
1016
|
+
code += `${indent(2)}});
|
|
294
1017
|
|
|
295
1018
|
`;
|
|
296
|
-
code += `${indent(
|
|
1019
|
+
code += `${indent(2)}test('TODO: name the test case', async () => {
|
|
297
1020
|
`;
|
|
298
|
-
|
|
299
|
-
(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
events.forEach((event) => {
|
|
303
|
-
const e = event;
|
|
304
|
-
switch (e.type) {
|
|
305
|
-
case import_types3.EventType.Meta:
|
|
306
|
-
if (e.data.href) {
|
|
307
|
-
code += `${indent(2)}await page.goto('${e.data.href}');
|
|
1021
|
+
extractWebActions(events).forEach((a) => {
|
|
1022
|
+
switch (a.kind) {
|
|
1023
|
+
case "navigate":
|
|
1024
|
+
code += `${i}await page.goto(${q(a.href)});
|
|
308
1025
|
`;
|
|
309
|
-
|
|
1026
|
+
code += `${i}expect(page.url()).toBe(${q(a.href)});
|
|
310
1027
|
`;
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
1028
|
+
break;
|
|
1029
|
+
case "viewport":
|
|
1030
|
+
code += `${i}await page.setViewport({ width: ${a.width}, height: ${a.height} });
|
|
314
1031
|
`;
|
|
315
|
-
}
|
|
316
1032
|
break;
|
|
317
|
-
case
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
case import_types3.IncrementalSource.Scroll:
|
|
345
|
-
d = data;
|
|
346
|
-
if (d.x && d.y) {
|
|
347
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
348
|
-
code += `${indent(2)}await page.evaluate(() => {
|
|
349
|
-
`;
|
|
350
|
-
code += `${indent(3)}document.querySelector('#${elementId}').scrollTo(${d.x}, ${d.y});
|
|
351
|
-
`;
|
|
352
|
-
code += `${indent(2)}});
|
|
353
|
-
`;
|
|
354
|
-
}
|
|
355
|
-
break;
|
|
356
|
-
case import_types3.IncrementalSource.ViewportResize:
|
|
357
|
-
d = data;
|
|
358
|
-
if (d.width && d.height) {
|
|
359
|
-
code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });
|
|
360
|
-
`;
|
|
361
|
-
}
|
|
362
|
-
break;
|
|
363
|
-
case import_types3.IncrementalSource.Input:
|
|
364
|
-
d = data;
|
|
365
|
-
if (d.text) {
|
|
366
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
367
|
-
code += `${indent(2)}await page.type('#${elementId}', '${d.text}');
|
|
368
|
-
`;
|
|
369
|
-
}
|
|
370
|
-
break;
|
|
371
|
-
case import_types3.IncrementalSource.MediaInteraction:
|
|
372
|
-
d = data;
|
|
373
|
-
if (d.type) {
|
|
374
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
375
|
-
code += `${indent(2)}await page.evaluate(() => {
|
|
376
|
-
`;
|
|
377
|
-
code += `${indent(3)}document.querySelector('#${elementId}').${d.type}();
|
|
378
|
-
`;
|
|
379
|
-
code += `${indent(2)}});
|
|
380
|
-
`;
|
|
381
|
-
}
|
|
382
|
-
break;
|
|
1033
|
+
case "mousemove":
|
|
1034
|
+
code += `${i}await page.mouse.move(${a.x}, ${a.y});
|
|
1035
|
+
`;
|
|
1036
|
+
break;
|
|
1037
|
+
case "click":
|
|
1038
|
+
code += `${i}await page.click(${q(a.target.css)});
|
|
1039
|
+
`;
|
|
1040
|
+
break;
|
|
1041
|
+
case "dblclick":
|
|
1042
|
+
code += `${i}await page.click(${q(a.target.css)}, { clickCount: 2 });
|
|
1043
|
+
`;
|
|
1044
|
+
break;
|
|
1045
|
+
case "fill": {
|
|
1046
|
+
const sel = q(a.target.css);
|
|
1047
|
+
const value = a.masked ? MASKED_PLACEHOLDER : a.value;
|
|
1048
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
1049
|
+
`;
|
|
1050
|
+
if (isScriptValueInput(a.target)) {
|
|
1051
|
+
code += `${i}await page.$eval(${sel}, (el, v) => { el.value = v; el.dispatchEvent(new Event('input', { bubbles: true })); el.dispatchEvent(new Event('change', { bubbles: true })); }, ${q(value)});
|
|
1052
|
+
`;
|
|
1053
|
+
} else {
|
|
1054
|
+
code += `${i}await page.click(${sel}, { clickCount: 3 });
|
|
1055
|
+
`;
|
|
1056
|
+
code += `${i}await page.keyboard.press('Backspace');
|
|
1057
|
+
`;
|
|
1058
|
+
if (value) code += `${i}await page.type(${sel}, ${q(value)});
|
|
1059
|
+
`;
|
|
383
1060
|
}
|
|
384
1061
|
break;
|
|
385
|
-
|
|
1062
|
+
}
|
|
1063
|
+
case "check":
|
|
1064
|
+
code += `${i}await page.$eval(${q(a.target.css)}, (el) => { if (el.checked !== ${a.checked}) el.click(); });
|
|
1065
|
+
`;
|
|
1066
|
+
break;
|
|
1067
|
+
case "select":
|
|
1068
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
1069
|
+
`;
|
|
1070
|
+
code += `${i}await page.select(${q(a.target.css)}, ${q(a.masked ? MASKED_PLACEHOLDER : a.value)});
|
|
1071
|
+
`;
|
|
1072
|
+
break;
|
|
1073
|
+
case "scroll":
|
|
1074
|
+
code += a.target ? `${i}await page.$eval(${q(a.target.css)}, (el) => el.scrollTo(${a.x}, ${a.y}));
|
|
1075
|
+
` : `${i}await page.evaluate(() => window.scrollTo(${a.x}, ${a.y}));
|
|
1076
|
+
`;
|
|
1077
|
+
break;
|
|
1078
|
+
case "media":
|
|
1079
|
+
code += `${i}await page.$eval(${q(a.target.css)}, (el) => el.${a.action}());
|
|
1080
|
+
`;
|
|
1081
|
+
break;
|
|
1082
|
+
case "seek":
|
|
1083
|
+
code += `${i}await page.$eval(${q(a.target.css)}, (el) => { el.currentTime = ${a.currentTime}; });
|
|
1084
|
+
`;
|
|
386
1085
|
break;
|
|
387
1086
|
}
|
|
388
1087
|
});
|
|
389
|
-
code += `${indent(
|
|
1088
|
+
code += `${indent(2)}});
|
|
390
1089
|
`;
|
|
391
1090
|
code += `});
|
|
392
1091
|
`;
|
|
@@ -394,127 +1093,168 @@ var generatePuppeteerTests = (events) => {
|
|
|
394
1093
|
};
|
|
395
1094
|
|
|
396
1095
|
// src/selenium/index.ts
|
|
397
|
-
var
|
|
1096
|
+
var find = (css) => `await driver.findElement(By.css(${q(css)}))`;
|
|
1097
|
+
var SET_VALUE_SCRIPT = q(
|
|
1098
|
+
"arguments[0].value = arguments[1]; arguments[0].dispatchEvent(new Event('input', { bubbles: true })); arguments[0].dispatchEvent(new Event('change', { bubbles: true }));"
|
|
1099
|
+
);
|
|
398
1100
|
var generateSeleniumTests = (events) => {
|
|
1101
|
+
const i = indent(4);
|
|
399
1102
|
let code = "";
|
|
400
1103
|
code += `const { Builder, By, until } = require('selenium-webdriver');
|
|
401
1104
|
|
|
402
1105
|
`;
|
|
403
1106
|
code += `describe('TODO: name the test block', () => {
|
|
404
1107
|
`;
|
|
405
|
-
code += `${indent(
|
|
1108
|
+
code += `${indent(2)}let driver;
|
|
406
1109
|
|
|
407
1110
|
`;
|
|
408
|
-
code += `${indent(
|
|
1111
|
+
code += `${indent(2)}beforeAll(async () => {
|
|
409
1112
|
`;
|
|
410
|
-
code += `${
|
|
1113
|
+
code += `${i}driver = await new Builder().forBrowser('chrome').build();
|
|
411
1114
|
`;
|
|
412
|
-
code += `${indent(
|
|
1115
|
+
code += `${indent(2)}});
|
|
413
1116
|
|
|
414
1117
|
`;
|
|
415
|
-
code += `${indent(
|
|
1118
|
+
code += `${indent(2)}afterAll(async () => {
|
|
416
1119
|
`;
|
|
417
|
-
code += `${
|
|
1120
|
+
code += `${i}await driver.quit();
|
|
418
1121
|
`;
|
|
419
|
-
code += `${indent(
|
|
1122
|
+
code += `${indent(2)}});
|
|
420
1123
|
|
|
421
1124
|
`;
|
|
422
|
-
code += `${indent(
|
|
1125
|
+
code += `${indent(2)}test('TODO: name the test case', async () => {
|
|
423
1126
|
`;
|
|
424
|
-
|
|
425
|
-
(
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
events.forEach((event) => {
|
|
429
|
-
const e = event;
|
|
430
|
-
switch (e.type) {
|
|
431
|
-
case import_types4.EventType.Meta:
|
|
432
|
-
if (e.data.href) {
|
|
433
|
-
code += `${indent(2)}await driver.get('${e.data.href}');
|
|
1127
|
+
extractWebActions(events).forEach((a) => {
|
|
1128
|
+
switch (a.kind) {
|
|
1129
|
+
case "navigate":
|
|
1130
|
+
code += `${i}await driver.get(${q(a.href)});
|
|
434
1131
|
`;
|
|
435
|
-
|
|
1132
|
+
code += `${i}await driver.wait(until.urlIs(${q(a.href)}), 5000);
|
|
436
1133
|
`;
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
1134
|
+
break;
|
|
1135
|
+
case "viewport":
|
|
1136
|
+
code += `${i}await driver.manage().window().setRect({ width: ${a.width}, height: ${a.height} });
|
|
1137
|
+
`;
|
|
1138
|
+
break;
|
|
1139
|
+
case "mousemove":
|
|
1140
|
+
code += `${i}await driver.actions().move({ x: ${a.x}, y: ${a.y} }).perform();
|
|
1141
|
+
`;
|
|
1142
|
+
break;
|
|
1143
|
+
case "click":
|
|
1144
|
+
code += `${i}${find(a.target.css)}.click();
|
|
1145
|
+
`;
|
|
1146
|
+
break;
|
|
1147
|
+
case "dblclick":
|
|
1148
|
+
code += `${i}await driver.actions().doubleClick(${find(a.target.css)}).perform();
|
|
440
1149
|
`;
|
|
441
|
-
}
|
|
442
1150
|
break;
|
|
443
|
-
case
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
`;
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
(n1) => n1?.["textContent"]
|
|
462
|
-
)
|
|
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;
|
|
464
|
-
if (id) {
|
|
465
|
-
code += `${indent(2)}await driver.findElement(By.css('${id}')).click();
|
|
466
|
-
`;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
break;
|
|
470
|
-
case import_types4.IncrementalSource.Scroll:
|
|
471
|
-
d = data;
|
|
472
|
-
if (d.x && d.y) {
|
|
473
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
474
|
-
code += `${indent(2)}await driver.executeScript('document.querySelector("[id=${elementId}]").scrollTo(${d.x}, ${d.y});');
|
|
475
|
-
`;
|
|
476
|
-
}
|
|
477
|
-
break;
|
|
478
|
-
case import_types4.IncrementalSource.ViewportResize:
|
|
479
|
-
d = data;
|
|
480
|
-
if (d.width && d.height) {
|
|
481
|
-
code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });
|
|
482
|
-
`;
|
|
483
|
-
}
|
|
484
|
-
break;
|
|
485
|
-
case import_types4.IncrementalSource.Input:
|
|
486
|
-
d = data;
|
|
487
|
-
if (d.text) {
|
|
488
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
489
|
-
code += `${indent(2)}const input = await driver.findElement(By.css('#${elementId}'));
|
|
490
|
-
`;
|
|
491
|
-
code += `${indent(2)}await input.clear();
|
|
492
|
-
`;
|
|
493
|
-
code += `${indent(2)}await input.sendKeys('${d.text}');
|
|
494
|
-
`;
|
|
495
|
-
}
|
|
496
|
-
break;
|
|
497
|
-
case import_types4.IncrementalSource.MediaInteraction:
|
|
498
|
-
d = data;
|
|
499
|
-
if (d.type) {
|
|
500
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
501
|
-
code += `${indent(2)}await driver.executeScript('document.querySelector("[id=${elementId}]").${d.type}();');
|
|
502
|
-
`;
|
|
503
|
-
}
|
|
504
|
-
break;
|
|
1151
|
+
case "fill": {
|
|
1152
|
+
const value = a.masked ? MASKED_PLACEHOLDER : a.value;
|
|
1153
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
1154
|
+
`;
|
|
1155
|
+
if (isScriptValueInput(a.target)) {
|
|
1156
|
+
code += `${i}await driver.executeScript(${SET_VALUE_SCRIPT}, ${find(a.target.css)}, ${q(value)});
|
|
1157
|
+
`;
|
|
1158
|
+
} else {
|
|
1159
|
+
code += `${i}{
|
|
1160
|
+
`;
|
|
1161
|
+
code += `${i} const el = ${find(a.target.css)};
|
|
1162
|
+
`;
|
|
1163
|
+
code += `${i} await el.clear();
|
|
1164
|
+
`;
|
|
1165
|
+
if (value) code += `${i} await el.sendKeys(${q(value)});
|
|
1166
|
+
`;
|
|
1167
|
+
code += `${i}}
|
|
1168
|
+
`;
|
|
505
1169
|
}
|
|
506
1170
|
break;
|
|
507
|
-
|
|
1171
|
+
}
|
|
1172
|
+
case "check":
|
|
1173
|
+
code += `${i}await driver.executeScript('if (arguments[0].checked !== arguments[1]) arguments[0].click();', ${find(a.target.css)}, ${a.checked});
|
|
1174
|
+
`;
|
|
1175
|
+
break;
|
|
1176
|
+
case "select":
|
|
1177
|
+
if (a.masked) code += `${i}${MASKED_VALUE_TODO}
|
|
1178
|
+
`;
|
|
1179
|
+
code += `${i}await driver.executeScript(${SET_VALUE_SCRIPT}, ${find(a.target.css)}, ${q(a.masked ? MASKED_PLACEHOLDER : a.value)});
|
|
1180
|
+
`;
|
|
1181
|
+
break;
|
|
1182
|
+
case "scroll":
|
|
1183
|
+
code += a.target ? `${i}await driver.executeScript('arguments[0].scrollTo(arguments[1], arguments[2]);', ${find(a.target.css)}, ${a.x}, ${a.y});
|
|
1184
|
+
` : `${i}await driver.executeScript('window.scrollTo(arguments[0], arguments[1]);', ${a.x}, ${a.y});
|
|
1185
|
+
`;
|
|
1186
|
+
break;
|
|
1187
|
+
case "media":
|
|
1188
|
+
code += `${i}await driver.executeScript('arguments[0].${a.action}();', ${find(a.target.css)});
|
|
1189
|
+
`;
|
|
1190
|
+
break;
|
|
1191
|
+
case "seek":
|
|
1192
|
+
code += `${i}await driver.executeScript('arguments[0].currentTime = arguments[1];', ${find(a.target.css)}, ${a.currentTime});
|
|
1193
|
+
`;
|
|
508
1194
|
break;
|
|
509
1195
|
}
|
|
510
1196
|
});
|
|
511
|
-
code += `${indent(
|
|
1197
|
+
code += `${indent(2)}});
|
|
512
1198
|
`;
|
|
513
1199
|
code += `});
|
|
514
1200
|
`;
|
|
515
1201
|
return code;
|
|
516
1202
|
};
|
|
517
1203
|
|
|
1204
|
+
// src/xcuitest/index.ts
|
|
1205
|
+
var tapTarget = (loc) => {
|
|
1206
|
+
if (!loc) return `app.buttons["TODO_add_accessibility_identifier"]`;
|
|
1207
|
+
if (loc.strategy === "text")
|
|
1208
|
+
return `app.staticTexts[${swiftString(loc.value)}]`;
|
|
1209
|
+
return `app.buttons[${swiftString(loc.value)}]`;
|
|
1210
|
+
};
|
|
1211
|
+
var inputTarget = (loc) => {
|
|
1212
|
+
if (!loc) return `app.textFields["TODO_add_accessibility_identifier"]`;
|
|
1213
|
+
return `app.textFields[${swiftString(loc.value)}]`;
|
|
1214
|
+
};
|
|
1215
|
+
var swipeFn2 = (direction) => ({
|
|
1216
|
+
up: "swipeUp",
|
|
1217
|
+
down: "swipeDown",
|
|
1218
|
+
left: "swipeLeft",
|
|
1219
|
+
right: "swipeRight"
|
|
1220
|
+
})[direction];
|
|
1221
|
+
var generateXcuiTests = (events) => {
|
|
1222
|
+
const actions = extractMobileActions(events);
|
|
1223
|
+
let code = "";
|
|
1224
|
+
code += `// XCUITest (Swift) \u2014 generated from a session recording
|
|
1225
|
+
`;
|
|
1226
|
+
code += `func testReplaySession() {
|
|
1227
|
+
`;
|
|
1228
|
+
code += `${indent(2)}let app = XCUIApplication()
|
|
1229
|
+
`;
|
|
1230
|
+
code += `${indent(2)}app.launch()
|
|
1231
|
+
`;
|
|
1232
|
+
actions.forEach((a) => {
|
|
1233
|
+
switch (a.kind) {
|
|
1234
|
+
case "launch":
|
|
1235
|
+
break;
|
|
1236
|
+
// already launched above
|
|
1237
|
+
case "tap":
|
|
1238
|
+
code += `${indent(2)}${tapTarget(a.locator)}.tap()
|
|
1239
|
+
`;
|
|
1240
|
+
break;
|
|
1241
|
+
case "input":
|
|
1242
|
+
code += `${indent(2)}${inputTarget(a.locator)}.tap()
|
|
1243
|
+
`;
|
|
1244
|
+
code += `${indent(2)}${inputTarget(a.locator)}.typeText(${swiftString(a.text)})
|
|
1245
|
+
`;
|
|
1246
|
+
break;
|
|
1247
|
+
case "swipe":
|
|
1248
|
+
code += `${indent(2)}app.${swipeFn2(a.direction)}()
|
|
1249
|
+
`;
|
|
1250
|
+
break;
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
code += `}
|
|
1254
|
+
`;
|
|
1255
|
+
return code;
|
|
1256
|
+
};
|
|
1257
|
+
|
|
518
1258
|
// src/core.ts
|
|
519
1259
|
var generateTests = (events, options) => {
|
|
520
1260
|
switch (options?.framework) {
|
|
@@ -526,6 +1266,14 @@ var generateTests = (events, options) => {
|
|
|
526
1266
|
return generateSeleniumTests(events);
|
|
527
1267
|
case TestFramework.PUPPETEER:
|
|
528
1268
|
return generatePuppeteerTests(events);
|
|
1269
|
+
case TestFramework.APPIUM:
|
|
1270
|
+
return generateAppiumTests(events);
|
|
1271
|
+
case TestFramework.ESPRESSO:
|
|
1272
|
+
return generateEspressoTests(events);
|
|
1273
|
+
case TestFramework.XCUITEST:
|
|
1274
|
+
return generateXcuiTests(events);
|
|
1275
|
+
case TestFramework.DETOX:
|
|
1276
|
+
return generateDetoxTests(events);
|
|
529
1277
|
default:
|
|
530
1278
|
return generatePlaywrightTests(events);
|
|
531
1279
|
}
|
|
@@ -535,6 +1283,7 @@ var generateBrowserTests = (events, options) => {
|
|
|
535
1283
|
};
|
|
536
1284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
537
1285
|
0 && (module.exports = {
|
|
1286
|
+
MOBILE_FRAMEWORKS,
|
|
538
1287
|
TestFramework,
|
|
539
1288
|
generateBrowserTests
|
|
540
1289
|
});
|