@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,185 @@
1
+ class DOM_Parent {
2
+
3
+ getActualParent(element) {
4
+ if (!element || !(element instanceof Element)) {
5
+ throw new Error('Invalid element provided');
6
+ }
7
+
8
+ // TODO: account for slotted elements
9
+
10
+ if (element.assignedSlot) {
11
+ return element.assignedSlot
12
+ }
13
+ // Get the actual parent element, skipping shadow DOM if necessary
14
+ let parent = element.parentElement;
15
+ if (parent) {
16
+ return parent;
17
+ }
18
+ const parentNode = element.parentNode;
19
+ if (parentNode && parentNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
20
+ // If the parent is a shadow root, return its host
21
+ return parentNode.host || null;
22
+ }
23
+ return null;
24
+
25
+ }
26
+
27
+ getFullAncestorChain(element) {
28
+ if (!element || !(element instanceof Element)) {
29
+ throw new Error('Invalid element provided');
30
+ }
31
+
32
+ const ancestors = [];
33
+ let currentElement = element;
34
+
35
+ while (currentElement) {
36
+ ancestors.push(currentElement);
37
+ currentElement = this.getActualParent(currentElement);
38
+ }
39
+
40
+ return ancestors;
41
+ }
42
+ getFullAncestorChainToRoot(element, root) {
43
+ if (!element || !(element instanceof Element)) {
44
+ throw new Error('Invalid element provided');
45
+ }
46
+ if (!root || !(root instanceof Element)) {
47
+ throw new Error('Invalid root provided');
48
+ }
49
+ if (!this.containsElementCrossShadow(root, element)) {
50
+ throw new Error('Root does not contain the element');
51
+ }
52
+ const ancestors = [];
53
+ let currentElement = element;
54
+ while (currentElement && currentElement !== root && this.containsElementCrossShadow(root, currentElement)) {
55
+ ancestors.push(currentElement);
56
+ currentElement = this.getActualParent(currentElement);
57
+
58
+ }
59
+ if (currentElement === root) {
60
+ ancestors.push(currentElement);
61
+ }
62
+ return ancestors;
63
+ }
64
+ getClimbCountToParent(element, targetParent) {
65
+ if (!element || !(element instanceof Element)) {
66
+ throw new Error('Invalid element provided');
67
+ }
68
+ if (!targetParent || !(targetParent instanceof Element)) {
69
+ throw new Error('Invalid target parent provided');
70
+ }
71
+
72
+ let count = 0;
73
+ let currentElement = element;
74
+
75
+ while (currentElement && currentElement !== targetParent) {
76
+ currentElement = this.getActualParent(currentElement);
77
+ count++;
78
+ }
79
+
80
+ return currentElement === targetParent ? count : -1; // Return -1 if target parent is not found
81
+ }
82
+
83
+ containsElementCrossShadow(element, target) {
84
+ if (!element || !(element instanceof Element)) {
85
+ throw new Error('Invalid element provided');
86
+ }
87
+ if (!target || !(target instanceof Element)) {
88
+ throw new Error('Invalid target provided');
89
+ }
90
+
91
+ // Check if the element contains the target, accounting for shadow DOM
92
+ let currentElement = target;
93
+
94
+ while (currentElement) {
95
+ if (currentElement === element) {
96
+ return true;
97
+ }
98
+ currentElement = this.getActualParent(currentElement);
99
+ }
100
+
101
+ return false;
102
+ }
103
+
104
+ findLowestCommonAncestor(elements) {
105
+ if (!Array.isArray(elements) || elements.length === 0) {
106
+ throw new Error('Invalid elements array provided');
107
+ }
108
+
109
+ // Ensure all elements are valid
110
+ for (const el of elements) {
111
+ if (!(el instanceof Element)) {
112
+ throw new Error('All items in the array must be DOM Elements');
113
+ }
114
+ }
115
+
116
+ // Start with the first element's ancestors
117
+ let commonAncestors = this.getFullAncestorChain(elements[0]);
118
+
119
+ commonAncestors.reverse(); // Reverse to start from the closest ancestor
120
+
121
+ // Iterate through the rest of the elements
122
+ for (let i = 1; i < elements.length; i++) {
123
+ const currentAncestors = this.getFullAncestorChain(elements[i]);
124
+ currentAncestors.reverse(); // Reverse to start from the closest ancestor
125
+ commonAncestors = commonAncestors.filter(ancestor =>
126
+ currentAncestors.includes(ancestor)
127
+ );
128
+ }
129
+
130
+ // Return the lowest common ancestor, or null if none found
131
+ return commonAncestors.length > 0 ? commonAncestors[commonAncestors.length - 1] : null;
132
+ }
133
+
134
+ /**
135
+ * Finds the branching parent for a target element within an array of elements
136
+ * The branching parent is the direct child of the common ancestor that contains the target
137
+ * @param {Element[]} elements - Array of elements (target must be included)
138
+ * @param {Element} target - Target element to find branching parent for
139
+
140
+ * @returns {Element|null} - The branching parent element, or null if not found
141
+ */
142
+ findBranchingParent(elements, target) {
143
+ if (!Array.isArray(elements) || elements.length === 0) {
144
+ throw new Error('Invalid elements array provided');
145
+ }
146
+ if (!(target instanceof Element)) {
147
+ throw new Error('Target must be a DOM Element');
148
+ }
149
+
150
+ // Ensure all elements are valid
151
+ for (const el of elements) {
152
+ if (!(el instanceof Element)) {
153
+ throw new Error('All items in the array must be DOM Elements');
154
+ }
155
+ }
156
+ // Check if the target is in the elements array
157
+ if (!elements.includes(target)) {
158
+ // throw new Error("Target element must be included in the elements array");
159
+ console.warn("Target element must be included in the elements array, returning null");
160
+ return null;
161
+ }
162
+ const allTargetparents = this.getFullAncestorChain(target);
163
+
164
+ // reverse the order of parents to start from the closest parent
165
+ allTargetparents.reverse();
166
+
167
+ // Find the parent that only contains the target and no other elements
168
+ let branchingParent = null;
169
+ for (const parent of allTargetparents) {
170
+ /// find all elements that are inside this parent
171
+ const allElementsThatAreInsideParent = elements.filter(el => this.containsElementCrossShadow(parent, el));
172
+ // If the parent contains only the target element, it is the branching parent
173
+ if (allElementsThatAreInsideParent.length === 1 && allElementsThatAreInsideParent[0] === target) {
174
+ branchingParent = parent;
175
+ break;
176
+ }
177
+ }
178
+ if (branchingParent) {
179
+ return branchingParent;
180
+ }
181
+
182
+ return null; // No branching parent found
183
+ }
184
+ }
185
+ export default DOM_Parent;
@@ -0,0 +1,105 @@
1
+ import { __PW } from "./pw";
2
+
3
+ const closestCrossShadow = __PW.domUtils.closestCrossShadow;
4
+ const isElementVisible = __PW.domUtils.isElementVisible;
5
+
6
+ export default class EventUtils {
7
+ deepEventTarget(event) {
8
+ return event.composedPath()[0];
9
+ }
10
+ deepActiveElement(document) {
11
+ let activeElement = document.activeElement;
12
+ while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
13
+ activeElement = activeElement.shadowRoot.activeElement;
14
+ return activeElement;
15
+ }
16
+ modifiersForEvent(event) {
17
+ return (event.altKey ? 1 : 0) | (event.ctrlKey ? 2 : 0) | (event.metaKey ? 4 : 0) | (event.shiftKey ? 8 : 0);
18
+ }
19
+ buttonForEvent(event) {
20
+ switch (event.which) {
21
+ case 1:
22
+ return "left";
23
+ case 2:
24
+ return "middle";
25
+ case 3:
26
+ return "right";
27
+ }
28
+ return "left";
29
+ }
30
+ positionForEvent(event) {
31
+ const targetElement = event.target;
32
+ if (targetElement.nodeName !== "CANVAS") return;
33
+ return {
34
+ x: event.offsetX,
35
+ y: event.offsetY,
36
+ };
37
+ }
38
+ consumeEvent(e) {
39
+ e.preventDefault();
40
+ e.stopPropagation();
41
+ e.stopImmediatePropagation();
42
+ }
43
+ asCheckbox(node) {
44
+ if (!node || node.nodeName !== "INPUT") return null;
45
+ const inputElement = node;
46
+ return ["checkbox", "radio"].includes(inputElement.type) ? inputElement : null;
47
+ }
48
+ isRangeInput(node) {
49
+ if (!node || node.nodeName !== "INPUT") return false;
50
+ const inputElement = node;
51
+ return inputElement.type.toLowerCase() === "range";
52
+ }
53
+ addEventListener(target, eventName, listener, useCapture) {
54
+ target.addEventListener(eventName, listener, useCapture);
55
+ const remove = () => {
56
+ target.removeEventListener(eventName, listener, useCapture);
57
+ };
58
+ return remove;
59
+ }
60
+ removeEventListeners(listeners) {
61
+ for (const listener of listeners) listener();
62
+ listeners.splice(0, listeners.length);
63
+ }
64
+
65
+ getNearestInteractiveElement(targetElement, root = window.document) {
66
+ try {
67
+ if (!targetElement.matches("input,textarea,select") && !targetElement.isContentEditable) {
68
+ const interactiveParent = closestCrossShadow(
69
+ targetElement,
70
+ "button,select,input,[role=button],[role=checkbox],[role=radio],a,[role=link]",
71
+ root
72
+ );
73
+ if (interactiveParent && isElementVisible(interactiveParent)) return interactiveParent;
74
+ }
75
+ return targetElement;
76
+ } catch (e) {
77
+ console.error(e);
78
+ // bvtRecorderBindings.log(`Error in getNearestInteractiveElement: ${e.message}`);
79
+ return targetElement;
80
+ }
81
+ }
82
+ shouldGenerateKeyPressFor(event) {
83
+ // Enter aka. new line is handled in input event.
84
+ if (
85
+ event.key === "Enter" &&
86
+ (this.deepEventTarget(event).nodeName === "TEXTAREA" || this.deepEventTarget(event).isContentEditable)
87
+ )
88
+ return false;
89
+ // Backspace, Delete, AltGraph are changing input, will handle it there.
90
+ if (["Backspace", "Delete", "AltGraph"].includes(event.key)) return false;
91
+ // Ignore the QWERTZ shortcut for creating a at sign on MacOS
92
+ if (event.key === "@" && event.code === "KeyL") return false;
93
+ // Allow and ignore common used shortcut for pasting.
94
+ if (navigator.platform.includes("Mac")) {
95
+ if (event.key === "v" && event.metaKey) return false;
96
+ } else {
97
+ if (event.key === "v" && event.ctrlKey) return false;
98
+ if (event.key === "Insert" && event.shiftKey) return false;
99
+ }
100
+ if (["Shift", "Control", "Meta", "Alt", "Process"].includes(event.key)) return false;
101
+ const hasModifier = event.ctrlKey || event.altKey || event.metaKey;
102
+ if (event.key.length === 1 && !hasModifier) return !!this.asCheckbox(this.deepEventTarget(event));
103
+ return true;
104
+ }
105
+ }