@dev-blinq/cucumber_client 1.0.1237-dev → 1.0.1237-stage

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.
Files changed (40) hide show
  1. package/bin/assets/bundled_scripts/recorder.js +220 -0
  2. package/bin/assets/preload/recorderv3.js +5 -3
  3. package/bin/assets/preload/unique_locators.js +1 -1
  4. package/bin/assets/scripts/aria_snapshot.js +235 -0
  5. package/bin/assets/scripts/dom_attr.js +372 -0
  6. package/bin/assets/scripts/dom_element.js +0 -0
  7. package/bin/assets/scripts/dom_parent.js +185 -0
  8. package/bin/assets/scripts/event_utils.js +105 -0
  9. package/bin/assets/scripts/pw.js +7886 -0
  10. package/bin/assets/scripts/recorder.js +1147 -0
  11. package/bin/assets/scripts/snapshot_capturer.js +155 -0
  12. package/bin/assets/scripts/unique_locators.js +852 -0
  13. package/bin/assets/scripts/yaml.js +4770 -0
  14. package/bin/assets/templates/_hooks_template.txt +37 -0
  15. package/bin/assets/templates/page_template.txt +2 -16
  16. package/bin/assets/templates/utils_template.txt +44 -71
  17. package/bin/client/apiTest/apiTest.js +6 -0
  18. package/bin/client/cli_helpers.js +11 -13
  19. package/bin/client/code_cleanup/utils.js +36 -13
  20. package/bin/client/code_gen/code_inversion.js +68 -10
  21. package/bin/client/code_gen/page_reflection.js +12 -15
  22. package/bin/client/code_gen/playwright_codeget.js +127 -34
  23. package/bin/client/cucumber/feature.js +85 -27
  24. package/bin/client/cucumber/steps_definitions.js +84 -76
  25. package/bin/client/cucumber_selector.js +13 -1
  26. package/bin/client/local_agent.js +3 -3
  27. package/bin/client/project.js +7 -1
  28. package/bin/client/recorderv3/bvt_recorder.js +267 -87
  29. package/bin/client/recorderv3/implemented_steps.js +74 -12
  30. package/bin/client/recorderv3/index.js +58 -8
  31. package/bin/client/recorderv3/network.js +299 -0
  32. package/bin/client/recorderv3/step_runner.js +319 -67
  33. package/bin/client/recorderv3/step_utils.js +152 -5
  34. package/bin/client/recorderv3/update_feature.js +58 -30
  35. package/bin/client/recording.js +5 -0
  36. package/bin/client/run_cucumber.js +5 -1
  37. package/bin/client/scenario_report.js +0 -5
  38. package/bin/client/test_scenario.js +0 -1
  39. package/bin/index.js +1 -0
  40. package/package.json +17 -9
