rrweb-browser-test 2.2.0 → 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 +845 -412
- package/dist/index.js +854 -429
- package/package.json +60 -36
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/ci.yml +0 -29
- package/.prettierrc +0 -7
- package/CHANGELOG.md +0 -66
- package/example/index.js +0 -18
- package/src/appium/index.ts +0 -50
- package/src/core.ts +0 -43
- package/src/cypress/index.ts +0 -127
- package/src/detox/index.ts +0 -50
- package/src/espresso/index.ts +0 -61
- package/src/index.ts +0 -3
- package/src/mobile/shared.ts +0 -146
- package/src/playwright/index.ts +0 -131
- package/src/puppeteer/index.ts +0 -140
- package/src/selenium/index.ts +0 -136
- package/src/types.ts +0 -37
- package/src/utils.test.ts +0 -6
- package/src/utils.ts +0 -71
- package/src/xcuitest/index.ts +0 -58
- package/tsconfig.json +0 -20
- package/tsup.config.ts +0 -9
package/dist/index.cjs
CHANGED
|
@@ -46,38 +46,149 @@ var MOBILE_FRAMEWORKS = [
|
|
|
46
46
|
|
|
47
47
|
// src/utils.ts
|
|
48
48
|
var indent = (level) => " ".repeat(level);
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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);
|
|
59
84
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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;
|
|
72
181
|
}
|
|
73
182
|
}
|
|
74
|
-
|
|
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 });
|
|
75
187
|
});
|
|
76
|
-
return
|
|
188
|
+
return out.sort((a, b) => (a.timestamp || 0) - (b.timestamp || 0));
|
|
77
189
|
};
|
|
78
190
|
|
|
79
191
|
// src/mobile/shared.ts
|
|
80
|
-
var import_types = require("@rrweb/types");
|
|
81
192
|
var resourceIdLeaf = (value) => {
|
|
82
193
|
const slash = value.lastIndexOf("/");
|
|
83
194
|
return slash >= 0 ? value.slice(slash + 1) : value;
|
|
@@ -102,43 +213,50 @@ var swipeDirection = (d) => {
|
|
|
102
213
|
};
|
|
103
214
|
var extractMobileActions = (events) => {
|
|
104
215
|
const actions = [];
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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) {
|
|
112
230
|
if (e.data?.href)
|
|
113
231
|
actions.push({ kind: "launch", url: e.data.href });
|
|
114
232
|
return;
|
|
115
233
|
}
|
|
116
|
-
if (e.type !==
|
|
234
|
+
if (e.type !== import_types2.EventType.IncrementalSnapshot) return;
|
|
117
235
|
const data = e.data;
|
|
118
236
|
switch (data.source) {
|
|
119
|
-
case
|
|
237
|
+
case import_types2.IncrementalSource.MouseInteraction: {
|
|
120
238
|
const d = data;
|
|
121
|
-
if (d.type ===
|
|
239
|
+
if (d.type === import_types2.MouseInteractions.Click || d.type === import_types2.MouseInteractions.TouchEnd) {
|
|
122
240
|
actions.push({
|
|
123
241
|
kind: "tap",
|
|
124
|
-
locator: mobileLocator(
|
|
242
|
+
locator: mobileLocator(nodeAt(d.id))
|
|
125
243
|
});
|
|
126
244
|
}
|
|
127
245
|
break;
|
|
128
246
|
}
|
|
129
|
-
case
|
|
247
|
+
case import_types2.IncrementalSource.Input: {
|
|
130
248
|
const d = data;
|
|
131
249
|
if (typeof d.text === "string") {
|
|
132
250
|
actions.push({
|
|
133
251
|
kind: "input",
|
|
134
|
-
locator: mobileLocator(
|
|
252
|
+
locator: mobileLocator(nodeAt(d.id)),
|
|
135
253
|
text: d.text
|
|
136
254
|
});
|
|
137
255
|
}
|
|
138
256
|
break;
|
|
139
257
|
}
|
|
140
|
-
case
|
|
141
|
-
case
|
|
258
|
+
case import_types2.IncrementalSource.Scroll:
|
|
259
|
+
case import_types2.IncrementalSource.TouchMove: {
|
|
142
260
|
actions.push({
|
|
143
261
|
kind: "swipe",
|
|
144
262
|
direction: swipeDirection(data)
|
|
@@ -153,16 +271,15 @@ var extractMobileActions = (events) => {
|
|
|
153
271
|
};
|
|
154
272
|
|
|
155
273
|
// src/appium/index.ts
|
|
156
|
-
var esc = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
157
274
|
var selector = (loc) => {
|
|
158
275
|
if (!loc) return `$('~TODO_add_accessibility_id')`;
|
|
159
276
|
switch (loc.strategy) {
|
|
160
277
|
case "id":
|
|
161
|
-
return `$(
|
|
278
|
+
return `$(${q(`android=new UiSelector().resourceId(${doubleQuoted(loc.value)})`)})`;
|
|
162
279
|
case "accessibility":
|
|
163
|
-
return `$(
|
|
280
|
+
return `$(${q(`~${loc.value}`)})`;
|
|
164
281
|
case "text":
|
|
165
|
-
return `$(
|
|
282
|
+
return `$(${q(`android=new UiSelector().text(${doubleQuoted(loc.value)})`)})`;
|
|
166
283
|
}
|
|
167
284
|
};
|
|
168
285
|
var generateAppiumTests = (events) => {
|
|
@@ -185,7 +302,7 @@ var generateAppiumTests = (events) => {
|
|
|
185
302
|
`;
|
|
186
303
|
break;
|
|
187
304
|
case "input":
|
|
188
|
-
code += `${indent(4)}await ${selector(a.locator)}.setValue(
|
|
305
|
+
code += `${indent(4)}await ${selector(a.locator)}.setValue(${q(a.text)});
|
|
189
306
|
`;
|
|
190
307
|
break;
|
|
191
308
|
case "swipe":
|
|
@@ -201,99 +318,483 @@ var generateAppiumTests = (events) => {
|
|
|
201
318
|
return code;
|
|
202
319
|
};
|
|
203
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;
|
|
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;
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
return actions;
|
|
721
|
+
};
|
|
722
|
+
|
|
204
723
|
// src/cypress/index.ts
|
|
205
|
-
var
|
|
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, "{{}");
|
|
206
726
|
var generateCypressTests = (events) => {
|
|
727
|
+
const i = indent(4);
|
|
207
728
|
let code = "";
|
|
208
729
|
code += `describe('TODO: name the test block', () => {
|
|
209
730
|
`;
|
|
210
731
|
code += ` it('TODO: name the test case', () => {
|
|
211
732
|
`;
|
|
212
|
-
|
|
213
|
-
(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
events.forEach((event) => {
|
|
217
|
-
const e = event;
|
|
218
|
-
switch (e.type) {
|
|
219
|
-
case import_types2.EventType.Meta:
|
|
220
|
-
if (e.data.href) {
|
|
221
|
-
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)});
|
|
222
737
|
`;
|
|
223
|
-
|
|
738
|
+
code += `${i}cy.url().should('include', ${q(a.href)});
|
|
224
739
|
`;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
740
|
+
break;
|
|
741
|
+
case "viewport":
|
|
742
|
+
code += `${i}cy.viewport(${a.width}, ${a.height});
|
|
228
743
|
`;
|
|
229
|
-
}
|
|
230
744
|
break;
|
|
231
|
-
case
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
`;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
`;
|
|
257
|
-
} else {
|
|
258
|
-
code += `${indent(3)}cy.get('${id}').click();
|
|
259
|
-
`;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
break;
|
|
264
|
-
case import_types2.IncrementalSource.Scroll:
|
|
265
|
-
d = data;
|
|
266
|
-
if (d.x && d.y) {
|
|
267
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y});
|
|
268
|
-
`;
|
|
269
|
-
}
|
|
270
|
-
break;
|
|
271
|
-
case import_types2.IncrementalSource.ViewportResize:
|
|
272
|
-
d = data;
|
|
273
|
-
if (d.width && d.height) {
|
|
274
|
-
code += `${indent(3)}cy.viewport(${d.width}, ${d.height});
|
|
275
|
-
`;
|
|
276
|
-
}
|
|
277
|
-
break;
|
|
278
|
-
case import_types2.IncrementalSource.Input:
|
|
279
|
-
d = data;
|
|
280
|
-
if (d.text) {
|
|
281
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').type('${d.text}');
|
|
282
|
-
`;
|
|
283
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').should('have.value', '${d.text}');
|
|
284
|
-
`;
|
|
285
|
-
}
|
|
286
|
-
break;
|
|
287
|
-
case import_types2.IncrementalSource.MediaInteraction:
|
|
288
|
-
d = data;
|
|
289
|
-
if (d.type) {
|
|
290
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').then((el) => el[0].${d.type}());
|
|
291
|
-
`;
|
|
292
|
-
}
|
|
293
|
-
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();
|
|
751
|
+
`;
|
|
752
|
+
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
|
+
`;
|
|
294
770
|
}
|
|
771
|
+
if (!a.masked)
|
|
772
|
+
code += `${i}${get(a.target)}.should('have.value', ${q(value)});
|
|
773
|
+
`;
|
|
295
774
|
break;
|
|
296
|
-
|
|
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
|
+
`;
|
|
297
798
|
break;
|
|
298
799
|
}
|
|
299
800
|
});
|
|
@@ -305,16 +806,15 @@ var generateCypressTests = (events) => {
|
|
|
305
806
|
};
|
|
306
807
|
|
|
307
808
|
// src/detox/index.ts
|
|
308
|
-
var esc2 = (s) => s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
309
809
|
var matcher = (loc) => {
|
|
310
810
|
if (!loc) return `by.id('TODO_add_testID')`;
|
|
311
811
|
switch (loc.strategy) {
|
|
312
812
|
case "id":
|
|
313
|
-
return `by.id(
|
|
813
|
+
return `by.id(${q(loc.value)})`;
|
|
314
814
|
case "accessibility":
|
|
315
|
-
return `by.label(
|
|
815
|
+
return `by.label(${q(loc.value)})`;
|
|
316
816
|
case "text":
|
|
317
|
-
return `by.text(
|
|
817
|
+
return `by.text(${q(loc.value)})`;
|
|
318
818
|
}
|
|
319
819
|
};
|
|
320
820
|
var generateDetoxTests = (events) => {
|
|
@@ -337,7 +837,7 @@ var generateDetoxTests = (events) => {
|
|
|
337
837
|
`;
|
|
338
838
|
break;
|
|
339
839
|
case "input":
|
|
340
|
-
code += `${indent(4)}await element(${matcher(a.locator)}).typeText(
|
|
840
|
+
code += `${indent(4)}await element(${matcher(a.locator)}).typeText(${q(a.text)});
|
|
341
841
|
`;
|
|
342
842
|
break;
|
|
343
843
|
case "swipe":
|
|
@@ -354,16 +854,17 @@ var generateDetoxTests = (events) => {
|
|
|
354
854
|
};
|
|
355
855
|
|
|
356
856
|
// src/espresso/index.ts
|
|
357
|
-
var esc3 = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
358
857
|
var matcher2 = (loc) => {
|
|
359
858
|
if (!loc) return `withContentDescription("TODO_add_content_description")`;
|
|
360
859
|
switch (loc.strategy) {
|
|
361
|
-
case "id":
|
|
362
|
-
|
|
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
|
+
}
|
|
363
864
|
case "accessibility":
|
|
364
|
-
return `withContentDescription(
|
|
865
|
+
return `withContentDescription(${kotlinString(loc.value)})`;
|
|
365
866
|
case "text":
|
|
366
|
-
return `withText(
|
|
867
|
+
return `withText(${kotlinString(loc.value)})`;
|
|
367
868
|
}
|
|
368
869
|
};
|
|
369
870
|
var swipeFn = (direction) => ({
|
|
@@ -392,7 +893,7 @@ var generateEspressoTests = (events) => {
|
|
|
392
893
|
`;
|
|
393
894
|
break;
|
|
394
895
|
case "input":
|
|
395
|
-
code += `${indent(2)}onView(${matcher2(a.locator)}).perform(typeText(
|
|
896
|
+
code += `${indent(2)}onView(${matcher2(a.locator)}).perform(typeText(${kotlinString(a.text)}), closeSoftKeyboard())
|
|
396
897
|
`;
|
|
397
898
|
break;
|
|
398
899
|
case "swipe":
|
|
@@ -407,238 +908,184 @@ var generateEspressoTests = (events) => {
|
|
|
407
908
|
};
|
|
408
909
|
|
|
409
910
|
// src/playwright/index.ts
|
|
410
|
-
var
|
|
911
|
+
var locator = (t) => t.withText ? `page.locator(${q(t.withText.css)}, { hasText: ${q(t.withText.text)} })` : `page.locator(${q(t.css)})`;
|
|
411
912
|
var generatePlaywrightTests = (events) => {
|
|
913
|
+
const i = indent(2);
|
|
412
914
|
let code = "";
|
|
413
915
|
code += `import { test, expect } from '@playwright/test';
|
|
414
916
|
|
|
415
917
|
`;
|
|
416
|
-
code += `test('TODO: name the test block', async ({ page
|
|
918
|
+
code += `test('TODO: name the test block', async ({ page }) => {
|
|
417
919
|
`;
|
|
418
|
-
|
|
419
|
-
(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
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)});
|
|
423
924
|
`;
|
|
424
|
-
|
|
425
|
-
const e = event;
|
|
426
|
-
switch (e.type) {
|
|
427
|
-
case import_types3.EventType.Meta:
|
|
428
|
-
if (e.data.href) {
|
|
429
|
-
code += `${indent(2)}await page.goto('${e.data.href}');
|
|
925
|
+
code += `${i}await expect(page).toHaveURL(${q(a.href)});
|
|
430
926
|
`;
|
|
431
|
-
|
|
927
|
+
break;
|
|
928
|
+
case "viewport":
|
|
929
|
+
code += `${i}await page.setViewportSize({ width: ${a.width}, height: ${a.height} });
|
|
432
930
|
`;
|
|
433
|
-
}
|
|
434
|
-
if (e.data.width && e.data.height) {
|
|
435
|
-
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} });
|
|
436
932
|
`;
|
|
437
|
-
|
|
933
|
+
break;
|
|
934
|
+
case "mousemove":
|
|
935
|
+
code += `${i}await page.mouse.move(${a.x}, ${a.y});
|
|
438
936
|
`;
|
|
439
|
-
}
|
|
440
937
|
break;
|
|
441
|
-
case
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
(n1) => n1?.["textContent"]
|
|
461
|
-
)
|
|
462
|
-
).join(" ")}")` : clickNode?.tagName === "a" ? `${clickNode?.tagName}:has-text("${clickNode.childNodes?.map((node) => node?.["textContent"]).join(" ")}")` : clickNode !== void 0 ? cssSelector(clickNode) : void 0;
|
|
463
|
-
if (id && d.x && d.y) {
|
|
464
|
-
code += `${indent(2)}await page.locator(\`${id}\`).click();
|
|
465
|
-
`;
|
|
466
|
-
code += `${indent(2)}await expect(page.locator(\`${id}\`)).toBeVisible();
|
|
467
|
-
`;
|
|
468
|
-
}
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
-
break;
|
|
472
|
-
case import_types3.IncrementalSource.Scroll:
|
|
473
|
-
d = data;
|
|
474
|
-
if (d.x && d.y) {
|
|
475
|
-
code += `${indent(2)}await page.mouse.wheel(() => { document.querySelector('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y}); });
|
|
476
|
-
`;
|
|
477
|
-
code += `${indent(2)}await expect(page.locator('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]')).toBeVisible();
|
|
478
|
-
`;
|
|
479
|
-
}
|
|
480
|
-
break;
|
|
481
|
-
case import_types3.IncrementalSource.ViewportResize:
|
|
482
|
-
d = data;
|
|
483
|
-
if (d.width && d.height) {
|
|
484
|
-
code += `${indent(2)}await page.setViewportSize({ width: ${d.width}, height: ${d.height} });
|
|
485
|
-
`;
|
|
486
|
-
code += `${indent(2)}await expect(page).toHaveViewportSize({ width: ${d.width}, height: ${d.height} });
|
|
487
|
-
`;
|
|
488
|
-
}
|
|
489
|
-
break;
|
|
490
|
-
case import_types3.IncrementalSource.Input:
|
|
491
|
-
d = data;
|
|
492
|
-
if (d.text) {
|
|
493
|
-
code += `${indent(2)}await page.fill('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', '${d.text}');
|
|
494
|
-
`;
|
|
495
|
-
code += `${indent(2)}await expect(page.locator('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]')).toHaveValue('${d.text}');
|
|
496
|
-
`;
|
|
497
|
-
}
|
|
498
|
-
break;
|
|
499
|
-
case import_types3.IncrementalSource.MediaInteraction:
|
|
500
|
-
d = data;
|
|
501
|
-
if (d.type) {
|
|
502
|
-
code += `${indent(2)}await page.$eval('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]', el => el.${d.type}());
|
|
503
|
-
`;
|
|
504
|
-
code += `${indent(2)}await expect(page.locator('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]')).toBeVisible();
|
|
505
|
-
`;
|
|
506
|
-
}
|
|
507
|
-
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
|
+
`;
|
|
508
957
|
}
|
|
509
958
|
break;
|
|
510
|
-
|
|
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
|
+
`;
|
|
511
983
|
break;
|
|
512
984
|
}
|
|
513
985
|
});
|
|
514
|
-
code +=
|
|
986
|
+
code += `});
|
|
515
987
|
`;
|
|
516
988
|
return code;
|
|
517
989
|
};
|
|
518
990
|
|
|
519
991
|
// src/puppeteer/index.ts
|
|
520
|
-
var import_types4 = require("@rrweb/types");
|
|
521
992
|
var generatePuppeteerTests = (events) => {
|
|
993
|
+
const i = indent(4);
|
|
522
994
|
let code = "";
|
|
523
995
|
code += `const puppeteer = require('puppeteer');
|
|
524
996
|
|
|
525
997
|
`;
|
|
526
998
|
code += `describe('TODO: name the test block', () => {
|
|
527
999
|
`;
|
|
528
|
-
code += `${indent(
|
|
1000
|
+
code += `${indent(2)}let browser, page;
|
|
529
1001
|
|
|
530
1002
|
`;
|
|
531
|
-
code += `${indent(
|
|
1003
|
+
code += `${indent(2)}beforeAll(async () => {
|
|
532
1004
|
`;
|
|
533
|
-
code += `${
|
|
1005
|
+
code += `${i}browser = await puppeteer.launch();
|
|
534
1006
|
`;
|
|
535
|
-
code += `${
|
|
1007
|
+
code += `${i}page = await browser.newPage();
|
|
536
1008
|
`;
|
|
537
|
-
code += `${indent(
|
|
1009
|
+
code += `${indent(2)}});
|
|
538
1010
|
|
|
539
1011
|
`;
|
|
540
|
-
code += `${indent(
|
|
1012
|
+
code += `${indent(2)}afterAll(async () => {
|
|
541
1013
|
`;
|
|
542
|
-
code += `${
|
|
1014
|
+
code += `${i}await browser.close();
|
|
543
1015
|
`;
|
|
544
|
-
code += `${indent(
|
|
1016
|
+
code += `${indent(2)}});
|
|
545
1017
|
|
|
546
1018
|
`;
|
|
547
|
-
code += `${indent(
|
|
1019
|
+
code += `${indent(2)}test('TODO: name the test case', async () => {
|
|
548
1020
|
`;
|
|
549
|
-
|
|
550
|
-
(
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
events.forEach((event) => {
|
|
554
|
-
const e = event;
|
|
555
|
-
switch (e.type) {
|
|
556
|
-
case import_types4.EventType.Meta:
|
|
557
|
-
if (e.data.href) {
|
|
558
|
-
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)});
|
|
559
1025
|
`;
|
|
560
|
-
|
|
1026
|
+
code += `${i}expect(page.url()).toBe(${q(a.href)});
|
|
561
1027
|
`;
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
1028
|
+
break;
|
|
1029
|
+
case "viewport":
|
|
1030
|
+
code += `${i}await page.setViewport({ width: ${a.width}, height: ${a.height} });
|
|
1031
|
+
`;
|
|
1032
|
+
break;
|
|
1033
|
+
case "mousemove":
|
|
1034
|
+
code += `${i}await page.mouse.move(${a.x}, ${a.y});
|
|
565
1035
|
`;
|
|
566
|
-
}
|
|
567
1036
|
break;
|
|
568
|
-
case
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
code += `${indent(2)}await page.click('${id}');
|
|
592
|
-
`;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
break;
|
|
596
|
-
case import_types4.IncrementalSource.Scroll:
|
|
597
|
-
d = data;
|
|
598
|
-
if (d.x && d.y) {
|
|
599
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
600
|
-
code += `${indent(2)}await page.evaluate(() => {
|
|
601
|
-
`;
|
|
602
|
-
code += `${indent(3)}document.querySelector('#${elementId}').scrollTo(${d.x}, ${d.y});
|
|
603
|
-
`;
|
|
604
|
-
code += `${indent(2)}});
|
|
605
|
-
`;
|
|
606
|
-
}
|
|
607
|
-
break;
|
|
608
|
-
case import_types4.IncrementalSource.ViewportResize:
|
|
609
|
-
d = data;
|
|
610
|
-
if (d.width && d.height) {
|
|
611
|
-
code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });
|
|
612
|
-
`;
|
|
613
|
-
}
|
|
614
|
-
break;
|
|
615
|
-
case import_types4.IncrementalSource.Input:
|
|
616
|
-
d = data;
|
|
617
|
-
if (d.text) {
|
|
618
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
619
|
-
code += `${indent(2)}await page.type('#${elementId}', '${d.text}');
|
|
620
|
-
`;
|
|
621
|
-
}
|
|
622
|
-
break;
|
|
623
|
-
case import_types4.IncrementalSource.MediaInteraction:
|
|
624
|
-
d = data;
|
|
625
|
-
if (d.type) {
|
|
626
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
627
|
-
code += `${indent(2)}await page.evaluate(() => {
|
|
628
|
-
`;
|
|
629
|
-
code += `${indent(3)}document.querySelector('#${elementId}').${d.type}();
|
|
630
|
-
`;
|
|
631
|
-
code += `${indent(2)}});
|
|
632
|
-
`;
|
|
633
|
-
}
|
|
634
|
-
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
|
+
`;
|
|
635
1060
|
}
|
|
636
1061
|
break;
|
|
637
|
-
|
|
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
|
+
`;
|
|
638
1085
|
break;
|
|
639
1086
|
}
|
|
640
1087
|
});
|
|
641
|
-
code += `${indent(
|
|
1088
|
+
code += `${indent(2)}});
|
|
642
1089
|
`;
|
|
643
1090
|
code += `});
|
|
644
1091
|
`;
|
|
@@ -646,122 +1093,108 @@ var generatePuppeteerTests = (events) => {
|
|
|
646
1093
|
};
|
|
647
1094
|
|
|
648
1095
|
// src/selenium/index.ts
|
|
649
|
-
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
|
+
);
|
|
650
1100
|
var generateSeleniumTests = (events) => {
|
|
1101
|
+
const i = indent(4);
|
|
651
1102
|
let code = "";
|
|
652
1103
|
code += `const { Builder, By, until } = require('selenium-webdriver');
|
|
653
1104
|
|
|
654
1105
|
`;
|
|
655
1106
|
code += `describe('TODO: name the test block', () => {
|
|
656
1107
|
`;
|
|
657
|
-
code += `${indent(
|
|
1108
|
+
code += `${indent(2)}let driver;
|
|
658
1109
|
|
|
659
1110
|
`;
|
|
660
|
-
code += `${indent(
|
|
1111
|
+
code += `${indent(2)}beforeAll(async () => {
|
|
661
1112
|
`;
|
|
662
|
-
code += `${
|
|
1113
|
+
code += `${i}driver = await new Builder().forBrowser('chrome').build();
|
|
663
1114
|
`;
|
|
664
|
-
code += `${indent(
|
|
1115
|
+
code += `${indent(2)}});
|
|
665
1116
|
|
|
666
1117
|
`;
|
|
667
|
-
code += `${indent(
|
|
1118
|
+
code += `${indent(2)}afterAll(async () => {
|
|
668
1119
|
`;
|
|
669
|
-
code += `${
|
|
1120
|
+
code += `${i}await driver.quit();
|
|
670
1121
|
`;
|
|
671
|
-
code += `${indent(
|
|
1122
|
+
code += `${indent(2)}});
|
|
672
1123
|
|
|
673
1124
|
`;
|
|
674
|
-
code += `${indent(
|
|
1125
|
+
code += `${indent(2)}test('TODO: name the test case', async () => {
|
|
675
1126
|
`;
|
|
676
|
-
|
|
677
|
-
(
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
events.forEach((event) => {
|
|
681
|
-
const e = event;
|
|
682
|
-
switch (e.type) {
|
|
683
|
-
case import_types5.EventType.Meta:
|
|
684
|
-
if (e.data.href) {
|
|
685
|
-
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)});
|
|
686
1131
|
`;
|
|
687
|
-
|
|
1132
|
+
code += `${i}await driver.wait(until.urlIs(${q(a.href)}), 5000);
|
|
688
1133
|
`;
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
1134
|
+
break;
|
|
1135
|
+
case "viewport":
|
|
1136
|
+
code += `${i}await driver.manage().window().setRect({ width: ${a.width}, height: ${a.height} });
|
|
692
1137
|
`;
|
|
693
|
-
}
|
|
694
1138
|
break;
|
|
695
|
-
case
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
`;
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
if (d.x && d.y) {
|
|
726
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
727
|
-
code += `${indent(2)}await driver.executeScript('document.querySelector("[id=${elementId}]").scrollTo(${d.x}, ${d.y});');
|
|
728
|
-
`;
|
|
729
|
-
}
|
|
730
|
-
break;
|
|
731
|
-
case import_types5.IncrementalSource.ViewportResize:
|
|
732
|
-
d = data;
|
|
733
|
-
if (d.width && d.height) {
|
|
734
|
-
code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });
|
|
735
|
-
`;
|
|
736
|
-
}
|
|
737
|
-
break;
|
|
738
|
-
case import_types5.IncrementalSource.Input:
|
|
739
|
-
d = data;
|
|
740
|
-
if (d.text) {
|
|
741
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
742
|
-
code += `${indent(2)}const input = await driver.findElement(By.css('#${elementId}'));
|
|
743
|
-
`;
|
|
744
|
-
code += `${indent(2)}await input.clear();
|
|
745
|
-
`;
|
|
746
|
-
code += `${indent(2)}await input.sendKeys('${d.text}');
|
|
747
|
-
`;
|
|
748
|
-
}
|
|
749
|
-
break;
|
|
750
|
-
case import_types5.IncrementalSource.MediaInteraction:
|
|
751
|
-
d = data;
|
|
752
|
-
if (d.type) {
|
|
753
|
-
const elementId = nodeMap.get(d.id)?.attributes?.id || "";
|
|
754
|
-
code += `${indent(2)}await driver.executeScript('document.querySelector("[id=${elementId}]").${d.type}();');
|
|
755
|
-
`;
|
|
756
|
-
}
|
|
757
|
-
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();
|
|
1149
|
+
`;
|
|
1150
|
+
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
|
+
`;
|
|
758
1169
|
}
|
|
759
1170
|
break;
|
|
760
|
-
|
|
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
|
+
`;
|
|
761
1194
|
break;
|
|
762
1195
|
}
|
|
763
1196
|
});
|
|
764
|
-
code += `${indent(
|
|
1197
|
+
code += `${indent(2)}});
|
|
765
1198
|
`;
|
|
766
1199
|
code += `});
|
|
767
1200
|
`;
|
|
@@ -769,15 +1202,15 @@ var generateSeleniumTests = (events) => {
|
|
|
769
1202
|
};
|
|
770
1203
|
|
|
771
1204
|
// src/xcuitest/index.ts
|
|
772
|
-
var esc4 = (s) => s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
773
1205
|
var tapTarget = (loc) => {
|
|
774
1206
|
if (!loc) return `app.buttons["TODO_add_accessibility_identifier"]`;
|
|
775
|
-
if (loc.strategy === "text")
|
|
776
|
-
|
|
1207
|
+
if (loc.strategy === "text")
|
|
1208
|
+
return `app.staticTexts[${swiftString(loc.value)}]`;
|
|
1209
|
+
return `app.buttons[${swiftString(loc.value)}]`;
|
|
777
1210
|
};
|
|
778
1211
|
var inputTarget = (loc) => {
|
|
779
1212
|
if (!loc) return `app.textFields["TODO_add_accessibility_identifier"]`;
|
|
780
|
-
return `app.textFields[
|
|
1213
|
+
return `app.textFields[${swiftString(loc.value)}]`;
|
|
781
1214
|
};
|
|
782
1215
|
var swipeFn2 = (direction) => ({
|
|
783
1216
|
up: "swipeUp",
|
|
@@ -808,7 +1241,7 @@ var generateXcuiTests = (events) => {
|
|
|
808
1241
|
case "input":
|
|
809
1242
|
code += `${indent(2)}${inputTarget(a.locator)}.tap()
|
|
810
1243
|
`;
|
|
811
|
-
code += `${indent(2)}${inputTarget(a.locator)}.typeText(
|
|
1244
|
+
code += `${indent(2)}${inputTarget(a.locator)}.typeText(${swiftString(a.text)})
|
|
812
1245
|
`;
|
|
813
1246
|
break;
|
|
814
1247
|
case "swipe":
|