playwright-cucumber-ts-steps 0.1.7 → 1.0.1
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/README.md +21 -11
- package/lib/actions/clickSteps.d.ts +251 -1
- package/lib/actions/clickSteps.js +297 -47
- package/lib/actions/cookieSteps.d.ts +18 -1
- package/lib/actions/cookieSteps.js +65 -0
- package/lib/actions/debugSteps.d.ts +14 -1
- package/lib/actions/debugSteps.js +18 -3
- package/lib/actions/elementFindSteps.d.ts +668 -1
- package/lib/actions/elementFindSteps.js +808 -94
- package/lib/actions/fillFormSteps.d.ts +69 -1
- package/lib/actions/fillFormSteps.js +178 -71
- package/lib/actions/index.d.ts +11 -0
- package/lib/actions/index.js +28 -0
- package/lib/actions/inputSteps.d.ts +218 -1
- package/lib/actions/inputSteps.js +303 -57
- package/lib/actions/interceptionSteps.d.ts +169 -1
- package/lib/actions/interceptionSteps.js +258 -38
- package/lib/actions/miscSteps.d.ts +645 -1
- package/lib/actions/miscSteps.js +898 -157
- package/lib/actions/mouseSteps.d.ts +143 -1
- package/lib/actions/mouseSteps.js +200 -32
- package/lib/actions/scrollSteps.d.ts +82 -1
- package/lib/actions/scrollSteps.js +116 -16
- package/lib/actions/storageSteps.d.ts +174 -1
- package/lib/actions/storageSteps.js +253 -33
- package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +245 -1
- package/lib/assertions/buttonAndTextVisibilitySteps.js +342 -91
- package/lib/assertions/cookieSteps.d.ts +75 -1
- package/lib/assertions/cookieSteps.js +97 -29
- package/lib/assertions/elementSteps.d.ts +264 -1
- package/lib/assertions/elementSteps.js +376 -78
- package/lib/assertions/formInputSteps.d.ts +248 -1
- package/lib/assertions/formInputSteps.js +342 -79
- package/lib/assertions/index.d.ts +10 -0
- package/lib/assertions/index.js +27 -0
- package/lib/assertions/interceptionRequestsSteps.d.ts +353 -1
- package/lib/assertions/interceptionRequestsSteps.js +569 -177
- package/lib/assertions/locationSteps.d.ts +217 -1
- package/lib/assertions/locationSteps.js +287 -64
- package/lib/assertions/roleTestIdSteps.d.ts +159 -1
- package/lib/assertions/roleTestIdSteps.js +217 -22
- package/lib/assertions/semanticSteps.d.ts +176 -1
- package/lib/assertions/semanticSteps.js +245 -60
- package/lib/assertions/storageSteps.d.ts +149 -1
- package/lib/assertions/storageSteps.js +201 -65
- package/lib/assertions/visualSteps.d.ts +74 -1
- package/lib/assertions/visualSteps.js +178 -45
- package/lib/custom_setups/loginHooks.js +19 -2
- package/lib/helpers/world.d.ts +3 -0
- package/lib/helpers/world.js +11 -5
- package/lib/index.d.ts +3 -21
- package/lib/index.js +3 -23
- package/package.json +9 -2
- package/src/actions/clickSteps.ts +364 -142
- package/src/actions/cookieSteps.ts +66 -0
- package/src/actions/debugSteps.ts +17 -3
- package/src/actions/elementFindSteps.ts +822 -117
- package/src/actions/fillFormSteps.ts +234 -177
- package/src/actions/index.ts +12 -0
- package/src/actions/inputSteps.ts +318 -82
- package/src/actions/interceptionSteps.ts +295 -57
- package/src/actions/miscSteps.ts +984 -254
- package/src/actions/mouseSteps.ts +212 -55
- package/src/actions/scrollSteps.ts +114 -16
- package/src/actions/storageSteps.ts +267 -42
- package/src/assertions/buttonAndTextVisibilitySteps.ts +353 -95
- package/src/assertions/cookieSteps.ts +115 -36
- package/src/assertions/elementSteps.ts +414 -85
- package/src/assertions/formInputSteps.ts +375 -108
- package/src/assertions/index.ts +11 -0
- package/src/assertions/interceptionRequestsSteps.ts +619 -195
- package/src/assertions/locationSteps.ts +280 -64
- package/src/assertions/roleTestIdSteps.ts +244 -26
- package/src/assertions/semanticSteps.ts +257 -69
- package/src/assertions/storageSteps.ts +234 -73
- package/src/assertions/visualSteps.ts +245 -68
- package/src/custom_setups/loginHooks.ts +21 -2
- package/src/helpers/world.ts +30 -4
- package/src/index.ts +4 -25
|
@@ -1 +1,143 @@
|
|
|
1
|
-
|
|
1
|
+
import { CustomWorld } from "../helpers/world";
|
|
2
|
+
/**
|
|
3
|
+
* Scrolls the element matching the given selector into view.
|
|
4
|
+
* This is useful for making sure an element is visible before interacting with it.
|
|
5
|
+
*
|
|
6
|
+
* ```gherkin
|
|
7
|
+
* When I scroll {string} into view
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param selector - The CSS selector of the element to scroll into view.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* When I scroll ".footer-section" into view
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This step uses Playwright's `locator.scrollIntoViewIfNeeded()`.
|
|
17
|
+
* It will scroll the page or scrollable container as little as possible to bring
|
|
18
|
+
* the element into the viewport.
|
|
19
|
+
* @category Scrolling Steps
|
|
20
|
+
*/
|
|
21
|
+
export declare function When_I_scroll_element_into_view(this: CustomWorld, selector: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Scrolls the element matching the given selector to a specific X and Y position.
|
|
24
|
+
* The scrolling is relative to the element's own scrollable area.
|
|
25
|
+
*
|
|
26
|
+
* ```gherkin
|
|
27
|
+
* When I scroll {string} to position x:{int} y:{int}
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param selector - The CSS selector of the element to scroll.
|
|
31
|
+
* @param x - The X-coordinate (horizontal) to scroll to within the element.
|
|
32
|
+
* @param y - The Y-coordinate (vertical) to scroll to within the element.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* When I scroll ".my-scrollable-div" to position x:100 y:200
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* This step uses `locator.evaluate()` to execute `element.scrollTo()` directly
|
|
39
|
+
* in the browser context. This is typically used for scrolling within a specific
|
|
40
|
+
* scrollable HTML element, not the main window.
|
|
41
|
+
* @category Scrolling Steps
|
|
42
|
+
*/
|
|
43
|
+
export declare function When_I_scroll_element_to_position(this: CustomWorld, selector: string, x: number, // Changed to number as Cucumber's {int} already parses it
|
|
44
|
+
y: number): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Scrolls the entire window to specific X and Y coordinates.
|
|
47
|
+
* The coordinates are absolute positions on the page.
|
|
48
|
+
*
|
|
49
|
+
* ```gherkin
|
|
50
|
+
* When I scroll to coordinates x:{int} y:{int}
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param x - The X-coordinate (horizontal) to scroll the window to.
|
|
54
|
+
* @param y - The Y-coordinate (vertical) to scroll the window to.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* When I scroll to coordinates x:0 y:500
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* This step uses `page.evaluate()` to execute `window.scrollTo()` directly
|
|
61
|
+
* in the browser context. This controls the main browser window's scroll position.
|
|
62
|
+
* @category Scrolling Steps
|
|
63
|
+
*/
|
|
64
|
+
export declare function When_I_scroll_to_coordinates(this: CustomWorld, x: number, // Changed to number
|
|
65
|
+
y: number): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Scrolls the entire window to a specified top and left position with a smooth animation.
|
|
68
|
+
*
|
|
69
|
+
* ```gherkin
|
|
70
|
+
* When I scroll window to position top:{int} left:{int}
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @param top - The Y-coordinate (vertical) to scroll the window to.
|
|
74
|
+
* @param left - The X-coordinate (horizontal) to scroll the window to.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* When I scroll window to position top:0 left:100
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* This step uses `page.evaluate()` to execute `window.scrollTo()` with a `behavior: "smooth"`
|
|
81
|
+
* option in the browser context, providing a native smooth scrolling experience.
|
|
82
|
+
* @category Scrolling Steps
|
|
83
|
+
*/
|
|
84
|
+
export declare function When_I_scroll_mouse_window_to_position(this: CustomWorld, top: number, // Changed to number
|
|
85
|
+
left: number): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Scrolls the window to a predefined direction (top, bottom, left, or right) with smooth behavior.
|
|
88
|
+
*
|
|
89
|
+
* ```gherkin
|
|
90
|
+
* When I scroll to "{word}"
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @param direction - The direction to scroll to: "top", "bottom", "left", or "right".
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* When I scroll to "bottom"
|
|
97
|
+
* When I scroll to "top"
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* This step evaluates `window.scrollTo()` in the browser context, setting the `top`
|
|
101
|
+
* or `left` property based on the `direction`. It includes a short `waitForTimeout`
|
|
102
|
+
* to allow the smooth scroll animation to complete.
|
|
103
|
+
* @category Scrolling Steps
|
|
104
|
+
*/
|
|
105
|
+
export declare function When_I_scroll_to_direction(this: CustomWorld, direction: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Hovers the mouse cursor over the element matching the given selector.
|
|
108
|
+
*
|
|
109
|
+
* ```gherkin
|
|
110
|
+
* When I hover over the element {string}
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param selector - The CSS selector of the element to hover over.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* When I hover over the element ".dropdown-menu-trigger"
|
|
117
|
+
* Then I should see element ".dropdown-content"
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* This step simulates a mouse hover event. It also stores the hovered element
|
|
121
|
+
* in {@link CustomWorld.element | this.element} for potential subsequent actions.
|
|
122
|
+
* @category Mouse Interaction Steps
|
|
123
|
+
*/
|
|
124
|
+
export declare function When_I_hover_over_the_element(this: CustomWorld, selector: string): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Moves the mouse cursor to the given absolute X and Y coordinates on the page.
|
|
127
|
+
*
|
|
128
|
+
* ```gherkin
|
|
129
|
+
* When I move mouse to coordinates {int}, {int}
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @param x - The X-coordinate in pixels.
|
|
133
|
+
* @param y - The Y-coordinate in pixels.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* When I move mouse to coordinates 100, 200
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* This step directly controls the mouse cursor position using Playwright's
|
|
140
|
+
* `page.mouse.move()`. This is a low-level mouse action.
|
|
141
|
+
* @category Mouse Interaction Steps
|
|
142
|
+
*/
|
|
143
|
+
export declare function When_I_move_mouse_to_coordinates(this: CustomWorld, x: number, y: number): Promise<void>;
|
|
@@ -1,32 +1,155 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.When_I_scroll_element_into_view = When_I_scroll_element_into_view;
|
|
4
|
+
exports.When_I_scroll_element_to_position = When_I_scroll_element_to_position;
|
|
5
|
+
exports.When_I_scroll_to_coordinates = When_I_scroll_to_coordinates;
|
|
6
|
+
exports.When_I_scroll_mouse_window_to_position = When_I_scroll_mouse_window_to_position;
|
|
7
|
+
exports.When_I_scroll_to_direction = When_I_scroll_to_direction;
|
|
8
|
+
exports.When_I_hover_over_the_element = When_I_hover_over_the_element;
|
|
9
|
+
exports.When_I_move_mouse_to_coordinates = When_I_move_mouse_to_coordinates;
|
|
3
10
|
// e2e/step_definitions/common/mouseSteps.ts
|
|
4
11
|
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
// ===================================================================================
|
|
13
|
+
// MOUSE ACTIONS: SCROLLING
|
|
14
|
+
// ===================================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Scrolls the element matching the given selector into view.
|
|
17
|
+
* This is useful for making sure an element is visible before interacting with it.
|
|
18
|
+
*
|
|
19
|
+
* ```gherkin
|
|
20
|
+
* When I scroll {string} into view
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param selector - The CSS selector of the element to scroll into view.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* When I scroll ".footer-section" into view
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This step uses Playwright's `locator.scrollIntoViewIfNeeded()`.
|
|
30
|
+
* It will scroll the page or scrollable container as little as possible to bring
|
|
31
|
+
* the element into the viewport.
|
|
32
|
+
* @category Scrolling Steps
|
|
33
|
+
*/
|
|
34
|
+
async function When_I_scroll_element_into_view(selector) {
|
|
35
|
+
const locator = this.getScope().locator(selector);
|
|
36
|
+
await locator.scrollIntoViewIfNeeded();
|
|
37
|
+
this.log?.(`🖱️ Scrolled element "${selector}" into view.`);
|
|
38
|
+
}
|
|
39
|
+
(0, cucumber_1.When)(/^I scroll "([^"]+)" into view$/, When_I_scroll_element_into_view);
|
|
40
|
+
/**
|
|
41
|
+
* Scrolls the element matching the given selector to a specific X and Y position.
|
|
42
|
+
* The scrolling is relative to the element's own scrollable area.
|
|
43
|
+
*
|
|
44
|
+
* ```gherkin
|
|
45
|
+
* When I scroll {string} to position x:{int} y:{int}
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param selector - The CSS selector of the element to scroll.
|
|
49
|
+
* @param x - The X-coordinate (horizontal) to scroll to within the element.
|
|
50
|
+
* @param y - The Y-coordinate (vertical) to scroll to within the element.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* When I scroll ".my-scrollable-div" to position x:100 y:200
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* This step uses `locator.evaluate()` to execute `element.scrollTo()` directly
|
|
57
|
+
* in the browser context. This is typically used for scrolling within a specific
|
|
58
|
+
* scrollable HTML element, not the main window.
|
|
59
|
+
* @category Scrolling Steps
|
|
60
|
+
*/
|
|
61
|
+
async function When_I_scroll_element_to_position(selector, x, // Changed to number as Cucumber's {int} already parses it
|
|
62
|
+
y // Changed to number
|
|
63
|
+
) {
|
|
64
|
+
const locator = this.getScope().locator(selector);
|
|
65
|
+
await locator.evaluate((el, coords) => {
|
|
66
|
+
el.scrollTo(coords.x, coords.y);
|
|
67
|
+
}, { x, y } // Pass coordinates as an object
|
|
68
|
+
);
|
|
69
|
+
this.log?.(`🖱️ Scrolled element "${selector}" to position x:${x} y:${y}.`);
|
|
70
|
+
}
|
|
71
|
+
(0, cucumber_1.When)(/^I scroll "([^"]+)" to position x:(\d+) y:(\d+)$/, When_I_scroll_element_to_position);
|
|
72
|
+
/**
|
|
73
|
+
* Scrolls the entire window to specific X and Y coordinates.
|
|
74
|
+
* The coordinates are absolute positions on the page.
|
|
75
|
+
*
|
|
76
|
+
* ```gherkin
|
|
77
|
+
* When I scroll to coordinates x:{int} y:{int}
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @param x - The X-coordinate (horizontal) to scroll the window to.
|
|
81
|
+
* @param y - The Y-coordinate (vertical) to scroll the window to.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* When I scroll to coordinates x:0 y:500
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* This step uses `page.evaluate()` to execute `window.scrollTo()` directly
|
|
88
|
+
* in the browser context. This controls the main browser window's scroll position.
|
|
89
|
+
* @category Scrolling Steps
|
|
90
|
+
*/
|
|
91
|
+
async function When_I_scroll_to_coordinates(x, // Changed to number
|
|
92
|
+
y // Changed to number
|
|
93
|
+
) {
|
|
94
|
+
await this.page.evaluate((coords) => {
|
|
95
|
+
window.scrollTo(coords.x, coords.y);
|
|
96
|
+
}, { x, y } // Pass coordinates as an object
|
|
97
|
+
);
|
|
98
|
+
this.log?.(`🖱️ Scrolled window to coordinates x:${x} y:${y}.`);
|
|
99
|
+
}
|
|
100
|
+
(0, cucumber_1.When)(/^I scroll to coordinates x:(\d+) y:(\d+)$/, When_I_scroll_to_coordinates);
|
|
101
|
+
/**
|
|
102
|
+
* Scrolls the entire window to a specified top and left position with a smooth animation.
|
|
103
|
+
*
|
|
104
|
+
* ```gherkin
|
|
105
|
+
* When I scroll window to position top:{int} left:{int}
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @param top - The Y-coordinate (vertical) to scroll the window to.
|
|
109
|
+
* @param left - The X-coordinate (horizontal) to scroll the window to.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* When I scroll window to position top:0 left:100
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* This step uses `page.evaluate()` to execute `window.scrollTo()` with a `behavior: "smooth"`
|
|
116
|
+
* option in the browser context, providing a native smooth scrolling experience.
|
|
117
|
+
* @category Scrolling Steps
|
|
118
|
+
*/
|
|
119
|
+
async function When_I_scroll_mouse_window_to_position(top, // Changed to number
|
|
120
|
+
left // Changed to number
|
|
121
|
+
) {
|
|
122
|
+
await this.page.evaluate((coords) => {
|
|
22
123
|
window.scrollTo({
|
|
23
|
-
top:
|
|
24
|
-
left:
|
|
124
|
+
top: coords.top,
|
|
125
|
+
left: coords.left,
|
|
25
126
|
behavior: "smooth",
|
|
26
127
|
});
|
|
27
|
-
}, top, left
|
|
28
|
-
|
|
29
|
-
|
|
128
|
+
}, { top, left } // Pass coordinates as an object
|
|
129
|
+
);
|
|
130
|
+
this.log?.(`🖱️ Scrolled window to position top:${top} left:${left} (smooth).`);
|
|
131
|
+
}
|
|
132
|
+
(0, cucumber_1.When)(/^I scroll mouse window to position top:(\d+) left:(\d+)$/, When_I_scroll_mouse_window_to_position);
|
|
133
|
+
/**
|
|
134
|
+
* Scrolls the window to a predefined direction (top, bottom, left, or right) with smooth behavior.
|
|
135
|
+
*
|
|
136
|
+
* ```gherkin
|
|
137
|
+
* When I scroll to "{word}"
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @param direction - The direction to scroll to: "top", "bottom", "left", or "right".
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* When I scroll to "bottom"
|
|
144
|
+
* When I scroll to "top"
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* This step evaluates `window.scrollTo()` in the browser context, setting the `top`
|
|
148
|
+
* or `left` property based on the `direction`. It includes a short `waitForTimeout`
|
|
149
|
+
* to allow the smooth scroll animation to complete.
|
|
150
|
+
* @category Scrolling Steps
|
|
151
|
+
*/
|
|
152
|
+
async function When_I_scroll_to_direction(direction) {
|
|
30
153
|
const validDirections = ["top", "bottom", "left", "right"];
|
|
31
154
|
if (!validDirections.includes(direction)) {
|
|
32
155
|
throw new Error(`Invalid scroll direction "${direction}". Must be one of: ${validDirections.join(", ")}.`);
|
|
@@ -40,27 +163,72 @@ const cucumber_1 = require("@cucumber/cucumber");
|
|
|
40
163
|
scrollOptions.top = 0;
|
|
41
164
|
break;
|
|
42
165
|
case "bottom":
|
|
166
|
+
// Scroll to the bottom of the body's scroll height
|
|
43
167
|
scrollOptions.top = document.body.scrollHeight;
|
|
44
168
|
break;
|
|
45
169
|
case "left":
|
|
46
170
|
scrollOptions.left = 0;
|
|
47
171
|
break;
|
|
48
172
|
case "right":
|
|
173
|
+
// Scroll to the rightmost edge of the body's scroll width
|
|
49
174
|
scrollOptions.left = document.body.scrollWidth;
|
|
50
175
|
break;
|
|
51
176
|
}
|
|
52
177
|
window.scrollTo(scrollOptions);
|
|
53
178
|
}, direction);
|
|
54
|
-
this.log?.(`🖱️ Scrolled to "${direction}"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
179
|
+
this.log?.(`🖱️ Scrolled to "${direction}".`);
|
|
180
|
+
// Allow a brief moment for the smooth scroll animation to complete
|
|
181
|
+
await this.page.waitForTimeout(500);
|
|
182
|
+
}
|
|
183
|
+
(0, cucumber_1.When)('I scroll to "{word}"', When_I_scroll_to_direction);
|
|
184
|
+
// ===================================================================================
|
|
185
|
+
// MOUSE ACTIONS: HOVERING / MOVEMENT
|
|
186
|
+
// ===================================================================================
|
|
187
|
+
/**
|
|
188
|
+
* Hovers the mouse cursor over the element matching the given selector.
|
|
189
|
+
*
|
|
190
|
+
* ```gherkin
|
|
191
|
+
* When I hover over the element {string}
|
|
192
|
+
* ```
|
|
193
|
+
*
|
|
194
|
+
* @param selector - The CSS selector of the element to hover over.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* When I hover over the element ".dropdown-menu-trigger"
|
|
198
|
+
* Then I should see element ".dropdown-content"
|
|
199
|
+
*
|
|
200
|
+
* @remarks
|
|
201
|
+
* This step simulates a mouse hover event. It also stores the hovered element
|
|
202
|
+
* in {@link CustomWorld.element | this.element} for potential subsequent actions.
|
|
203
|
+
* @category Mouse Interaction Steps
|
|
204
|
+
*/
|
|
205
|
+
async function When_I_hover_over_the_element(selector) {
|
|
58
206
|
const element = this.getScope().locator(selector);
|
|
59
207
|
await element.hover();
|
|
60
|
-
this.element = element;
|
|
61
|
-
this.log?.(`🖱️ Hovered: ${selector}
|
|
62
|
-
}
|
|
63
|
-
(0, cucumber_1.When)("I
|
|
208
|
+
this.element = element; // Store the hovered element as the current element
|
|
209
|
+
this.log?.(`🖱️ Hovered over: "${selector}".`);
|
|
210
|
+
}
|
|
211
|
+
(0, cucumber_1.When)("I hover over the element {string}", When_I_hover_over_the_element);
|
|
212
|
+
/**
|
|
213
|
+
* Moves the mouse cursor to the given absolute X and Y coordinates on the page.
|
|
214
|
+
*
|
|
215
|
+
* ```gherkin
|
|
216
|
+
* When I move mouse to coordinates {int}, {int}
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* @param x - The X-coordinate in pixels.
|
|
220
|
+
* @param y - The Y-coordinate in pixels.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* When I move mouse to coordinates 100, 200
|
|
224
|
+
*
|
|
225
|
+
* @remarks
|
|
226
|
+
* This step directly controls the mouse cursor position using Playwright's
|
|
227
|
+
* `page.mouse.move()`. This is a low-level mouse action.
|
|
228
|
+
* @category Mouse Interaction Steps
|
|
229
|
+
*/
|
|
230
|
+
async function When_I_move_mouse_to_coordinates(x, y) {
|
|
64
231
|
await this.page.mouse.move(x, y);
|
|
65
|
-
this.log?.(`🧭 Mouse moved to (${x}, ${y})
|
|
66
|
-
}
|
|
232
|
+
this.log?.(`🧭 Mouse moved to (${x}, ${y}).`);
|
|
233
|
+
}
|
|
234
|
+
(0, cucumber_1.When)("I move mouse to coordinates {int}, {int}", When_I_move_mouse_to_coordinates);
|
|
@@ -1 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
import { CustomWorld } from "../helpers/world";
|
|
2
|
+
/**
|
|
3
|
+
* Scrolls the previously selected element into the viewport if it's not already visible.
|
|
4
|
+
*
|
|
5
|
+
* ```gherkin
|
|
6
|
+
* When I scroll into view
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* When I find element by selector ".my-long-content-element"
|
|
11
|
+
* And I scroll into view
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
15
|
+
* (e.g., "When I find element by selector"). It uses Playwright's `locator.scrollIntoViewIfNeeded()`,
|
|
16
|
+
* which scrolls the least amount necessary to make the element visible.
|
|
17
|
+
* @category Scrolling Steps
|
|
18
|
+
*/
|
|
19
|
+
export declare function When_I_scroll_into_view(this: CustomWorld): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Scrolls the main browser window to the given X (horizontal) and Y (vertical) pixel coordinates.
|
|
22
|
+
*
|
|
23
|
+
* ```gherkin
|
|
24
|
+
* When I scroll to position {int} {int}
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param x - The X-coordinate in pixels to scroll to.
|
|
28
|
+
* @param y - The Y-coordinate in pixels to scroll to.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* When I scroll to position 0 500
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* This step directly executes `window.scrollTo(x, y)` in the browser's context.
|
|
35
|
+
* It sets the absolute scroll position of the main document.
|
|
36
|
+
* This is similar to `When I scroll window to position {int} {int}` and `When I scroll window to x {int} and y {int}`.
|
|
37
|
+
* Consider consolidating if their functionality is identical.
|
|
38
|
+
* @category Scrolling Steps
|
|
39
|
+
*/
|
|
40
|
+
export declare function When_I_scroll_to_position(this: CustomWorld, x: number, y: number): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Scrolls the main browser window to the given X (horizontal) and Y (vertical) pixel coordinates.
|
|
43
|
+
* This step is an alias for "When I scroll to position {int} {int}".
|
|
44
|
+
*
|
|
45
|
+
* ```gherkin
|
|
46
|
+
* When I scroll window to position {int} {int}
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param x - The X-coordinate in pixels to scroll to.
|
|
50
|
+
* @param y - The Y-coordinate in pixels to scroll to.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* When I scroll window to position 0 500
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* This step is functionally identical to {@link When_I_scroll_to_position | "When I scroll to position {int} {int}"}.
|
|
57
|
+
* It executes `window.scrollTo(x, y)` in the browser's context.
|
|
58
|
+
* @category Scrolling Steps
|
|
59
|
+
*/
|
|
60
|
+
export declare function When_I_scroll_window_to_position(this: CustomWorld, x: number, y: number): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Scrolls the main browser window to the given X (horizontal) and Y (vertical) pixel coordinates.
|
|
63
|
+
* This step is another alias for "When I scroll to position {int} {int}".
|
|
64
|
+
*
|
|
65
|
+
* ```gherkin
|
|
66
|
+
* When I scroll window to x {int} and y {int}
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param x - The X-coordinate in pixels to scroll to.
|
|
70
|
+
* @param y - The Y-coordinate in pixels to scroll to.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* When I scroll window to x 0 and y 500
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This step is functionally identical to {@link When_I_scroll_to_position | "When I scroll to position {int} {int}"}
|
|
77
|
+
* and {@link When_I_scroll_window_to_position | "When I scroll window to position {int} {int}"}.
|
|
78
|
+
* It executes `window.scrollTo(x, y)` in the browser's context.
|
|
79
|
+
* It's recommended to choose one consistent step pattern for window scrolling.
|
|
80
|
+
* @category Scrolling Steps
|
|
81
|
+
*/
|
|
82
|
+
export declare function When_I_scroll_window_to_x_and_y(this: CustomWorld, x: number, y: number): Promise<void>;
|
|
@@ -1,23 +1,123 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.When_I_scroll_into_view = When_I_scroll_into_view;
|
|
4
|
+
exports.When_I_scroll_to_position = When_I_scroll_to_position;
|
|
5
|
+
exports.When_I_scroll_window_to_position = When_I_scroll_window_to_position;
|
|
6
|
+
exports.When_I_scroll_window_to_x_and_y = When_I_scroll_window_to_x_and_y;
|
|
3
7
|
// e2e/step_definitions/common/scrollSteps.ts
|
|
4
8
|
const cucumber_1 = require("@cucumber/cucumber");
|
|
5
|
-
|
|
9
|
+
// ===================================================================================
|
|
10
|
+
// SCROLLING ACTIONS
|
|
11
|
+
// ===================================================================================
|
|
12
|
+
/**
|
|
13
|
+
* Scrolls the previously selected element into the viewport if it's not already visible.
|
|
14
|
+
*
|
|
15
|
+
* ```gherkin
|
|
16
|
+
* When I scroll into view
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* When I find element by selector ".my-long-content-element"
|
|
21
|
+
* And I scroll into view
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This step requires a preceding step that sets the {@link CustomWorld.element | current element}
|
|
25
|
+
* (e.g., "When I find element by selector"). It uses Playwright's `locator.scrollIntoViewIfNeeded()`,
|
|
26
|
+
* which scrolls the least amount necessary to make the element visible.
|
|
27
|
+
* @category Scrolling Steps
|
|
28
|
+
*/
|
|
29
|
+
async function When_I_scroll_into_view() {
|
|
6
30
|
const element = this.element;
|
|
7
31
|
if (!element)
|
|
8
|
-
throw new Error("No element selected");
|
|
32
|
+
throw new Error("No element selected. Use a 'find element' step before this.");
|
|
9
33
|
await element.scrollIntoViewIfNeeded();
|
|
10
|
-
this.log("Scrolled selected element into view");
|
|
11
|
-
}
|
|
12
|
-
(0, cucumber_1.When)("I scroll
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
34
|
+
this.log?.("Scrolled selected element into view."); // Using optional chaining for log
|
|
35
|
+
}
|
|
36
|
+
(0, cucumber_1.When)("I scroll into view", When_I_scroll_into_view);
|
|
37
|
+
/**
|
|
38
|
+
* Scrolls the main browser window to the given X (horizontal) and Y (vertical) pixel coordinates.
|
|
39
|
+
*
|
|
40
|
+
* ```gherkin
|
|
41
|
+
* When I scroll to position {int} {int}
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param x - The X-coordinate in pixels to scroll to.
|
|
45
|
+
* @param y - The Y-coordinate in pixels to scroll to.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* When I scroll to position 0 500
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* This step directly executes `window.scrollTo(x, y)` in the browser's context.
|
|
52
|
+
* It sets the absolute scroll position of the main document.
|
|
53
|
+
* This is similar to `When I scroll window to position {int} {int}` and `When I scroll window to x {int} and y {int}`.
|
|
54
|
+
* Consider consolidating if their functionality is identical.
|
|
55
|
+
* @category Scrolling Steps
|
|
56
|
+
*/
|
|
57
|
+
async function When_I_scroll_to_position(x, y) {
|
|
58
|
+
// FIX: Pass arguments as an object instead of an array
|
|
59
|
+
await this.page.evaluate(({ xCoord, yCoord }) => window.scrollTo(xCoord, yCoord), {
|
|
60
|
+
xCoord: x,
|
|
61
|
+
yCoord: y,
|
|
62
|
+
});
|
|
63
|
+
this.log?.(`Scrolled window to position: ${x}, ${y}.`);
|
|
64
|
+
}
|
|
65
|
+
(0, cucumber_1.When)("I scroll to position {int} {int}", When_I_scroll_to_position);
|
|
66
|
+
/**
|
|
67
|
+
* Scrolls the main browser window to the given X (horizontal) and Y (vertical) pixel coordinates.
|
|
68
|
+
* This step is an alias for "When I scroll to position {int} {int}".
|
|
69
|
+
*
|
|
70
|
+
* ```gherkin
|
|
71
|
+
* When I scroll window to position {int} {int}
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param x - The X-coordinate in pixels to scroll to.
|
|
75
|
+
* @param y - The Y-coordinate in pixels to scroll to.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* When I scroll window to position 0 500
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* This step is functionally identical to {@link When_I_scroll_to_position | "When I scroll to position {int} {int}"}.
|
|
82
|
+
* It executes `window.scrollTo(x, y)` in the browser's context.
|
|
83
|
+
* @category Scrolling Steps
|
|
84
|
+
*/
|
|
85
|
+
async function When_I_scroll_window_to_position(x, y) {
|
|
86
|
+
// FIX: Pass arguments as an object instead of an array
|
|
87
|
+
await this.page.evaluate(({ xCoord, yCoord }) => window.scrollTo(xCoord, yCoord), {
|
|
88
|
+
xCoord: x,
|
|
89
|
+
yCoord: y,
|
|
90
|
+
});
|
|
91
|
+
this.log?.(`Window scrolled to: ${x}, ${y}.`);
|
|
92
|
+
}
|
|
93
|
+
(0, cucumber_1.When)("I scroll window to position {int} {int}", When_I_scroll_window_to_position);
|
|
94
|
+
/**
|
|
95
|
+
* Scrolls the main browser window to the given X (horizontal) and Y (vertical) pixel coordinates.
|
|
96
|
+
* This step is another alias for "When I scroll to position {int} {int}".
|
|
97
|
+
*
|
|
98
|
+
* ```gherkin
|
|
99
|
+
* When I scroll window to x {int} and y {int}
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @param x - The X-coordinate in pixels to scroll to.
|
|
103
|
+
* @param y - The Y-coordinate in pixels to scroll to.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* When I scroll window to x 0 and y 500
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* This step is functionally identical to {@link When_I_scroll_to_position | "When I scroll to position {int} {int}"}
|
|
110
|
+
* and {@link When_I_scroll_window_to_position | "When I scroll window to position {int} {int}"}.
|
|
111
|
+
* It executes `window.scrollTo(x, y)` in the browser's context.
|
|
112
|
+
* It's recommended to choose one consistent step pattern for window scrolling.
|
|
113
|
+
* @category Scrolling Steps
|
|
114
|
+
*/
|
|
115
|
+
async function When_I_scroll_window_to_x_and_y(x, y) {
|
|
116
|
+
// FIX: Pass arguments as an object instead of an array
|
|
117
|
+
await this.page.evaluate(({ xCoord, yCoord }) => window.scrollTo(xCoord, yCoord), {
|
|
118
|
+
xCoord: x,
|
|
119
|
+
yCoord: y,
|
|
120
|
+
});
|
|
121
|
+
this.log?.(`Window scrolled to coordinates: (${x}, ${y}).`);
|
|
122
|
+
}
|
|
123
|
+
(0, cucumber_1.When)("I scroll window to x {int} and y {int}", When_I_scroll_window_to_x_and_y);
|