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/README.md
CHANGED
|
@@ -1,33 +1,134 @@
|
|
|
1
1
|
# rrweb-browser-test
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
3
|
+
[](https://github.com/Archish27/rrweb-browser-test/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/rrweb-browser-test)
|
|
5
|
+
[](https://www.npmjs.com/package/rrweb-browser-test)
|
|
6
|
+
[](https://www.npmjs.com/package/rrweb-browser-test)
|
|
7
|
+
[](https://bundlephobia.com/package/rrweb-browser-test)
|
|
8
|
+
[](https://www.npmjs.com/package/rrweb-browser-test)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](CONTRIBUTING.md)
|
|
11
|
+
|
|
12
|
+
Turn an [rrweb](https://github.com/rrweb-io/rrweb) session recording into an
|
|
13
|
+
end-to-end test. Record a real user journey once, get a Playwright, Cypress,
|
|
14
|
+
Puppeteer or Selenium script back (or a mobile test for Appium, Espresso,
|
|
15
|
+
XCUITest or Detox).
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
await page.locator('button[data-testid="header-datepicker"]').click();
|
|
19
|
+
await page.locator('div.list-item', { hasText: 'Past week' }).click();
|
|
20
|
+
await page.locator('input[name="email"]').fill('jane@example.com');
|
|
21
|
+
await page.locator('input#remember').setChecked(true, { force: true });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install --save-dev rrweb-browser-test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Works in Node 18+ and ships ESM, CommonJS and TypeScript types.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { generateBrowserTests, TestFramework } from 'rrweb-browser-test';
|
|
36
|
+
|
|
37
|
+
const events = await loadRecording(); // the rrweb events array
|
|
38
|
+
|
|
39
|
+
const code = generateBrowserTests(events, {
|
|
40
|
+
framework: TestFramework.PLAYWRIGHT,
|
|
41
|
+
});
|
|
42
|
+
// write `code` to tests/recorded.spec.ts
|
|
33
43
|
```
|
|
44
|
+
|
|
45
|
+
`generateBrowserTests` returns the test file as a string. Without options it
|
|
46
|
+
generates Playwright.
|
|
47
|
+
|
|
48
|
+
Try it on the bundled sample recording:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm run build
|
|
52
|
+
node example/generate.mjs # Playwright
|
|
53
|
+
node example/generate.mjs example/events.json cypress
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Frameworks
|
|
57
|
+
|
|
58
|
+
| `framework` | Target | Output |
|
|
59
|
+
| ------------ | ---------------------- | --------------------------- |
|
|
60
|
+
| `playwright` | Browser | `@playwright/test` spec |
|
|
61
|
+
| `cypress` | Browser | Cypress spec |
|
|
62
|
+
| `puppeteer` | Browser | Jest + Puppeteer |
|
|
63
|
+
| `selenium` | Browser | Jest + `selenium-webdriver` |
|
|
64
|
+
| `appium` | Android / iOS (native) | WebdriverIO + Appium |
|
|
65
|
+
| `espresso` | Android (native) | Espresso (Kotlin) |
|
|
66
|
+
| `xcuitest` | iOS (native) | XCUITest (Swift) |
|
|
67
|
+
| `detox` | React Native | Detox |
|
|
68
|
+
|
|
69
|
+
`MOBILE_FRAMEWORKS` lists the native ones, if you need to tell them apart.
|
|
70
|
+
|
|
71
|
+
### Input formats
|
|
72
|
+
|
|
73
|
+
`events` can be any of:
|
|
74
|
+
|
|
75
|
+
- rrweb `eventWithTime` objects, as emitted by `rrweb.record()`
|
|
76
|
+
- JSON strings of those events
|
|
77
|
+
- stored rows with stringified fields, such as
|
|
78
|
+
`{ "type": "3", "timestamp": "1700000000000", "data": "{\"source\":2,…}" }`
|
|
79
|
+
|
|
80
|
+
Events are sorted by timestamp, so the order of the input doesn't matter.
|
|
81
|
+
|
|
82
|
+
## How it works
|
|
83
|
+
|
|
84
|
+
1. **Replays the DOM.** rrweb identifies elements by numeric ids that restart
|
|
85
|
+
on every page load and change with every DOM mutation. The generator
|
|
86
|
+
replays each full snapshot and mutation in order, so every click, input or
|
|
87
|
+
scroll is resolved against the page as it was at that moment.
|
|
88
|
+
2. **Finds the element the user meant.** A click on an icon or a `<span>`
|
|
89
|
+
inside a button targets the button (or the nearest link, input, label,
|
|
90
|
+
`role="button"` element, or element with a test id).
|
|
91
|
+
3. **Builds a selector that is unique at that moment,** in this order:
|
|
92
|
+
1. `data-testid` / `data-test` / `data-cy` / `data-qa`
|
|
93
|
+
2. `id`, unless it looks generated (`:r1:`, `rc_…`, uuids)
|
|
94
|
+
3. `name`, `placeholder`, `aria-label`, `title`, `alt`, or `href` for links
|
|
95
|
+
4. tag plus stable classes, ignoring hashed and state classes such as
|
|
96
|
+
`css-1x2y3z`, `active` or `is-open`
|
|
97
|
+
5. the element's text (`hasText` in Playwright, `cy.contains` in Cypress)
|
|
98
|
+
6. a unique ancestor plus the element, then an `:nth-of-type` path
|
|
99
|
+
4. **Keeps only what the user did.** rrweb also records value changes made by
|
|
100
|
+
page scripts. Input events count only on elements the user focused or
|
|
101
|
+
clicked (or that rrweb marks `userTriggered`). Keystrokes collapse into a
|
|
102
|
+
single fill, and scroll ticks into the final position.
|
|
103
|
+
|
|
104
|
+
### Masked inputs
|
|
105
|
+
|
|
106
|
+
When rrweb masks an input (`maskAllInputs`, password fields), the recording
|
|
107
|
+
holds `********` instead of the value. The generator writes a placeholder and
|
|
108
|
+
a TODO instead of typing asterisks:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// TODO: this value was masked in the recording — replace with test data
|
|
112
|
+
await page.locator('input[name="password"]').fill('TODO_MASKED_VALUE');
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Tips for stable tests
|
|
116
|
+
|
|
117
|
+
- Add `data-testid` attributes to the elements users interact with. They
|
|
118
|
+
always win.
|
|
119
|
+
- Generated tests are a starting point. Rename the test, replace masked
|
|
120
|
+
values, and add assertions for what the journey should prove.
|
|
121
|
+
- Mouse moves are kept so hover menus work. Delete them if your flow doesn't
|
|
122
|
+
need them.
|
|
123
|
+
|
|
124
|
+
## Contributing
|
|
125
|
+
|
|
126
|
+
Contributions are welcome! Read [CONTRIBUTING.md](CONTRIBUTING.md) for setup,
|
|
127
|
+
the project layout and how to add a framework. Please follow the
|
|
128
|
+
[Code of Conduct](CODE_OF_CONDUCT.md).
|
|
129
|
+
|
|
130
|
+
Found a security issue? See [SECURITY.md](SECURITY.md).
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
[MIT](LICENSE) © Archish Thakkar
|