rrweb-browser-test 2.0.0 → 2.1.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/CHANGELOG.md +12 -0
- package/README.md +32 -0
- package/dist/index.cjs +403 -6071
- package/dist/index.d.cts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +389 -6071
- package/example/index.js +18 -0
- package/package.json +1 -1
- package/src/core.ts +12 -3
- package/src/cypress/index.ts +123 -0
- package/src/index.ts +2 -5
- package/src/playwright/index.ts +9 -3
- package/src/puppeteer/index.ts +130 -0
- package/src/selenium/index.ts +127 -0
- package/src/types.ts +5 -0
package/example/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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/package.json
CHANGED
package/src/core.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import type { eventWithTime } from '@rrweb/types';
|
|
2
|
+
import { generateCypressTests } from './cypress';
|
|
2
3
|
import { generatePlaywrightTests } from './playwright';
|
|
3
|
-
import {
|
|
4
|
+
import { generatePuppeteerTests } from './puppeteer';
|
|
5
|
+
import { generateSeleniumTests } from './selenium';
|
|
6
|
+
import { TestFramework, type BrowserTests, type TestOptions } from './types';
|
|
4
7
|
|
|
5
8
|
const generateTests = (
|
|
6
9
|
events: Array<eventWithTime | string>,
|
|
7
10
|
options?: TestOptions,
|
|
8
|
-
):
|
|
11
|
+
): BrowserTests => {
|
|
9
12
|
switch (options?.framework) {
|
|
10
13
|
case TestFramework.PLAYWRIGHT:
|
|
11
14
|
return generatePlaywrightTests(events);
|
|
15
|
+
case TestFramework.CYPRESS:
|
|
16
|
+
return generateCypressTests(events);
|
|
17
|
+
case TestFramework.SELENIUM:
|
|
18
|
+
return generateSeleniumTests(events);
|
|
19
|
+
case TestFramework.PUPPETEER:
|
|
20
|
+
return generatePuppeteerTests(events);
|
|
12
21
|
default:
|
|
13
22
|
return generatePlaywrightTests(events);
|
|
14
23
|
}
|
|
@@ -17,6 +26,6 @@ const generateTests = (
|
|
|
17
26
|
export const generateBrowserTests = (
|
|
18
27
|
events: Array<eventWithTime | string>,
|
|
19
28
|
options?: TestOptions,
|
|
20
|
-
):
|
|
29
|
+
): BrowserTests => {
|
|
21
30
|
return generateTests(events, options);
|
|
22
31
|
};
|
|
@@ -0,0 +1,123 @@
|
|
|
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 type { BrowserTests } from '../types';
|
|
15
|
+
import { buildNodeMapFromFullSnapshots, indent } from '../utils';
|
|
16
|
+
|
|
17
|
+
export const generateCypressTests = (
|
|
18
|
+
events: Array<eventWithTime | string>,
|
|
19
|
+
): BrowserTests => {
|
|
20
|
+
let code = '';
|
|
21
|
+
|
|
22
|
+
code += `describe('Generated Cypress Test from rrweb events', () => {\n`;
|
|
23
|
+
code += ` it('should replay events accurately', () => {\n`;
|
|
24
|
+
|
|
25
|
+
const fullSnapshotEvents = events.filter(
|
|
26
|
+
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
27
|
+
) as fullSnapshotEvent[];
|
|
28
|
+
const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
|
|
29
|
+
|
|
30
|
+
events.forEach((event: eventWithTime | string) => {
|
|
31
|
+
const e = event as eventWithTime;
|
|
32
|
+
switch (e.type) {
|
|
33
|
+
case EventType.Meta:
|
|
34
|
+
if (e.data.href) {
|
|
35
|
+
code += `${indent(3)}cy.visit('${e.data.href}');\n`;
|
|
36
|
+
code += `${indent(3)}cy.url().should('include', '${e.data.href}');\n`; // Assert URL after navigation
|
|
37
|
+
}
|
|
38
|
+
if (e.data.width && e.data.height) {
|
|
39
|
+
code += `${indent(3)}cy.viewport(${e.data.width}, ${e.data.height});\n`;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
case EventType.IncrementalSnapshot:
|
|
44
|
+
const data = e.data;
|
|
45
|
+
const type = data.source;
|
|
46
|
+
let d;
|
|
47
|
+
switch (type) {
|
|
48
|
+
case IncrementalSource.MouseMove || 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.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}.${clickNode?.attributes?.class}`;
|
|
71
|
+
if (clickNode?.tagName === 'nav') {
|
|
72
|
+
code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();\n`;
|
|
73
|
+
} else {
|
|
74
|
+
code += `${indent(3)}cy.get('${id}').click();\n`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case IncrementalSource.Scroll:
|
|
80
|
+
d = data as scrollData;
|
|
81
|
+
if (d.x && d.y) {
|
|
82
|
+
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').scrollTo(${d.x}, ${d.y});\n`;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case IncrementalSource.ViewportResize:
|
|
87
|
+
d = data as viewportResizeData;
|
|
88
|
+
if (d.width && d.height) {
|
|
89
|
+
code += `${indent(3)}cy.viewport(${d.width}, ${d.height});\n`;
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
|
|
93
|
+
case IncrementalSource.Input:
|
|
94
|
+
d = data as inputData;
|
|
95
|
+
if (d.text) {
|
|
96
|
+
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').type('${d.text}');\n`;
|
|
97
|
+
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').should('have.value', '${d.text}');\n`; // Assert input value
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
|
|
101
|
+
case IncrementalSource.MediaInteraction:
|
|
102
|
+
d = data as mediaInteractionData;
|
|
103
|
+
if (d.type) {
|
|
104
|
+
code += `${indent(3)}cy.get('[data-id="${nodeMap.get(d.id)?.attributes?.id}"]').then((el) => el[0].${d.type}());\n`;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
default:
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
code += ` });\n`;
|
|
116
|
+
code += `});\n`;
|
|
117
|
+
|
|
118
|
+
const browserTests: BrowserTests = {
|
|
119
|
+
toCode: () => code,
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
return browserTests;
|
|
123
|
+
};
|
package/src/index.ts
CHANGED
package/src/playwright/index.ts
CHANGED
|
@@ -8,15 +8,15 @@ import {
|
|
|
8
8
|
type mediaInteractionData,
|
|
9
9
|
type mouseInteractionData,
|
|
10
10
|
type mousemoveData,
|
|
11
|
-
type mutationData,
|
|
12
11
|
type scrollData,
|
|
13
12
|
type viewportResizeData,
|
|
14
13
|
} from '@rrweb/types';
|
|
14
|
+
import type { BrowserTests } from '../types';
|
|
15
15
|
import { buildNodeMapFromFullSnapshots, indent } from '../utils';
|
|
16
16
|
|
|
17
17
|
export const generatePlaywrightTests = (
|
|
18
18
|
events: Array<eventWithTime | string>,
|
|
19
|
-
):
|
|
19
|
+
): BrowserTests => {
|
|
20
20
|
let code = '';
|
|
21
21
|
|
|
22
22
|
code += `import { test, expect } from '@playwright/test';\n\n`;
|
|
@@ -121,5 +121,11 @@ export const generatePlaywrightTests = (
|
|
|
121
121
|
|
|
122
122
|
code += `${indent(1)}});\n`;
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
const browserTests: BrowserTests = {
|
|
125
|
+
toCode: () => {
|
|
126
|
+
return code;
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return browserTests;
|
|
125
131
|
};
|
|
@@ -0,0 +1,130 @@
|
|
|
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, indent } from '../utils';
|
|
15
|
+
import type { BrowserTests } from '../types';
|
|
16
|
+
|
|
17
|
+
export const generatePuppeteerTests = (
|
|
18
|
+
events: Array<eventWithTime | string>,
|
|
19
|
+
): BrowserTests => {
|
|
20
|
+
let code = '';
|
|
21
|
+
|
|
22
|
+
code += `const puppeteer = require('puppeteer');\n\n`;
|
|
23
|
+
code += `describe('Generated Puppeteer Test from rrweb events', () => {\n`;
|
|
24
|
+
code += `${indent(1)}let browser, page;\n\n`;
|
|
25
|
+
code += `${indent(1)}beforeAll(async () => {\n`;
|
|
26
|
+
code += `${indent(2)}browser = await puppeteer.launch();\n`;
|
|
27
|
+
code += `${indent(2)}page = await browser.newPage();\n`;
|
|
28
|
+
code += `${indent(1)}});\n\n`;
|
|
29
|
+
code += `${indent(1)}afterAll(async () => {\n`;
|
|
30
|
+
code += `${indent(2)}await browser.close();\n`;
|
|
31
|
+
code += `${indent(1)}});\n\n`;
|
|
32
|
+
|
|
33
|
+
code += `${indent(1)}test('Replay rrweb events', async () => {\n`;
|
|
34
|
+
|
|
35
|
+
const fullSnapshotEvents = events.filter(
|
|
36
|
+
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
37
|
+
) as fullSnapshotEvent[];
|
|
38
|
+
const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
|
|
39
|
+
|
|
40
|
+
events.forEach((event: eventWithTime | string) => {
|
|
41
|
+
const e = event as eventWithTime;
|
|
42
|
+
switch (e.type) {
|
|
43
|
+
case EventType.Meta:
|
|
44
|
+
if (e.data.href) {
|
|
45
|
+
code += `${indent(2)}await page.goto('${e.data.href}');\n`;
|
|
46
|
+
code += `${indent(2)}await expect(page.url()).toBe('${e.data.href}');\n`;
|
|
47
|
+
}
|
|
48
|
+
if (e.data.width && e.data.height) {
|
|
49
|
+
code += `${indent(2)}await page.setViewport({ width: ${e.data.width}, height: ${e.data.height} });\n`;
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case EventType.IncrementalSnapshot:
|
|
54
|
+
const data = e.data;
|
|
55
|
+
const type = data.source;
|
|
56
|
+
let d;
|
|
57
|
+
switch (type) {
|
|
58
|
+
case IncrementalSource.MouseMove || IncrementalSource.TouchMove:
|
|
59
|
+
d = data as mousemoveData;
|
|
60
|
+
if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
|
|
61
|
+
code += `${indent(2)}await page.mouse.move(${d.positions[0].x}, ${d.positions[0].y});\n`;
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
|
|
65
|
+
case IncrementalSource.MouseInteraction:
|
|
66
|
+
d = data as mouseInteractionData;
|
|
67
|
+
if (d.type === MouseInteractions.Click) {
|
|
68
|
+
const clickNode = nodeMap.get(d.id);
|
|
69
|
+
const selector = clickNode?.attributes?.id
|
|
70
|
+
? `#${clickNode?.attributes?.id}`
|
|
71
|
+
: clickNode?.attributes?.class
|
|
72
|
+
? `.${clickNode?.attributes?.class}`
|
|
73
|
+
: `${clickNode?.tagName}`;
|
|
74
|
+
code += `${indent(2)}await page.click('${selector}');\n`;
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case IncrementalSource.Scroll:
|
|
79
|
+
d = data as scrollData;
|
|
80
|
+
if (d.x && d.y) {
|
|
81
|
+
const elementId = nodeMap.get(d.id)?.attributes?.id || '';
|
|
82
|
+
code += `${indent(2)}await page.evaluate(() => {\n`;
|
|
83
|
+
code += `${indent(3)}document.querySelector('#${elementId}').scrollTo(${d.x}, ${d.y});\n`;
|
|
84
|
+
code += `${indent(2)}});\n`;
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case IncrementalSource.ViewportResize:
|
|
89
|
+
d = data as viewportResizeData;
|
|
90
|
+
if (d.width && d.height) {
|
|
91
|
+
code += `${indent(2)}await page.setViewport({ width: ${d.width}, height: ${d.height} });\n`;
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case IncrementalSource.Input:
|
|
96
|
+
d = data as inputData;
|
|
97
|
+
if (d.text) {
|
|
98
|
+
const elementId = nodeMap.get(d.id)?.attributes?.id || '';
|
|
99
|
+
code += `${indent(2)}await page.type('#${elementId}', '${d.text}');\n`;
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case IncrementalSource.MediaInteraction:
|
|
104
|
+
d = data as mediaInteractionData;
|
|
105
|
+
if (d.type) {
|
|
106
|
+
const elementId = nodeMap.get(d.id)?.attributes?.id || '';
|
|
107
|
+
code += `${indent(2)}await page.evaluate(() => {\n`;
|
|
108
|
+
code += `${indent(3)}document.querySelector('#${elementId}').${d.type}();\n`;
|
|
109
|
+
code += `${indent(2)}});\n`;
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
default:
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
code += `${indent(1)}});\n`;
|
|
121
|
+
code += `});\n`;
|
|
122
|
+
|
|
123
|
+
const browserTests: BrowserTests = {
|
|
124
|
+
toCode: () => {
|
|
125
|
+
return code;
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return browserTests;
|
|
130
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
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, indent } from '../utils';
|
|
15
|
+
import type { BrowserTests } from '../types';
|
|
16
|
+
|
|
17
|
+
export const generateSeleniumTests = (
|
|
18
|
+
events: Array<eventWithTime | string>,
|
|
19
|
+
): BrowserTests => {
|
|
20
|
+
let code = '';
|
|
21
|
+
|
|
22
|
+
code += `const { Builder, By, until } = require('selenium-webdriver');\n\n`;
|
|
23
|
+
code += `describe('Generated Selenium Test from rrweb events', () => {\n`;
|
|
24
|
+
code += `${indent(1)}let driver;\n\n`;
|
|
25
|
+
code += `${indent(1)}beforeAll(async () => {\n`;
|
|
26
|
+
code += `${indent(2)}driver = await new Builder().forBrowser('chrome').build();\n`;
|
|
27
|
+
code += `${indent(1)}});\n\n`;
|
|
28
|
+
code += `${indent(1)}afterAll(async () => {\n`;
|
|
29
|
+
code += `${indent(2)}await driver.quit();\n`;
|
|
30
|
+
code += `${indent(1)}});\n\n`;
|
|
31
|
+
|
|
32
|
+
code += `${indent(1)}test('Replay rrweb events', async () => {\n`;
|
|
33
|
+
|
|
34
|
+
const fullSnapshotEvents = events.filter(
|
|
35
|
+
(event) => (event as eventWithTime).type === EventType.FullSnapshot,
|
|
36
|
+
) as fullSnapshotEvent[];
|
|
37
|
+
const nodeMap = buildNodeMapFromFullSnapshots(fullSnapshotEvents);
|
|
38
|
+
|
|
39
|
+
events.forEach((event: eventWithTime | string) => {
|
|
40
|
+
const e = event as eventWithTime;
|
|
41
|
+
switch (e.type) {
|
|
42
|
+
case EventType.Meta:
|
|
43
|
+
if (e.data.href) {
|
|
44
|
+
code += `${indent(2)}await driver.get('${e.data.href}');\n`;
|
|
45
|
+
code += `${indent(2)}await driver.wait(until.urlIs('${e.data.href}'), 5000);\n`; // Assert URL
|
|
46
|
+
}
|
|
47
|
+
if (e.data.width && e.data.height) {
|
|
48
|
+
code += `${indent(2)}await driver.manage().window().setRect({ width: ${e.data.width}, height: ${e.data.height} });\n`;
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
|
|
52
|
+
case EventType.IncrementalSnapshot:
|
|
53
|
+
const data = e.data;
|
|
54
|
+
const type = data.source;
|
|
55
|
+
let d;
|
|
56
|
+
switch (type) {
|
|
57
|
+
case IncrementalSource.MouseMove || IncrementalSource.TouchMove:
|
|
58
|
+
d = data as mousemoveData;
|
|
59
|
+
if (d.positions?.[0]?.x && d.positions?.[0]?.y) {
|
|
60
|
+
code += `${indent(2)}await driver.actions().move({ x: ${d.positions[0].x}, y: ${d.positions[0].y} }).perform();\n`;
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case IncrementalSource.MouseInteraction:
|
|
65
|
+
d = data as mouseInteractionData;
|
|
66
|
+
if (d.type === MouseInteractions.Click) {
|
|
67
|
+
const clickNode = nodeMap.get(d.id);
|
|
68
|
+
const selector = clickNode?.attributes?.id
|
|
69
|
+
? `#${clickNode?.attributes?.id}`
|
|
70
|
+
: clickNode?.attributes?.class
|
|
71
|
+
? `.${clickNode?.attributes?.class}`
|
|
72
|
+
: `${clickNode?.tagName}`;
|
|
73
|
+
code += `${indent(2)}await driver.findElement(By.css('${selector}')).click();\n`;
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case IncrementalSource.Scroll:
|
|
78
|
+
d = data as scrollData;
|
|
79
|
+
if (d.x && d.y) {
|
|
80
|
+
const elementId = nodeMap.get(d.id)?.attributes?.id || '';
|
|
81
|
+
code += `${indent(2)}await driver.executeScript('document.querySelector("[id=${elementId}]").scrollTo(${d.x}, ${d.y});');\n`;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
|
|
85
|
+
case IncrementalSource.ViewportResize:
|
|
86
|
+
d = data as viewportResizeData;
|
|
87
|
+
if (d.width && d.height) {
|
|
88
|
+
code += `${indent(2)}await driver.manage().window().setRect({ width: ${d.width}, height: ${d.height} });\n`;
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case IncrementalSource.Input:
|
|
93
|
+
d = data as inputData;
|
|
94
|
+
if (d.text) {
|
|
95
|
+
const elementId = nodeMap.get(d.id)?.attributes?.id || '';
|
|
96
|
+
code += `${indent(2)}const input = await driver.findElement(By.css('#${elementId}'));\n`;
|
|
97
|
+
code += `${indent(2)}await input.clear();\n`;
|
|
98
|
+
code += `${indent(2)}await input.sendKeys('${d.text}');\n`;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
|
|
102
|
+
case IncrementalSource.MediaInteraction:
|
|
103
|
+
d = data as mediaInteractionData;
|
|
104
|
+
if (d.type) {
|
|
105
|
+
const elementId = nodeMap.get(d.id)?.attributes?.id || '';
|
|
106
|
+
code += `${indent(2)}await driver.executeScript('document.querySelector("[id=${elementId}]").${d.type}();');\n`;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
default:
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
code += `${indent(1)}});\n`;
|
|
118
|
+
code += `});\n`;
|
|
119
|
+
|
|
120
|
+
const browserTests: BrowserTests = {
|
|
121
|
+
toCode: () => {
|
|
122
|
+
return code;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return browserTests;
|
|
127
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,11 @@ 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
|
+
|
|
5
10
|
export type SerializedNodeWithId = {
|
|
6
11
|
id: number;
|
|
7
12
|
tagName?: string;
|