@@ -0,0 +1,155 @@
1
+ class SnapshotCapturer {
2
+ constructor(options = {}) {
3
+ const {
4
+ inlineImages = true,
5
+ inlineStyles = true,
6
+ excludeSelectors = []
7
+ } = options;
8
+ // this.options = {
9
+ // inlineImages,
10
+ // inlineStyles,
11
+ // excludeSelectors
12
+ // };
13
+ this.inlineImages = inlineImages;
14
+ this.inlineStyles = inlineStyles;
15
+ this.excludeSelectors = excludeSelectors;
16
+ }
17
+ imageToDataURL(img, document) {
18
+ try {
19
+ // Create canvas to draw the image
20
+ const canvas = document.createElement('canvas');
21
+ canvas.width = img.naturalWidth || img.width;
22
+ canvas.height = img.naturalHeight || img.height;
23
+ const ctx = canvas.getContext('2d');
24
+
25
+ // Draw image to canvas and convert to data URL
26
+ ctx.drawImage(img, 0, 0);
27
+ return canvas.toDataURL('image/png');
28
+ } catch (error) {
29
+ console.warn(`Failed to inline image: ${img.src}`, error);
30
+ return img.src; // Fall back to original source
31
+ }
32
+ }
33
+ processStyles(document) {
34
+ if (!this.inlineStyles) return;
35
+
36
+ const stylesheets = Array.from(document.styleSheets);
37
+ for (const sheet of stylesheets) {
38
+ try {
39
+ if (!sheet.href) continue; // Skip inline styles
40
+ const styleEl = document.createElement('style');
41
+ let text = ""
42
+ const cssRules = Array.from(sheet.cssRules || []);
43
+ for (const rule of cssRules) {
44
+ if (rule.cssText) {
45
+ text += rule.cssText + '\n';
46
+ }
47
+ }
48
+ styleEl.textContent = text;
49
+
50
+ // Replace the link with our new style element
51
+ if (sheet.ownerNode && sheet.ownerNode.parentNode) {
52
+ sheet.ownerNode.parentNode.replaceChild(styleEl, sheet.ownerNode);
53
+ } else if (sheet.ownerNode) {
54
+ // If the owner node is not in the document, just append it
55
+ document.head.appendChild(styleEl);
56
+ }
57
+
58
+ } catch (error) {
59
+ console.warn(`Error processing stylesheet: ${sheet.href}`, error);
60
+ }
61
+ }
62
+ }
63
+ processImages(document) {
64
+ if (!this.inlineImages) return;
65
+
66
+ const images = document.querySelectorAll('img');
67
+ images.forEach(img => {
68
+ // Skip SVGs and already data URLs
69
+ if (img.src.startsWith('data:') || img.src.endsWith('.svg')) return;
70
+
71
+ // Skip if the image is excluded
72
+ if (this.excludeSelectors.some(selector => img.matches(selector))) return;
73
+
74
+ // Only inline complete images
75
+ if (img.complete && img.naturalWidth !== 0) {
76
+ try {
77
+ img.setAttribute('src', this.imageToDataURL(img, document));
78
+ } catch (e) {
79
+ console.warn(`Failed to process image: ${img.src}`, e);
80
+ }
81
+ }
82
+ });
83
+ }
84
+ removeExcludedElements(document) {
85
+ this.excludeSelectors.forEach(selector => {
86
+ const elements = document.querySelectorAll(selector);
87
+ elements.forEach(el => {
88
+ el.parentNode?.removeChild(el);
89
+ });
90
+ });
91
+ }
92
+ processComputedStyles(document) {
93
+ const elements = document.querySelectorAll('*');
94
+
95
+ elements.forEach(el => {
96
+ // Skip excluded elements
97
+ if (this.excludeSelectors.some(selector => el.matches(selector))) return;
98
+
99
+ // Get computed style
100
+ const style = window.getComputedStyle(el);
101
+
102
+ // Copy important styles to inline style
103
+ const importantStyles = [
104
+ 'display', 'position', 'width', 'height', 'margin', 'padding',
105
+ 'color', 'background-color', 'font-family', 'font-size',
106
+ 'text-align', 'line-height', 'border', 'box-shadow', 'opacity'
107
+ // Add more styles as needed
108
+ ];
109
+
110
+ const inlineStyles = [];
111
+
112
+ importantStyles.forEach(prop => {
113
+ const value = style.getPropertyValue(prop);
114
+ if (value) {
115
+ inlineStyles.push(`${prop}: ${value}`);
116
+ }
117
+ });
118
+
119
+ // Set inline style
120
+ if (inlineStyles.length > 0) {
121
+ const currentStyle = el.getAttribute('style') || '';
122
+ el.setAttribute('style', currentStyle + inlineStyles.join('; ') + ';');
123
+ }
124
+ });
125
+
126
+ }
127
+ createSnapshot() {
128
+ // Clone the document to avoid modifying the original
129
+ const docClone = window.document.cloneNode(true);
130
+
131
+ // Store the original document
132
+ const originalDoc = window.document;
133
+
134
+ // Temporarily "swap" the document for processing
135
+ // (We're just using this as a convention - it doesn't actually replace the global document)
136
+ const doc = docClone;
137
+
138
+ // Process the clone
139
+ this.processStyles(doc);
140
+ this.processImages(doc);
141
+ this.removeExcludedElements(doc);
142
+ this.processComputedStyles(doc);
143
+
144
+ // Generate HTML with doctype
145
+ const doctype = originalDoc.doctype ?
146
+ new XMLSerializer().serializeToString(originalDoc.doctype) : '<!DOCTYPE html>';
147
+
148
+ // Get the HTML content
149
+ const htmlContent = doc.documentElement.outerHTML;
150
+
151
+ // Combine doctype and HTML content
152
+ return `${doctype}${htmlContent}`;
153
+ }
154
+ }
155
+ export default SnapshotCapturer;