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/package.json
CHANGED
|
@@ -1,16 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rrweb-browser-test",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Generate Playwright, Cypress, Puppeteer, Selenium and mobile (Appium, Espresso, XCUITest, Detox) tests from rrweb session recordings",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rrweb",
|
|
7
|
+
"session-replay",
|
|
8
|
+
"session-recording",
|
|
9
|
+
"test-generation",
|
|
10
|
+
"e2e",
|
|
11
|
+
"playwright",
|
|
12
|
+
"cypress",
|
|
13
|
+
"puppeteer",
|
|
14
|
+
"selenium",
|
|
15
|
+
"appium",
|
|
16
|
+
"espresso",
|
|
17
|
+
"xcuitest",
|
|
18
|
+
"detox"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://github.com/Archish27/rrweb-browser-test#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Archish27/rrweb-browser-test/issues"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/Archish27/rrweb-browser-test.git"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"author": "Archish Thakkar",
|
|
6
30
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
31
|
+
"main": "./dist/index.cjs",
|
|
32
|
+
"module": "./dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"exports": {
|
|
35
|
+
"./package.json": "./package.json",
|
|
36
|
+
".": {
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=18"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"provenance": true
|
|
14
51
|
},
|
|
15
52
|
"scripts": {
|
|
16
53
|
"dev": "vitest",
|
|
@@ -22,34 +59,21 @@
|
|
|
22
59
|
"test": "vitest run",
|
|
23
60
|
"check-format": "prettier --check .",
|
|
24
61
|
"check-exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
62
|
+
"prepublishOnly": "npm run ci",
|
|
63
|
+
"test:coverage": "vitest run --coverage",
|
|
64
|
+
"changeset": "changeset",
|
|
65
|
+
"release": "npm run build && changeset publish"
|
|
27
66
|
},
|
|
28
|
-
"exports": {
|
|
29
|
-
"./package.json": "./package.json",
|
|
30
|
-
".": {
|
|
31
|
-
"import": "./dist/index.js",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
"repository": {
|
|
36
|
-
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/Archish27/rrweb-browser-test.git"
|
|
38
|
-
},
|
|
39
|
-
"keywords": [
|
|
40
|
-
"rrweb",
|
|
41
|
-
"playwright",
|
|
42
|
-
"puppeteer",
|
|
43
|
-
"cypress",
|
|
44
|
-
"selenium"
|
|
45
|
-
],
|
|
46
|
-
"author": "",
|
|
47
|
-
"license": "MIT",
|
|
48
|
-
"bugs": {
|
|
49
|
-
"url": "https://github.com/Archish27/rrweb-browser-test/issues"
|
|
50
|
-
},
|
|
51
|
-
"homepage": "https://github.com/Archish27/rrweb-browser-test#readme",
|
|
52
67
|
"dependencies": {
|
|
53
68
|
"@rrweb/types": "^2.0.0-alpha.17"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@arethetypeswrong/cli": "^0.17.0",
|
|
72
|
+
"@changesets/cli": "^2.27.10",
|
|
73
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
74
|
+
"prettier": "^3.3.3",
|
|
75
|
+
"tsup": "^8.3.5",
|
|
76
|
+
"typescript": "^5.6.3",
|
|
77
|
+
"vitest": "^2.1.5"
|
|
54
78
|
}
|
|
55
79
|
}
|
package/.changeset/README.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# Changesets
|
|
2
|
-
|
|
3
|
-
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
-
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
-
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
-
|
|
7
|
-
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
-
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
package/.changeset/config.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://unpkg.com/@changesets/config@3.0.4/schema.json",
|
|
3
|
-
"changelog": "@changesets/cli/changelog",
|
|
4
|
-
"commit": true,
|
|
5
|
-
"fixed": [],
|
|
6
|
-
"linked": [],
|
|
7
|
-
"access": "public",
|
|
8
|
-
"baseBranch": "main",
|
|
9
|
-
"updateInternalDependencies": "patch",
|
|
10
|
-
"ignore": []
|
|
11
|
-
}
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
push:
|
|
6
|
-
branches:
|
|
7
|
-
- main
|
|
8
|
-
|
|
9
|
-
concurrency:
|
|
10
|
-
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
-
cancel-in-progress: true
|
|
12
|
-
|
|
13
|
-
jobs:
|
|
14
|
-
ci:
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
|
|
17
|
-
steps:
|
|
18
|
-
- uses: actions/checkout@v4
|
|
19
|
-
|
|
20
|
-
- name: Use Node.js
|
|
21
|
-
uses: actions/setup-node@v4
|
|
22
|
-
with:
|
|
23
|
-
node-version: '20'
|
|
24
|
-
|
|
25
|
-
- name: Install dependencies
|
|
26
|
-
run: npm install
|
|
27
|
-
|
|
28
|
-
- name: Run CI
|
|
29
|
-
run: npm run ci
|
package/.prettierrc
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
# rrweb-browser-test
|
|
2
|
-
|
|
3
|
-
## 2.2.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- ac0b3b1: Add mobile test framework generators and fix selector/event handling
|
|
8
|
-
|
|
9
|
-
- Add Appium, Espresso, XCUITest and Detox generators, backed by a shared
|
|
10
|
-
`src/mobile/shared.ts` helper, plus a `MOBILE_FRAMEWORKS` export for
|
|
11
|
-
distinguishing native-app targets from browser ones.
|
|
12
|
-
- Export the `TestOptions` type from the package entrypoint.
|
|
13
|
-
- Fix `IncrementalSource.MouseMove || IncrementalSource.TouchMove` in the
|
|
14
|
-
switch statements of every web generator — the `||` collapsed to a single
|
|
15
|
-
case, so touch-move events were never handled.
|
|
16
|
-
- Replace ad-hoc `tag.class` selector building with a shared `cssSelector`
|
|
17
|
-
helper that prefers `id`, handles multiple space-separated classes, escapes
|
|
18
|
-
classes that aren't valid bare selectors, and never emits `tag.undefined`.
|
|
19
|
-
|
|
20
|
-
## 2.1.4
|
|
21
|
-
|
|
22
|
-
### Patch Changes
|
|
23
|
-
|
|
24
|
-
- 25667dc: :art: Removed console log line
|
|
25
|
-
|
|
26
|
-
## 2.1.3
|
|
27
|
-
|
|
28
|
-
### Patch Changes
|
|
29
|
-
|
|
30
|
-
- ab9f474: indent fixes
|
|
31
|
-
|
|
32
|
-
## 2.1.2
|
|
33
|
-
|
|
34
|
-
### Patch Changes
|
|
35
|
-
|
|
36
|
-
- 105d878: :bug: fix in generating click tests
|
|
37
|
-
|
|
38
|
-
## 2.1.1
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- 39e5ed9: Bug fix for generating tests
|
|
43
|
-
|
|
44
|
-
## 2.1.0
|
|
45
|
-
|
|
46
|
-
### Minor Changes
|
|
47
|
-
|
|
48
|
-
- 5ecdf00: :sparle: Support for puppeteer, cypress and selenium
|
|
49
|
-
|
|
50
|
-
## 2.0.1
|
|
51
|
-
|
|
52
|
-
### Patch Changes
|
|
53
|
-
|
|
54
|
-
- 76f7ce2: Exporting browser test function
|
|
55
|
-
|
|
56
|
-
## 2.0.0
|
|
57
|
-
|
|
58
|
-
### Major Changes
|
|
59
|
-
|
|
60
|
-
- e5ae4fa: :sparkle: Playwright auto-generation script code from rrweb events"
|
|
61
|
-
|
|
62
|
-
## 1.0.1
|
|
63
|
-
|
|
64
|
-
### Patch Changes
|
|
65
|
-
|
|
66
|
-
- 39106c0: Initial release
|
package/example/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { generateBrowserTests, TestFramework } from '../dist/index.cjs';
|
|
2
|
-
import events from 'events.json' with { type: 'json' };
|
|
3
|
-
|
|
4
|
-
console.log(generateBrowserTests(events).toCode());
|
|
5
|
-
console.log(
|
|
6
|
-
generateBrowserTests(events, {
|
|
7
|
-
framework: TestFramework.PLAYWRIGHT,
|
|
8
|
-
}).toCode(),
|
|
9
|
-
);
|
|
10
|
-
console.log(
|
|
11
|
-
generateBrowserTests(events, { framework: TestFramework.CYPRESS }).toCode(),
|
|
12
|
-
);
|
|
13
|
-
console.log(
|
|
14
|
-
generateBrowserTests(events, { framework: TestFramework.SELENIUM }).toCode(),
|
|
15
|
-
);
|
|
16
|
-
console.log(
|
|
17
|
-
generateBrowserTests(events, { framework: TestFramework.PUPPETEER }).toCode(),
|
|
18
|
-
);
|
package/src/appium/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
-
import { indent } from '../utils';
|
|
3
|
-
import { extractMobileActions, type MobileLocator } from '../mobile/shared';
|
|
4
|
-
|
|
5
|
-
const esc = (s: string) => s.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
6
|
-
|
|
7
|
-
const selector = (loc?: MobileLocator): string => {
|
|
8
|
-
if (!loc) return `$('~TODO_add_accessibility_id')`;
|
|
9
|
-
switch (loc.strategy) {
|
|
10
|
-
case 'id':
|
|
11
|
-
return `$('android=new UiSelector().resourceId("${esc(loc.value)}")')`;
|
|
12
|
-
case 'accessibility':
|
|
13
|
-
return `$('~${esc(loc.value)}')`;
|
|
14
|
-
case 'text':
|
|
15
|
-
return `$('android=new UiSelector().text("${esc(loc.value)}")')`;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Appium (WebdriverIO) mobile test from a session recording. */
|
|
20
|
-
export const generateAppiumTests = (
|
|
21
|
-
events: Array<eventWithTime | string>,
|
|
22
|
-
): string => {
|
|
23
|
-
const actions = extractMobileActions(events);
|
|
24
|
-
let code = '';
|
|
25
|
-
|
|
26
|
-
code += `// Appium + WebdriverIO — generated from a session recording\n`;
|
|
27
|
-
code += `describe('replayed session', () => {\n`;
|
|
28
|
-
code += `${indent(2)}it('replays the recorded user flow', async () => {\n`;
|
|
29
|
-
|
|
30
|
-
actions.forEach((a) => {
|
|
31
|
-
switch (a.kind) {
|
|
32
|
-
case 'launch':
|
|
33
|
-
code += `${indent(4)}await driver.launchApp();\n`;
|
|
34
|
-
break;
|
|
35
|
-
case 'tap':
|
|
36
|
-
code += `${indent(4)}await ${selector(a.locator)}.click();\n`;
|
|
37
|
-
break;
|
|
38
|
-
case 'input':
|
|
39
|
-
code += `${indent(4)}await ${selector(a.locator)}.setValue('${esc(a.text)}');\n`;
|
|
40
|
-
break;
|
|
41
|
-
case 'swipe':
|
|
42
|
-
code += `${indent(4)}await driver.execute('mobile: swipeGesture', { direction: '${a.direction}', percent: 0.75 });\n`;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
code += `${indent(2)}});\n`;
|
|
48
|
-
code += `});\n`;
|
|
49
|
-
return code;
|
|
50
|
-
};
|
package/src/core.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
-
import { generateAppiumTests } from './appium';
|
|
3
|
-
import { generateCypressTests } from './cypress';
|
|
4
|
-
import { generateDetoxTests } from './detox';
|
|
5
|
-
import { generateEspressoTests } from './espresso';
|
|
6
|
-
import { generatePlaywrightTests } from './playwright';
|
|
7
|
-
import { generatePuppeteerTests } from './puppeteer';
|
|
8
|
-
import { generateSeleniumTests } from './selenium';
|
|
9
|
-
import { generateXcuiTests } from './xcuitest';
|
|
10
|
-
import { TestFramework, type TestOptions } from './types';
|
|
11
|
-
|
|
12
|
-
const generateTests = (
|
|
13
|
-
events: Array<eventWithTime | string>,
|
|
14
|
-
options?: TestOptions,
|
|
15
|
-
): string => {
|
|
16
|
-
switch (options?.framework) {
|
|
17
|
-
case TestFramework.PLAYWRIGHT:
|
|
18
|
-
return generatePlaywrightTests(events);
|
|
19
|
-
case TestFramework.CYPRESS:
|
|
20
|
-
return generateCypressTests(events);
|
|
21
|
-
case TestFramework.SELENIUM:
|
|
22
|
-
return generateSeleniumTests(events);
|
|
23
|
-
case TestFramework.PUPPETEER:
|
|
24
|
-
return generatePuppeteerTests(events);
|
|
25
|
-
case TestFramework.APPIUM:
|
|
26
|
-
return generateAppiumTests(events);
|
|
27
|
-
case TestFramework.ESPRESSO:
|
|
28
|
-
return generateEspressoTests(events);
|
|
29
|
-
case TestFramework.XCUITEST:
|
|
30
|
-
return generateXcuiTests(events);
|
|
31
|
-
case TestFramework.DETOX:
|
|
32
|
-
return generateDetoxTests(events);
|
|
33
|
-
default:
|
|
34
|
-
return generatePlaywrightTests(events);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const generateBrowserTests = (
|
|
39
|
-
events: Array<eventWithTime | string>,
|
|
40
|
-
options?: TestOptions,
|
|
41
|
-
): string => {
|
|
42
|
-
return generateTests(events, options);
|
|
43
|
-
};
|
package/src/cypress/index.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EventType,
|
|
3
|
-
IncrementalSource,
|
|
4
|
-
MouseInteractions,
|
|
5
|
-
type eventWithTime,
|
|
6
|
-
type fullSnapshotEvent,
|
|
7
|
-
type inputData,
|
|
8
|
-
type mediaInteractionData,
|
|
9
|
-
type mouseInteractionData,
|
|
10
|
-
type mousemoveData,
|
|
11
|
-
type scrollData,
|
|
12
|
-
type viewportResizeData,
|
|
13
|
-
} from '@rrweb/types';
|
|
14
|
-
import { buildNodeMapFromFullSnapshots, cssSelector, indent } from '../utils';
|
|
15
|
-
|
|
16
|
-
export const generateCypressTests = (
|
|
17
|
-
events: Array<eventWithTime | string>,
|
|
18
|
-
): string => {
|
|
19
|
-
let code = '';
|
|
20
|
-
|
|
21
|
-
code += `describe('TODO: name the test block', () => {\n`;
|
|
22
|
-
code += ` it('TODO: name the test case', () => {\n`;
|
|
23
|
-
|
|
24
|
-
const fullSnapshotEvents = events.filter(
|
|
25
|
-
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
26
|
-
) as fullSnapshotEvent[];
|
|
27
|
-
const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
|
|
28
|
-
|
|
29
|
-
events.forEach((event: eventWithTime | string) => {
|
|
30
|
-
const e = event as eventWithTime;
|
|
31
|
-
switch (e.type) {
|
|
32
|
-
case EventType.Meta:
|
|
33
|
-
if (e.data.href) {
|
|
34
|
-
code += `${indent(3)}cy.visit('${e.data.href}');\n`;
|
|
35
|
-
code += `${indent(3)}cy.url().should('include', '${e.data.href}');\n`; // Assert URL after navigation
|
|
36
|
-
}
|
|
37
|
-
if (e.data.width && e.data.height) {
|
|
38
|
-
code += `${indent(3)}cy.viewport(${e.data.width}, ${e.data.height});\n`;
|
|
39
|
-
}
|
|
40
|
-
break;
|
|
41
|
-
|
|
42
|
-
case EventType.IncrementalSnapshot:
|
|
43
|
-
const data = e.data;
|
|
44
|
-
const type = data.source;
|
|
45
|
-
let d;
|
|
46
|
-
switch (type) {
|
|
47
|
-
case IncrementalSource.MouseMove:
|
|
48
|
-
case IncrementalSource.TouchMove:
|
|
49
|
-
d = data as mousemoveData;
|
|
50
|
-
if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
|
|
51
|
-
code += `${indent(3)}cy.get('body').trigger('mousemove', { clientX: ${d.positions[0].x}, clientY: ${d.positions[0].y} });\n`;
|
|
52
|
-
}
|
|
53
|
-
break;
|
|
54
|
-
|
|
55
|
-
case IncrementalSource.MouseInteraction:
|
|
56
|
-
d = data as mouseInteractionData;
|
|
57
|
-
if (d.type === MouseInteractions.Click) {
|
|
58
|
-
const clickNode = nodeMap.get(d.id);
|
|
59
|
-
const id = clickNode?.attributes?.id
|
|
60
|
-
? `#${clickNode?.attributes?.id}`
|
|
61
|
-
: clickNode?.tagName === 'nav'
|
|
62
|
-
? `${clickNode?.tagName}:text-is("${clickNode.childNodes
|
|
63
|
-
?.filter((f) => f.tagName === 'a')
|
|
64
|
-
?.map((node) =>
|
|
65
|
-
node.childNodes?.map(
|
|
66
|
-
(n1) => (n1 as any)?.['textContent'],
|
|
67
|
-
),
|
|
68
|
-
)
|
|
69
|
-
.join(' ')}")`
|
|
70
|
-
: clickNode?.tagName === 'a'
|
|
71
|
-
? `${clickNode?.tagName}:has-text("${clickNode.childNodes
|
|
72
|
-
?.map((node) => (node as any)?.['textContent'])
|
|
73
|
-
.join(' ')}")`
|
|
74
|
-
: clickNode !== undefined
|
|
75
|
-
? cssSelector(clickNode)
|
|
76
|
-
: undefined;
|
|
77
|
-
if (id) {
|
|
78
|
-
if (clickNode?.tagName === 'nav') {
|
|
79
|
-
code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();\n`;
|
|
80
|
-
} else {
|
|
81
|
-
code += `${indent(3)}cy.get('${id}').click();\n`;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
|
|
87
|
-
case IncrementalSource.Scroll:
|
|
88
|
-
d = data as scrollData;
|
|
89
|
-
if (d.x && d.y) {
|
|
90
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y});\n`;
|
|
91
|
-
}
|
|
92
|
-
break;
|
|
93
|
-
|
|
94
|
-
case IncrementalSource.ViewportResize:
|
|
95
|
-
d = data as viewportResizeData;
|
|
96
|
-
if (d.width && d.height) {
|
|
97
|
-
code += `${indent(3)}cy.viewport(${d.width}, ${d.height});\n`;
|
|
98
|
-
}
|
|
99
|
-
break;
|
|
100
|
-
|
|
101
|
-
case IncrementalSource.Input:
|
|
102
|
-
d = data as inputData;
|
|
103
|
-
if (d.text) {
|
|
104
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').type('${d.text}');\n`;
|
|
105
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').should('have.value', '${d.text}');\n`; // Assert input value
|
|
106
|
-
}
|
|
107
|
-
break;
|
|
108
|
-
|
|
109
|
-
case IncrementalSource.MediaInteraction:
|
|
110
|
-
d = data as mediaInteractionData;
|
|
111
|
-
if (d.type) {
|
|
112
|
-
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').then((el) => el[0].${d.type}());\n`;
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
|
|
118
|
-
default:
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
code += ` });\n`;
|
|
124
|
-
code += `});\n`;
|
|
125
|
-
|
|
126
|
-
return code;
|
|
127
|
-
};
|
package/src/detox/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
-
import { indent } from '../utils';
|
|
3
|
-
import { extractMobileActions, type MobileLocator } from '../mobile/shared';
|
|
4
|
-
|
|
5
|
-
const esc = (s: string) => s.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
6
|
-
|
|
7
|
-
const matcher = (loc?: MobileLocator): string => {
|
|
8
|
-
if (!loc) return `by.id('TODO_add_testID')`;
|
|
9
|
-
switch (loc.strategy) {
|
|
10
|
-
case 'id':
|
|
11
|
-
return `by.id('${esc(loc.value)}')`;
|
|
12
|
-
case 'accessibility':
|
|
13
|
-
return `by.label('${esc(loc.value)}')`;
|
|
14
|
-
case 'text':
|
|
15
|
-
return `by.text('${esc(loc.value)}')`;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Detox (JavaScript) mobile test from a session recording. */
|
|
20
|
-
export const generateDetoxTests = (
|
|
21
|
-
events: Array<eventWithTime | string>,
|
|
22
|
-
): string => {
|
|
23
|
-
const actions = extractMobileActions(events);
|
|
24
|
-
let code = '';
|
|
25
|
-
|
|
26
|
-
code += `// Detox — generated from a session recording\n`;
|
|
27
|
-
code += `describe('replayed session', () => {\n`;
|
|
28
|
-
code += `${indent(2)}it('replays the recorded user flow', async () => {\n`;
|
|
29
|
-
|
|
30
|
-
actions.forEach((a) => {
|
|
31
|
-
switch (a.kind) {
|
|
32
|
-
case 'launch':
|
|
33
|
-
code += `${indent(4)}await device.launchApp({ newInstance: true });\n`;
|
|
34
|
-
break;
|
|
35
|
-
case 'tap':
|
|
36
|
-
code += `${indent(4)}await element(${matcher(a.locator)}).tap();\n`;
|
|
37
|
-
break;
|
|
38
|
-
case 'input':
|
|
39
|
-
code += `${indent(4)}await element(${matcher(a.locator)}).typeText('${esc(a.text)}');\n`;
|
|
40
|
-
break;
|
|
41
|
-
case 'swipe':
|
|
42
|
-
code += `${indent(4)}await element(by.id('scrollView')).swipe('${a.direction}');\n`;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
code += `${indent(2)}});\n`;
|
|
48
|
-
code += `});\n`;
|
|
49
|
-
return code;
|
|
50
|
-
};
|
package/src/espresso/index.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
-
import { indent } from '../utils';
|
|
3
|
-
import {
|
|
4
|
-
extractMobileActions,
|
|
5
|
-
resourceIdLeaf,
|
|
6
|
-
type MobileLocator,
|
|
7
|
-
} from '../mobile/shared';
|
|
8
|
-
|
|
9
|
-
const esc = (s: string) => s.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
10
|
-
|
|
11
|
-
const matcher = (loc?: MobileLocator): string => {
|
|
12
|
-
if (!loc) return `withContentDescription("TODO_add_content_description")`;
|
|
13
|
-
switch (loc.strategy) {
|
|
14
|
-
case 'id':
|
|
15
|
-
return `withId(R.id.${resourceIdLeaf(loc.value)})`;
|
|
16
|
-
case 'accessibility':
|
|
17
|
-
return `withContentDescription("${esc(loc.value)}")`;
|
|
18
|
-
case 'text':
|
|
19
|
-
return `withText("${esc(loc.value)}")`;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const swipeFn = (direction: 'up' | 'down' | 'left' | 'right') =>
|
|
24
|
-
({
|
|
25
|
-
up: 'swipeUp',
|
|
26
|
-
down: 'swipeDown',
|
|
27
|
-
left: 'swipeLeft',
|
|
28
|
-
right: 'swipeRight',
|
|
29
|
-
})[direction];
|
|
30
|
-
|
|
31
|
-
/** Espresso (Kotlin) mobile test from a session recording. */
|
|
32
|
-
export const generateEspressoTests = (
|
|
33
|
-
events: Array<eventWithTime | string>,
|
|
34
|
-
): string => {
|
|
35
|
-
const actions = extractMobileActions(events);
|
|
36
|
-
let code = '';
|
|
37
|
-
|
|
38
|
-
code += `// Espresso (Kotlin) — generated from a session recording\n`;
|
|
39
|
-
code += `@Test\n`;
|
|
40
|
-
code += `fun replaySession() {\n`;
|
|
41
|
-
|
|
42
|
-
actions.forEach((a) => {
|
|
43
|
-
switch (a.kind) {
|
|
44
|
-
case 'launch':
|
|
45
|
-
code += `${indent(2)}// App launch is handled by ActivityScenarioRule\n`;
|
|
46
|
-
break;
|
|
47
|
-
case 'tap':
|
|
48
|
-
code += `${indent(2)}onView(${matcher(a.locator)}).perform(click())\n`;
|
|
49
|
-
break;
|
|
50
|
-
case 'input':
|
|
51
|
-
code += `${indent(2)}onView(${matcher(a.locator)}).perform(typeText("${esc(a.text)}"), closeSoftKeyboard())\n`;
|
|
52
|
-
break;
|
|
53
|
-
case 'swipe':
|
|
54
|
-
code += `${indent(2)}onView(isRoot()).perform(${swipeFn(a.direction)}())\n`;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
code += `}\n`;
|
|
60
|
-
return code;
|
|
61
|
-
};
|
package/src/index.ts
DELETED