rrweb-browser-test 2.1.1 → 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/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).toCode());
4
+ // console.log(generateBrowserTests(events));
5
5
  console.log(
6
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(),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rrweb-browser-test",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "RRWeb events to generating browser test scripts",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -58,19 +58,27 @@ export const generateCypressTests = (
58
58
  const id = clickNode?.attributes?.id
59
59
  ? `#${clickNode?.attributes?.id}`
60
60
  : clickNode?.tagName === 'nav'
61
- ? `"${clickNode.childNodes
61
+ ? `${clickNode?.tagName}:text-is("${clickNode.childNodes
62
62
  ?.filter((f) => f.tagName === 'a')
63
63
  ?.map((node) =>
64
64
  node.childNodes?.map(
65
65
  (n1) => (n1 as any)?.['textContent'],
66
66
  ),
67
67
  )
68
- .join(' ')}"`
69
- : `${clickNode?.tagName}.${clickNode?.attributes?.class}`;
70
- if (clickNode?.tagName === 'nav') {
71
- code += `${indent(3)}cy.contains('${clickNode?.tagName}', ${id}).click();\n`;
72
- } else {
73
- code += `${indent(3)}cy.get('${id}').click();\n`;
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
+ }
74
82
  }
75
83
  }
76
84
  break;
@@ -58,6 +58,7 @@ export const generatePlaywrightTests = (
58
58
  d = data as mouseInteractionData;
59
59
  if (d.type === MouseInteractions.Click) {
60
60
  const clickNode = nodeMap.get(d.id);
61
+ console.log(clickNode);
61
62
  const id = clickNode?.attributes?.id
62
63
  ? `#${clickNode?.attributes?.id}`
63
64
  : clickNode?.tagName === 'nav'
@@ -69,9 +70,15 @@ export const generatePlaywrightTests = (
69
70
  ),
70
71
  )
71
72
  .join(' ')}")`
72
- : `${clickNode?.tagName}.${clickNode?.attributes?.class}`;
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;
73
80
 
74
- if (d.x && d.y) {
81
+ if (id && d.x && d.y) {
75
82
  code += `${indent(2)}await page.locator(\`${id}\`).click();\n`;
76
83
  code += `${indent(2)}await expect(page.locator(\`${id}\`)).toBeVisible();\n`; // Assert visibility after click
77
84
  }
@@ -65,12 +65,29 @@ export const generatePuppeteerTests = (
65
65
  d = data as mouseInteractionData;
66
66
  if (d.type === MouseInteractions.Click) {
67
67
  const clickNode = nodeMap.get(d.id);
68
- const selector = clickNode?.attributes?.id
68
+ console.log(clickNode);
69
+ const id = clickNode?.attributes?.id
69
70
  ? `#${clickNode?.attributes?.id}`
70
- : clickNode?.attributes?.class
71
- ? `.${clickNode?.attributes?.class}`
72
- : `${clickNode?.tagName}`;
73
- code += `${indent(2)}await page.click('${selector}');\n`;
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
+ }
74
91
  }
75
92
  break;
76
93
 
@@ -64,12 +64,27 @@ export const generateSeleniumTests = (
64
64
  d = data as mouseInteractionData;
65
65
  if (d.type === MouseInteractions.Click) {
66
66
  const clickNode = nodeMap.get(d.id);
67
- const selector = clickNode?.attributes?.id
67
+ const id = clickNode?.attributes?.id
68
68
  ? `#${clickNode?.attributes?.id}`
69
- : clickNode?.attributes?.class
70
- ? `.${clickNode?.attributes?.class}`
71
- : `${clickNode?.tagName}`;
72
- code += `${indent(2)}await driver.findElement(By.css('${selector}')).click();\n`;
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
+ }
73
88
  }
74
89
  break;
75
90