rrweb-browser-test 2.1.0 → 2.1.3
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/CHANGELOG.md +18 -0
- package/dist/index.cjs +39 -41
- package/dist/index.d.cts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +39 -41
- package/events.json +31924 -0
- package/example/index.js +13 -13
- package/package.json +1 -1
- package/src/core.ts +3 -3
- package/src/cypress/index.ts +19 -16
- package/src/playwright/index.ts +13 -13
- package/src/puppeteer/index.ts +26 -16
- package/src/selenium/index.ts +24 -16
- package/src/types.ts +0 -5
package/example/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { generateBrowserTests, TestFramework } from '../dist/index.cjs';
|
|
2
|
-
import events from 'events.json' with { type: 'json' };
|
|
2
|
+
import events from '../events.json' with { type: 'json' };
|
|
3
3
|
|
|
4
|
-
console.log(generateBrowserTests(events)
|
|
4
|
+
// console.log(generateBrowserTests(events));
|
|
5
5
|
console.log(
|
|
6
6
|
generateBrowserTests(events, {
|
|
7
|
-
framework: TestFramework.
|
|
8
|
-
})
|
|
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(),
|
|
7
|
+
framework: TestFramework.CYPRESS,
|
|
8
|
+
}),
|
|
18
9
|
);
|
|
10
|
+
// console.log(
|
|
11
|
+
// generateBrowserTests(events, { framework: TestFramework.CYPRESS }),
|
|
12
|
+
// );
|
|
13
|
+
// console.log(
|
|
14
|
+
// generateBrowserTests(events, { framework: TestFramework.SELENIUM }),
|
|
15
|
+
// );
|
|
16
|
+
// console.log(
|
|
17
|
+
// generateBrowserTests(events, { framework: TestFramework.PUPPETEER }),
|
|
18
|
+
// );
|
package/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -3,12 +3,12 @@ import { generateCypressTests } from './cypress';
|
|
|
3
3
|
import { generatePlaywrightTests } from './playwright';
|
|
4
4
|
import { generatePuppeteerTests } from './puppeteer';
|
|
5
5
|
import { generateSeleniumTests } from './selenium';
|
|
6
|
-
import { TestFramework, type
|
|
6
|
+
import { TestFramework, type TestOptions } from './types';
|
|
7
7
|
|
|
8
8
|
const generateTests = (
|
|
9
9
|
events: Array<eventWithTime | string>,
|
|
10
10
|
options?: TestOptions,
|
|
11
|
-
):
|
|
11
|
+
): string => {
|
|
12
12
|
switch (options?.framework) {
|
|
13
13
|
case TestFramework.PLAYWRIGHT:
|
|
14
14
|
return generatePlaywrightTests(events);
|
|
@@ -26,6 +26,6 @@ const generateTests = (
|
|
|
26
26
|
export const generateBrowserTests = (
|
|
27
27
|
events: Array<eventWithTime | string>,
|
|
28
28
|
options?: TestOptions,
|
|
29
|
-
):
|
|
29
|
+
): string => {
|
|
30
30
|
return generateTests(events, options);
|
|
31
31
|
};
|
package/src/cypress/index.ts
CHANGED
|
@@ -11,16 +11,15 @@ import {
|
|
|
11
11
|
type scrollData,
|
|
12
12
|
type viewportResizeData,
|
|
13
13
|
} from '@rrweb/types';
|
|
14
|
-
import type { BrowserTests } from '../types';
|
|
15
14
|
import { buildNodeMapFromFullSnapshots, indent } from '../utils';
|
|
16
15
|
|
|
17
16
|
export const generateCypressTests = (
|
|
18
17
|
events: Array<eventWithTime | string>,
|
|
19
|
-
):
|
|
18
|
+
): string => {
|
|
20
19
|
let code = '';
|
|
21
20
|
|
|
22
|
-
code += `describe('
|
|
23
|
-
code += ` it('
|
|
21
|
+
code += `describe('TODO: name the test block', () => {\n`;
|
|
22
|
+
code += ` it('TODO: name the test case', () => {\n`;
|
|
24
23
|
|
|
25
24
|
const fullSnapshotEvents = events.filter(
|
|
26
25
|
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
@@ -59,19 +58,27 @@ export const generateCypressTests = (
|
|
|
59
58
|
const id = clickNode?.attributes?.id
|
|
60
59
|
? `#${clickNode?.attributes?.id}`
|
|
61
60
|
: clickNode?.tagName === 'nav'
|
|
62
|
-
?
|
|
61
|
+
? `${clickNode?.tagName}:text-is("${clickNode.childNodes
|
|
63
62
|
?.filter((f) => f.tagName === 'a')
|
|
64
63
|
?.map((node) =>
|
|
65
64
|
node.childNodes?.map(
|
|
66
65
|
(n1) => (n1 as any)?.['textContent'],
|
|
67
66
|
),
|
|
68
67
|
)
|
|
69
|
-
.join(' ')}"`
|
|
70
|
-
:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
.join(' ')}")`
|
|
69
|
+
: clickNode?.tagName === 'a'
|
|
70
|
+
? `${clickNode?.tagName}:has-text("${clickNode.childNodes
|
|
71
|
+
?.map((node) => (node as any)?.['textContent'])
|
|
72
|
+
.join(' ')}")`
|
|
73
|
+
: clickNode !== undefined
|
|
74
|
+
? `${clickNode?.tagName}.${clickNode?.attributes?.class}`
|
|
75
|
+
: undefined;
|
|
76
|
+
if (id) {
|
|
77
|
+
if (clickNode?.tagName === 'nav') {
|
|
78
|
+
code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();\n`;
|
|
79
|
+
} else {
|
|
80
|
+
code += `${indent(3)}cy.get('${id}').click();\n`;
|
|
81
|
+
}
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
break;
|
|
@@ -115,9 +122,5 @@ export const generateCypressTests = (
|
|
|
115
122
|
code += ` });\n`;
|
|
116
123
|
code += `});\n`;
|
|
117
124
|
|
|
118
|
-
|
|
119
|
-
toCode: () => code,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return browserTests;
|
|
125
|
+
return code;
|
|
123
126
|
};
|
package/src/playwright/index.ts
CHANGED
|
@@ -11,16 +11,15 @@ import {
|
|
|
11
11
|
type scrollData,
|
|
12
12
|
type viewportResizeData,
|
|
13
13
|
} from '@rrweb/types';
|
|
14
|
-
import type { BrowserTests } from '../types';
|
|
15
14
|
import { buildNodeMapFromFullSnapshots, indent } from '../utils';
|
|
16
15
|
|
|
17
16
|
export const generatePlaywrightTests = (
|
|
18
17
|
events: Array<eventWithTime | string>,
|
|
19
|
-
):
|
|
18
|
+
): string => {
|
|
20
19
|
let code = '';
|
|
21
20
|
|
|
22
21
|
code += `import { test, expect } from '@playwright/test';\n\n`;
|
|
23
|
-
code += `test('
|
|
22
|
+
code += `test('TODO: name the test block', async ({ page, context }) => {\n`;
|
|
24
23
|
|
|
25
24
|
const fullSnapshotEvents = events.filter(
|
|
26
25
|
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
@@ -59,6 +58,7 @@ export const generatePlaywrightTests = (
|
|
|
59
58
|
d = data as mouseInteractionData;
|
|
60
59
|
if (d.type === MouseInteractions.Click) {
|
|
61
60
|
const clickNode = nodeMap.get(d.id);
|
|
61
|
+
console.log(clickNode);
|
|
62
62
|
const id = clickNode?.attributes?.id
|
|
63
63
|
? `#${clickNode?.attributes?.id}`
|
|
64
64
|
: clickNode?.tagName === 'nav'
|
|
@@ -70,9 +70,15 @@ export const generatePlaywrightTests = (
|
|
|
70
70
|
),
|
|
71
71
|
)
|
|
72
72
|
.join(' ')}")`
|
|
73
|
-
:
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
: clickNode?.tagName === 'a'
|
|
74
|
+
? `${clickNode?.tagName}:has-text("${clickNode.childNodes
|
|
75
|
+
?.map((node) => (node as any)?.['textContent'])
|
|
76
|
+
.join(' ')}")`
|
|
77
|
+
: clickNode !== undefined
|
|
78
|
+
? `${clickNode?.tagName}.${clickNode?.attributes?.class}`
|
|
79
|
+
: undefined;
|
|
80
|
+
|
|
81
|
+
if (id && d.x && d.y) {
|
|
76
82
|
code += `${indent(2)}await page.locator(\`${id}\`).click();\n`;
|
|
77
83
|
code += `${indent(2)}await expect(page.locator(\`${id}\`)).toBeVisible();\n`; // Assert visibility after click
|
|
78
84
|
}
|
|
@@ -121,11 +127,5 @@ export const generatePlaywrightTests = (
|
|
|
121
127
|
|
|
122
128
|
code += `${indent(1)}});\n`;
|
|
123
129
|
|
|
124
|
-
|
|
125
|
-
toCode: () => {
|
|
126
|
-
return code;
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
return browserTests;
|
|
130
|
+
return code;
|
|
131
131
|
};
|
package/src/puppeteer/index.ts
CHANGED
|
@@ -12,15 +12,14 @@ import {
|
|
|
12
12
|
type viewportResizeData,
|
|
13
13
|
} from '@rrweb/types';
|
|
14
14
|
import { buildNodeMapFromFullSnapshots, indent } from '../utils';
|
|
15
|
-
import type { BrowserTests } from '../types';
|
|
16
15
|
|
|
17
16
|
export const generatePuppeteerTests = (
|
|
18
17
|
events: Array<eventWithTime | string>,
|
|
19
|
-
):
|
|
18
|
+
): string => {
|
|
20
19
|
let code = '';
|
|
21
20
|
|
|
22
21
|
code += `const puppeteer = require('puppeteer');\n\n`;
|
|
23
|
-
code += `describe('
|
|
22
|
+
code += `describe('TODO: name the test block', () => {\n`;
|
|
24
23
|
code += `${indent(1)}let browser, page;\n\n`;
|
|
25
24
|
code += `${indent(1)}beforeAll(async () => {\n`;
|
|
26
25
|
code += `${indent(2)}browser = await puppeteer.launch();\n`;
|
|
@@ -30,7 +29,7 @@ export const generatePuppeteerTests = (
|
|
|
30
29
|
code += `${indent(2)}await browser.close();\n`;
|
|
31
30
|
code += `${indent(1)}});\n\n`;
|
|
32
31
|
|
|
33
|
-
code += `${indent(1)}test('
|
|
32
|
+
code += `${indent(1)}test('TODO: name the test case', async () => {\n`;
|
|
34
33
|
|
|
35
34
|
const fullSnapshotEvents = events.filter(
|
|
36
35
|
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
@@ -66,12 +65,29 @@ export const generatePuppeteerTests = (
|
|
|
66
65
|
d = data as mouseInteractionData;
|
|
67
66
|
if (d.type === MouseInteractions.Click) {
|
|
68
67
|
const clickNode = nodeMap.get(d.id);
|
|
69
|
-
|
|
68
|
+
console.log(clickNode);
|
|
69
|
+
const id = clickNode?.attributes?.id
|
|
70
70
|
? `#${clickNode?.attributes?.id}`
|
|
71
|
-
: clickNode?.
|
|
72
|
-
?
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
: clickNode?.tagName === 'nav'
|
|
72
|
+
? `${clickNode?.tagName}:text-is("${clickNode.childNodes
|
|
73
|
+
?.filter((f) => f.tagName === 'a')
|
|
74
|
+
?.map((node) =>
|
|
75
|
+
node.childNodes?.map(
|
|
76
|
+
(n1) => (n1 as any)?.['textContent'],
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
.join(' ')}")`
|
|
80
|
+
: clickNode?.tagName === 'a'
|
|
81
|
+
? `${clickNode?.tagName}:has-text("${clickNode.childNodes
|
|
82
|
+
?.map((node) => (node as any)?.['textContent'])
|
|
83
|
+
.join(' ')}")`
|
|
84
|
+
: clickNode !== undefined
|
|
85
|
+
? `${clickNode?.tagName}.${clickNode?.attributes?.class}`
|
|
86
|
+
: undefined;
|
|
87
|
+
|
|
88
|
+
if (id) {
|
|
89
|
+
code += `${indent(2)}await page.click('${id}');\n`;
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
92
|
break;
|
|
77
93
|
|
|
@@ -120,11 +136,5 @@ export const generatePuppeteerTests = (
|
|
|
120
136
|
code += `${indent(1)}});\n`;
|
|
121
137
|
code += `});\n`;
|
|
122
138
|
|
|
123
|
-
|
|
124
|
-
toCode: () => {
|
|
125
|
-
return code;
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
return browserTests;
|
|
139
|
+
return code;
|
|
130
140
|
};
|
package/src/selenium/index.ts
CHANGED
|
@@ -12,15 +12,14 @@ import {
|
|
|
12
12
|
type viewportResizeData,
|
|
13
13
|
} from '@rrweb/types';
|
|
14
14
|
import { buildNodeMapFromFullSnapshots, indent } from '../utils';
|
|
15
|
-
import type { BrowserTests } from '../types';
|
|
16
15
|
|
|
17
16
|
export const generateSeleniumTests = (
|
|
18
17
|
events: Array<eventWithTime | string>,
|
|
19
|
-
):
|
|
18
|
+
): string => {
|
|
20
19
|
let code = '';
|
|
21
20
|
|
|
22
21
|
code += `const { Builder, By, until } = require('selenium-webdriver');\n\n`;
|
|
23
|
-
code += `describe('
|
|
22
|
+
code += `describe('TODO: name the test block', () => {\n`;
|
|
24
23
|
code += `${indent(1)}let driver;\n\n`;
|
|
25
24
|
code += `${indent(1)}beforeAll(async () => {\n`;
|
|
26
25
|
code += `${indent(2)}driver = await new Builder().forBrowser('chrome').build();\n`;
|
|
@@ -29,7 +28,7 @@ export const generateSeleniumTests = (
|
|
|
29
28
|
code += `${indent(2)}await driver.quit();\n`;
|
|
30
29
|
code += `${indent(1)}});\n\n`;
|
|
31
30
|
|
|
32
|
-
code += `${indent(1)}test('
|
|
31
|
+
code += `${indent(1)}test('TODO: name the test case', async () => {\n`;
|
|
33
32
|
|
|
34
33
|
const fullSnapshotEvents = events.filter(
|
|
35
34
|
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
@@ -65,12 +64,27 @@ export const generateSeleniumTests = (
|
|
|
65
64
|
d = data as mouseInteractionData;
|
|
66
65
|
if (d.type === MouseInteractions.Click) {
|
|
67
66
|
const clickNode = nodeMap.get(d.id);
|
|
68
|
-
const
|
|
67
|
+
const id = clickNode?.attributes?.id
|
|
69
68
|
? `#${clickNode?.attributes?.id}`
|
|
70
|
-
: clickNode?.
|
|
71
|
-
?
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
: clickNode?.tagName === 'nav'
|
|
70
|
+
? `${clickNode?.tagName}:text-is("${clickNode.childNodes
|
|
71
|
+
?.filter((f) => f.tagName === 'a')
|
|
72
|
+
?.map((node) =>
|
|
73
|
+
node.childNodes?.map(
|
|
74
|
+
(n1) => (n1 as any)?.['textContent'],
|
|
75
|
+
),
|
|
76
|
+
)
|
|
77
|
+
.join(' ')}")`
|
|
78
|
+
: clickNode?.tagName === 'a'
|
|
79
|
+
? `${clickNode?.tagName}:has-text("${clickNode.childNodes
|
|
80
|
+
?.map((node) => (node as any)?.['textContent'])
|
|
81
|
+
.join(' ')}")`
|
|
82
|
+
: clickNode !== undefined
|
|
83
|
+
? `${clickNode?.tagName}.${clickNode?.attributes?.class}`
|
|
84
|
+
: undefined;
|
|
85
|
+
if (id) {
|
|
86
|
+
code += `${indent(2)}await driver.findElement(By.css('${id}')).click();\n`;
|
|
87
|
+
}
|
|
74
88
|
}
|
|
75
89
|
break;
|
|
76
90
|
|
|
@@ -117,11 +131,5 @@ export const generateSeleniumTests = (
|
|
|
117
131
|
code += `${indent(1)}});\n`;
|
|
118
132
|
code += `});\n`;
|
|
119
133
|
|
|
120
|
-
|
|
121
|
-
toCode: () => {
|
|
122
|
-
return code;
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return browserTests;
|
|
134
|
+
return code;
|
|
127
135
|
};
|
package/src/types.ts
CHANGED
|
@@ -2,11 +2,6 @@ export type TestOptions = {
|
|
|
2
2
|
framework: 'playwright' | 'puppeteer' | 'cypress' | 'selenium';
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
export type BrowserTests = {
|
|
6
|
-
toCode: () => string;
|
|
7
|
-
toMap?: () => Map<number, string>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
5
|
export type SerializedNodeWithId = {
|
|
11
6
|
id: number;
|
|
12
7
|
tagName?: string;
|