playwright-cucumber-ts-steps 1.1.12 → 1.2.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/README.md +1697 -2
- package/dist/backend/actions/click.d.ts +55 -77
- package/dist/backend/actions/click.d.ts.map +1 -1
- package/dist/backend/actions/click.js +125 -103
- package/dist/backend/actions/find.d.ts +48 -121
- package/dist/backend/actions/find.d.ts.map +1 -1
- package/dist/backend/actions/find.js +126 -172
- package/dist/backend/actions/form.d.ts +18 -26
- package/dist/backend/actions/form.d.ts.map +1 -1
- package/dist/backend/actions/form.js +30 -35
- package/dist/backend/actions/formTable.d.ts +4 -9
- package/dist/backend/actions/formTable.d.ts.map +1 -1
- package/dist/backend/actions/formTable.js +13 -11
- package/dist/backend/actions/frames.d.ts +7 -35
- package/dist/backend/actions/frames.d.ts.map +1 -1
- package/dist/backend/actions/frames.js +22 -61
- package/dist/backend/actions/index.d.ts +0 -1
- package/dist/backend/actions/index.d.ts.map +1 -1
- package/dist/backend/actions/index.js +0 -1
- package/dist/backend/actions/inputs.d.ts +33 -77
- package/dist/backend/actions/inputs.d.ts.map +1 -1
- package/dist/backend/actions/inputs.js +92 -116
- package/dist/backend/actions/interactions.d.ts +10 -32
- package/dist/backend/actions/interactions.d.ts.map +1 -1
- package/dist/backend/actions/interactions.js +31 -41
- package/dist/backend/actions/keyboard.d.ts +13 -37
- package/dist/backend/actions/keyboard.d.ts.map +1 -1
- package/dist/backend/actions/keyboard.js +35 -46
- package/dist/backend/actions/misc.d.ts +29 -69
- package/dist/backend/actions/misc.d.ts.map +1 -1
- package/dist/backend/actions/misc.js +77 -98
- package/dist/backend/actions/mobile.d.ts +14 -36
- package/dist/backend/actions/mobile.d.ts.map +1 -1
- package/dist/backend/actions/mobile.js +42 -55
- package/dist/backend/actions/mouse.d.ts +29 -36
- package/dist/backend/actions/mouse.d.ts.map +1 -1
- package/dist/backend/actions/mouse.js +76 -51
- package/dist/backend/actions/navigation.d.ts +11 -23
- package/dist/backend/actions/navigation.d.ts.map +1 -1
- package/dist/backend/actions/navigation.js +32 -32
- package/dist/backend/actions/waits.d.ts +11 -30
- package/dist/backend/actions/waits.d.ts.map +1 -1
- package/dist/backend/actions/waits.js +32 -39
- package/dist/backend/api/assertions.d.ts +6 -15
- package/dist/backend/api/assertions.d.ts.map +1 -1
- package/dist/backend/api/assertions.js +21 -23
- package/dist/backend/api/mock.d.ts +9 -18
- package/dist/backend/api/mock.d.ts.map +1 -1
- package/dist/backend/api/mock.js +24 -22
- package/dist/backend/api/network.d.ts +13 -25
- package/dist/backend/api/network.d.ts.map +1 -1
- package/dist/backend/api/network.js +40 -39
- package/dist/backend/api/requests.d.ts +13 -24
- package/dist/backend/api/requests.d.ts.map +1 -1
- package/dist/backend/api/requests.js +31 -30
- package/dist/backend/assertions/pageState.d.ts +13 -24
- package/dist/backend/assertions/pageState.d.ts.map +1 -1
- package/dist/backend/assertions/pageState.js +31 -29
- package/dist/backend/assertions/text.d.ts +12 -23
- package/dist/backend/assertions/text.d.ts.map +1 -1
- package/dist/backend/assertions/text.js +30 -28
- package/dist/backend/assertions/visibility.d.ts +24 -51
- package/dist/backend/assertions/visibility.d.ts.map +1 -1
- package/dist/backend/assertions/visibility.js +74 -79
- package/dist/backend/auth/index.d.ts +14 -1
- package/dist/backend/auth/index.d.ts.map +1 -1
- package/dist/backend/auth/index.js +26 -8
- package/dist/backend/db/steps.d.ts +58 -18
- package/dist/backend/db/steps.d.ts.map +1 -1
- package/dist/backend/db/steps.js +180 -26
- package/dist/backend/elements/alerts.d.ts +10 -19
- package/dist/backend/elements/alerts.d.ts.map +1 -1
- package/dist/backend/elements/alerts.js +25 -23
- package/dist/backend/elements/forms.d.ts +12 -23
- package/dist/backend/elements/forms.d.ts.map +1 -1
- package/dist/backend/elements/forms.js +30 -29
- package/dist/backend/elements/frames.d.ts +9 -18
- package/dist/backend/elements/frames.d.ts.map +1 -1
- package/dist/backend/elements/frames.js +24 -23
- package/dist/backend/index.d.ts +14 -0
- package/dist/backend/index.d.ts.map +1 -0
- package/dist/backend/index.js +31 -0
- package/dist/metadata.json +1016 -0
- package/package.json +8 -4
|
@@ -1,75 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Taps on the currently stored (active) element.
|
|
3
3
|
* Uses a "Hybrid Tap" strategy: tries to tap, falls back to click if touch is unsupported.
|
|
4
|
-
*
|
|
5
|
-
* ```gherkin
|
|
4
|
+
* @example
|
|
6
5
|
* When I tap
|
|
7
|
-
* ```
|
|
8
6
|
*/
|
|
9
|
-
export declare
|
|
7
|
+
export declare function tapStoredElement(page: any): Promise<void>;
|
|
10
8
|
/**
|
|
11
9
|
* Finds an element by selector and taps it.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* ```gherkin
|
|
10
|
+
* @example
|
|
15
11
|
* When I tap element "#menu-toggle"
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
12
|
* @param selector - The CSS selector of the element.
|
|
19
13
|
*/
|
|
20
|
-
export declare
|
|
14
|
+
export declare function tapElementBySelector(page: any, selector: string): Promise<void>;
|
|
21
15
|
/**
|
|
22
16
|
* Taps at specific X, Y coordinates on the screen.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* ```gherkin
|
|
17
|
+
* @example
|
|
26
18
|
* When I tap coordinates x:50 y:200
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
19
|
* @param x - The X-coordinate.
|
|
30
20
|
* @param y - The Y-coordinate.
|
|
31
21
|
*/
|
|
32
|
-
export declare
|
|
22
|
+
export declare function tapCoordinates(page: any, x: number, y: number): Promise<void>;
|
|
33
23
|
/**
|
|
34
24
|
* Resizes the browser window/viewport to specific dimensions.
|
|
35
|
-
*
|
|
36
|
-
* ```gherkin
|
|
25
|
+
* @example
|
|
37
26
|
* When I resize window to width 375 and height 812
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
27
|
* @param width - The width in pixels.
|
|
41
28
|
* @param height - The height in pixels.
|
|
42
29
|
*/
|
|
43
|
-
export declare
|
|
30
|
+
export declare function resizeWindow(page: any, width: number, height: number): Promise<void>;
|
|
44
31
|
/**
|
|
45
32
|
* Resizes the viewport to match a specific device preset.
|
|
46
|
-
*
|
|
47
|
-
* ```gherkin
|
|
33
|
+
* @example
|
|
48
34
|
* When I simulate device "iPhone 12"
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
35
|
* @param deviceName - The name of the device. Supported: "iPhone 12", "iPhone SE", "iPad", "Pixel 5", "Samsung Galaxy S8", "Desktop".
|
|
52
36
|
*/
|
|
53
|
-
export declare
|
|
37
|
+
export declare function simulateDevice(page: any, deviceName: string): Promise<void>;
|
|
54
38
|
/**
|
|
55
39
|
* Sets the geolocation coordinates for the browser context and auto-grants permission.
|
|
56
|
-
*
|
|
57
|
-
* ```gherkin
|
|
40
|
+
* @example
|
|
58
41
|
* When I set geolocation to lat: 37.7749 long: -122.4194
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
42
|
* @param lat - The latitude (float).
|
|
62
43
|
* @param long - The longitude (float).
|
|
63
44
|
*/
|
|
64
|
-
export declare
|
|
45
|
+
export declare function setGeolocation(page: any, lat: number, long: number): Promise<void>;
|
|
65
46
|
/**
|
|
66
47
|
* Grants a specific browser permission to the current context.
|
|
67
|
-
*
|
|
68
|
-
* ```gherkin
|
|
48
|
+
* @example
|
|
69
49
|
* When I grant permission "notifications"
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
50
|
* @param permission - The permission name (e.g., "geolocation", "notifications", "camera").
|
|
73
51
|
*/
|
|
74
|
-
export declare
|
|
52
|
+
export declare function grantPermission(page: any, permission: string): Promise<void>;
|
|
75
53
|
//# sourceMappingURL=mobile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobile.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/mobile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mobile.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/mobile.ts"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/D;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGnF;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1F;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBjF;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIxF;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlF"}
|
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.tapStoredElement = tapStoredElement;
|
|
4
|
+
exports.tapElementBySelector = tapElementBySelector;
|
|
5
|
+
exports.tapCoordinates = tapCoordinates;
|
|
6
|
+
exports.resizeWindow = resizeWindow;
|
|
7
|
+
exports.simulateDevice = simulateDevice;
|
|
8
|
+
exports.setGeolocation = setGeolocation;
|
|
9
|
+
exports.grantPermission = grantPermission;
|
|
4
10
|
const registry_1 = require("../../core/registry");
|
|
5
11
|
const state_1 = require("../utils/state");
|
|
12
|
+
// ==================================================
|
|
13
|
+
// HELPER FUNCTIONS
|
|
14
|
+
// ==================================================
|
|
6
15
|
/**
|
|
7
16
|
* Helper: Tries to perform a touch tap.
|
|
8
17
|
* If the current browser context does not support touch events (e.g., Desktop Chrome),
|
|
9
18
|
* it gracefully falls back to a standard mouse click.
|
|
10
|
-
*
|
|
11
19
|
* @param target - The Playwright Locator to interact with.
|
|
12
20
|
* @returns "tapped" or "clicked (fallback)" based on what occurred.
|
|
13
21
|
*/
|
|
14
22
|
async function safeTap(target) {
|
|
15
23
|
try {
|
|
16
|
-
// Try native touch tap
|
|
17
24
|
await target.tap();
|
|
18
25
|
return "tapped";
|
|
19
26
|
}
|
|
20
27
|
catch (error) {
|
|
21
28
|
if (error.message.includes("does not support tap")) {
|
|
22
|
-
// Fallback for Desktop Contexts
|
|
23
29
|
await target.click();
|
|
24
30
|
return "clicked (fallback)";
|
|
25
31
|
}
|
|
@@ -27,79 +33,59 @@ async function safeTap(target) {
|
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
// ==================================================
|
|
30
|
-
//
|
|
36
|
+
// CORE FUNCTIONS
|
|
31
37
|
// ==================================================
|
|
32
38
|
/**
|
|
33
39
|
* Taps on the currently stored (active) element.
|
|
34
40
|
* Uses a "Hybrid Tap" strategy: tries to tap, falls back to click if touch is unsupported.
|
|
35
|
-
*
|
|
36
|
-
* ```gherkin
|
|
41
|
+
* @example
|
|
37
42
|
* When I tap
|
|
38
|
-
* ```
|
|
39
43
|
*/
|
|
40
|
-
|
|
44
|
+
async function tapStoredElement(page) {
|
|
41
45
|
const element = (0, state_1.getActiveElement)(page);
|
|
42
46
|
const action = await safeTap(element);
|
|
43
47
|
console.log(`👆 ${action === "tapped" ? "Tapped" : "Clicked"} stored element`);
|
|
44
|
-
}
|
|
48
|
+
}
|
|
45
49
|
/**
|
|
46
50
|
* Finds an element by selector and taps it.
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* ```gherkin
|
|
51
|
+
* @example
|
|
50
52
|
* When I tap element "#menu-toggle"
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
53
|
* @param selector - The CSS selector of the element.
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
async function tapElementBySelector(page, selector) {
|
|
56
56
|
const element = page.locator(selector);
|
|
57
57
|
const action = await safeTap(element);
|
|
58
58
|
console.log(`👆 ${action === "tapped" ? "Tapped" : "Clicked"} element "${selector}"`);
|
|
59
|
-
}
|
|
59
|
+
}
|
|
60
60
|
/**
|
|
61
61
|
* Taps at specific X, Y coordinates on the screen.
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* ```gherkin
|
|
62
|
+
* @example
|
|
65
63
|
* When I tap coordinates x:50 y:200
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
64
|
* @param x - The X-coordinate.
|
|
69
65
|
* @param y - The Y-coordinate.
|
|
70
66
|
*/
|
|
71
|
-
|
|
72
|
-
// page.mouse.click works for both desktop and mobile viewports
|
|
67
|
+
async function tapCoordinates(page, x, y) {
|
|
73
68
|
await page.mouse.click(x, y);
|
|
74
69
|
console.log(`👆 Tapped at (${x}, ${y})`);
|
|
75
|
-
}
|
|
76
|
-
// ==================================================
|
|
77
|
-
// 2. VIEWPORT & EMULATION
|
|
78
|
-
// ==================================================
|
|
70
|
+
}
|
|
79
71
|
/**
|
|
80
72
|
* Resizes the browser window/viewport to specific dimensions.
|
|
81
|
-
*
|
|
82
|
-
* ```gherkin
|
|
73
|
+
* @example
|
|
83
74
|
* When I resize window to width 375 and height 812
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
75
|
* @param width - The width in pixels.
|
|
87
76
|
* @param height - The height in pixels.
|
|
88
77
|
*/
|
|
89
|
-
|
|
78
|
+
async function resizeWindow(page, width, height) {
|
|
90
79
|
await page.setViewportSize({ width, height });
|
|
91
80
|
console.log(`📱 Resized viewport to ${width}x${height}`);
|
|
92
|
-
}
|
|
81
|
+
}
|
|
93
82
|
/**
|
|
94
83
|
* Resizes the viewport to match a specific device preset.
|
|
95
|
-
*
|
|
96
|
-
* ```gherkin
|
|
84
|
+
* @example
|
|
97
85
|
* When I simulate device "iPhone 12"
|
|
98
|
-
* ```
|
|
99
|
-
*
|
|
100
86
|
* @param deviceName - The name of the device. Supported: "iPhone 12", "iPhone SE", "iPad", "Pixel 5", "Samsung Galaxy S8", "Desktop".
|
|
101
87
|
*/
|
|
102
|
-
|
|
88
|
+
async function simulateDevice(page, deviceName) {
|
|
103
89
|
const devices = {
|
|
104
90
|
"iPhone 12": { width: 390, height: 844 },
|
|
105
91
|
"iPhone SE": { width: 375, height: 667 },
|
|
@@ -114,35 +100,36 @@ exports.SimulateDevice = (0, registry_1.Step)("I simulate device {string}", asyn
|
|
|
114
100
|
}
|
|
115
101
|
await page.setViewportSize(size);
|
|
116
102
|
console.log(`📱 Simulated device "${deviceName}" (${size.width}x${size.height})`);
|
|
117
|
-
}
|
|
118
|
-
// ==================================================
|
|
119
|
-
// 3. GEOLOCATION & PERMISSIONS
|
|
120
|
-
// ==================================================
|
|
103
|
+
}
|
|
121
104
|
/**
|
|
122
105
|
* Sets the geolocation coordinates for the browser context and auto-grants permission.
|
|
123
|
-
*
|
|
124
|
-
* ```gherkin
|
|
106
|
+
* @example
|
|
125
107
|
* When I set geolocation to lat: 37.7749 long: -122.4194
|
|
126
|
-
* ```
|
|
127
|
-
*
|
|
128
108
|
* @param lat - The latitude (float).
|
|
129
109
|
* @param long - The longitude (float).
|
|
130
110
|
*/
|
|
131
|
-
|
|
111
|
+
async function setGeolocation(page, lat, long) {
|
|
132
112
|
await page.context().setGeolocation({ latitude: lat, longitude: long });
|
|
133
113
|
await page.context().grantPermissions(["geolocation"]);
|
|
134
114
|
console.log(`🌍 Geolocation set to ${lat}, ${long}`);
|
|
135
|
-
}
|
|
115
|
+
}
|
|
136
116
|
/**
|
|
137
117
|
* Grants a specific browser permission to the current context.
|
|
138
|
-
*
|
|
139
|
-
* ```gherkin
|
|
118
|
+
* @example
|
|
140
119
|
* When I grant permission "notifications"
|
|
141
|
-
* ```
|
|
142
|
-
*
|
|
143
120
|
* @param permission - The permission name (e.g., "geolocation", "notifications", "camera").
|
|
144
121
|
*/
|
|
145
|
-
|
|
122
|
+
async function grantPermission(page, permission) {
|
|
146
123
|
await page.context().grantPermissions([permission]);
|
|
147
124
|
console.log(`🛡️ Granted permission: "${permission}"`);
|
|
148
|
-
}
|
|
125
|
+
}
|
|
126
|
+
// ==================================================
|
|
127
|
+
// GLUE STEPS
|
|
128
|
+
// ==================================================
|
|
129
|
+
(0, registry_1.Step)("I tap", tapStoredElement);
|
|
130
|
+
(0, registry_1.Step)("I tap element {string}", tapElementBySelector);
|
|
131
|
+
(0, registry_1.Step)("I tap coordinates x:{int} y:{int}", tapCoordinates);
|
|
132
|
+
(0, registry_1.Step)("I resize window to width {int} and height {int}", resizeWindow);
|
|
133
|
+
(0, registry_1.Step)("I simulate device {string}", simulateDevice);
|
|
134
|
+
(0, registry_1.Step)("I set geolocation to lat: {float} long: {float}", setGeolocation);
|
|
135
|
+
(0, registry_1.Step)("I grant permission {string}", grantPermission);
|
|
@@ -1,80 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Scrolls a specific element into the visible viewport.
|
|
3
3
|
* Useful when an element is off-screen and needs to be visible before interaction.
|
|
4
|
-
*
|
|
5
|
-
* ```gherkin
|
|
4
|
+
* @example
|
|
6
5
|
* When I scroll ".footer-section" into view
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
6
|
* @param selector - The CSS selector of the element.
|
|
10
7
|
*/
|
|
11
|
-
export declare
|
|
8
|
+
export declare function scrollIntoView(page: any, selector: string): Promise<void>;
|
|
12
9
|
/**
|
|
13
10
|
* Scrolls the internal content of a specific element (overflow container) to X, Y coordinates.
|
|
14
|
-
*
|
|
15
|
-
* ```gherkin
|
|
11
|
+
* @example
|
|
16
12
|
* When I scroll "#chat-box" to position x:0 y:500
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
13
|
* @param selector - The CSS selector of the scrollable container.
|
|
20
14
|
* @param x - The horizontal scroll position (pixels).
|
|
21
15
|
* @param y - The vertical scroll position (pixels).
|
|
22
16
|
*/
|
|
23
|
-
export declare
|
|
17
|
+
export declare function scrollElementToPosition(page: any, selector: string, x: number, y: number): Promise<void>;
|
|
24
18
|
/**
|
|
25
19
|
* Scrolls the entire main browser window to specific X, Y coordinates immediately.
|
|
26
|
-
*
|
|
27
|
-
* ```gherkin
|
|
20
|
+
* @example
|
|
28
21
|
* When I scroll to coordinates x:0 y:0
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
22
|
* @param x - The absolute horizontal position.
|
|
32
23
|
* @param y - The absolute vertical position.
|
|
33
24
|
*/
|
|
34
|
-
export declare
|
|
25
|
+
export declare function scrollWindowToCoordinates(page: any, x: number, y: number): Promise<void>;
|
|
35
26
|
/**
|
|
36
27
|
* Scrolls the entire main browser window smoothly to specific coordinates.
|
|
37
|
-
*
|
|
38
|
-
* ```gherkin
|
|
28
|
+
* @example
|
|
39
29
|
* When I scroll mouse window to position top:0 left:0
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
30
|
* @param top - The vertical position (Y).
|
|
43
31
|
* @param left - The horizontal position (X).
|
|
44
32
|
*/
|
|
45
|
-
export declare
|
|
33
|
+
export declare function scrollWindowSmoothly(page: any, top: number, left: number): Promise<void>;
|
|
46
34
|
/**
|
|
47
35
|
* Scrolls the window to a general direction edge (top, bottom, left, right).
|
|
48
36
|
* Includes a short wait for smooth scrolling animation to complete.
|
|
49
|
-
*
|
|
50
|
-
* ```gherkin
|
|
37
|
+
* @example
|
|
51
38
|
* When I scroll to "bottom"
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
39
|
* @param direction - One of: "top", "bottom", "left", "right".
|
|
55
40
|
*/
|
|
56
|
-
export declare
|
|
41
|
+
export declare function scrollToDirection(page: any, direction: string): Promise<void>;
|
|
57
42
|
/**
|
|
58
43
|
* Simulates a mouse hover over an element.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* ```gherkin
|
|
44
|
+
* Sets the hovered element as the "Active Element" for subsequent steps.
|
|
45
|
+
* @example
|
|
62
46
|
* When I hover over the element ".dropdown-toggle"
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
47
|
* @param selector - The CSS selector to hover over.
|
|
66
48
|
*/
|
|
67
|
-
export declare
|
|
49
|
+
export declare function hoverElement(page: any, selector: string): Promise<void>;
|
|
68
50
|
/**
|
|
69
51
|
* Moves the mouse cursor to specific absolute screen coordinates.
|
|
70
52
|
* Useful for canvas interactions or testing mouse tracking.
|
|
71
|
-
*
|
|
72
|
-
* ```gherkin
|
|
53
|
+
* @example
|
|
73
54
|
* When I move mouse to coordinates 100, 200
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
55
|
* @param x - The X-coordinate.
|
|
77
56
|
* @param y - The Y-coordinate.
|
|
78
57
|
*/
|
|
79
|
-
export declare
|
|
58
|
+
export declare function moveMouseToCoordinates(page: any, x: number, y: number): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Hovers over the Nth element containing the specified text.
|
|
61
|
+
* @example
|
|
62
|
+
* When I hover on 1st element "Profile"
|
|
63
|
+
* When I hover on 3rd element "Settings"
|
|
64
|
+
* | timeout | 2000 |
|
|
65
|
+
*/
|
|
66
|
+
export declare function hoverNthElementByText(page: any, indexStr: string, text: string, table?: any): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Hovers over the Nth element matching a CSS or XPath selector.
|
|
69
|
+
* @example
|
|
70
|
+
* When I hover on 1st selector ".user-avatar"
|
|
71
|
+
*/
|
|
72
|
+
export declare function hoverNthElementBySelector(page: any, indexStr: string, selector: string, table?: any): Promise<void>;
|
|
80
73
|
//# sourceMappingURL=mouse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/mouse.ts"],"names":[],"mappings":"AAOA
|
|
1
|
+
{"version":3,"file":"mouse.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/mouse.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAI/E;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,GACR,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ9F;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAY9F;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCnF;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK7E;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3F;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,GAAG,GACV,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,GAAG,GACV,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
|
@@ -1,71 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.scrollIntoView = scrollIntoView;
|
|
4
|
+
exports.scrollElementToPosition = scrollElementToPosition;
|
|
5
|
+
exports.scrollWindowToCoordinates = scrollWindowToCoordinates;
|
|
6
|
+
exports.scrollWindowSmoothly = scrollWindowSmoothly;
|
|
7
|
+
exports.scrollToDirection = scrollToDirection;
|
|
8
|
+
exports.hoverElement = hoverElement;
|
|
9
|
+
exports.moveMouseToCoordinates = moveMouseToCoordinates;
|
|
10
|
+
exports.hoverNthElementByText = hoverNthElementByText;
|
|
11
|
+
exports.hoverNthElementBySelector = hoverNthElementBySelector;
|
|
4
12
|
const registry_1 = require("../../core/registry");
|
|
5
13
|
const state_1 = require("../utils/state");
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
14
|
+
// ==================================================
|
|
15
|
+
// CORE FUNCTIONS
|
|
16
|
+
// ==================================================
|
|
9
17
|
/**
|
|
10
18
|
* Scrolls a specific element into the visible viewport.
|
|
11
19
|
* Useful when an element is off-screen and needs to be visible before interaction.
|
|
12
|
-
*
|
|
13
|
-
* ```gherkin
|
|
20
|
+
* @example
|
|
14
21
|
* When I scroll ".footer-section" into view
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
22
|
* @param selector - The CSS selector of the element.
|
|
18
23
|
*/
|
|
19
|
-
|
|
24
|
+
async function scrollIntoView(page, selector) {
|
|
20
25
|
const locator = page.locator(selector);
|
|
21
26
|
await locator.scrollIntoViewIfNeeded();
|
|
22
27
|
console.log(`🖱️ Scrolled element "${selector}" into view.`);
|
|
23
|
-
}
|
|
28
|
+
}
|
|
24
29
|
/**
|
|
25
30
|
* Scrolls the internal content of a specific element (overflow container) to X, Y coordinates.
|
|
26
|
-
*
|
|
27
|
-
* ```gherkin
|
|
31
|
+
* @example
|
|
28
32
|
* When I scroll "#chat-box" to position x:0 y:500
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
33
|
* @param selector - The CSS selector of the scrollable container.
|
|
32
34
|
* @param x - The horizontal scroll position (pixels).
|
|
33
35
|
* @param y - The vertical scroll position (pixels).
|
|
34
36
|
*/
|
|
35
|
-
|
|
37
|
+
async function scrollElementToPosition(page, selector, x, y) {
|
|
36
38
|
const locator = page.locator(selector);
|
|
37
39
|
await locator.evaluate((el, coords) => {
|
|
38
40
|
el.scrollTo(coords.x, coords.y);
|
|
39
41
|
}, { x, y });
|
|
40
42
|
console.log(`🖱️ Scrolled element "${selector}" to position x:${x} y:${y}.`);
|
|
41
|
-
}
|
|
43
|
+
}
|
|
42
44
|
/**
|
|
43
45
|
* Scrolls the entire main browser window to specific X, Y coordinates immediately.
|
|
44
|
-
*
|
|
45
|
-
* ```gherkin
|
|
46
|
+
* @example
|
|
46
47
|
* When I scroll to coordinates x:0 y:0
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
48
|
* @param x - The absolute horizontal position.
|
|
50
49
|
* @param y - The absolute vertical position.
|
|
51
50
|
*/
|
|
52
|
-
|
|
51
|
+
async function scrollWindowToCoordinates(page, x, y) {
|
|
53
52
|
await page.evaluate((coords) => {
|
|
54
53
|
window.scrollTo(coords.x, coords.y);
|
|
55
54
|
}, { x, y });
|
|
56
55
|
console.log(`🖱️ Scrolled window to coordinates x:${x} y:${y}.`);
|
|
57
|
-
}
|
|
56
|
+
}
|
|
58
57
|
/**
|
|
59
58
|
* Scrolls the entire main browser window smoothly to specific coordinates.
|
|
60
|
-
*
|
|
61
|
-
* ```gherkin
|
|
59
|
+
* @example
|
|
62
60
|
* When I scroll mouse window to position top:0 left:0
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
61
|
* @param top - The vertical position (Y).
|
|
66
62
|
* @param left - The horizontal position (X).
|
|
67
63
|
*/
|
|
68
|
-
|
|
64
|
+
async function scrollWindowSmoothly(page, top, left) {
|
|
69
65
|
await page.evaluate((coords) => {
|
|
70
66
|
window.scrollTo({
|
|
71
67
|
top: coords.top,
|
|
@@ -74,18 +70,15 @@ exports.ScrollWindowSmoothly = (0, registry_1.Step)("I scroll mouse window to po
|
|
|
74
70
|
});
|
|
75
71
|
}, { top, left });
|
|
76
72
|
console.log(`🖱️ Scrolled window to position top:${top} left:${left} (smooth).`);
|
|
77
|
-
}
|
|
73
|
+
}
|
|
78
74
|
/**
|
|
79
75
|
* Scrolls the window to a general direction edge (top, bottom, left, right).
|
|
80
76
|
* Includes a short wait for smooth scrolling animation to complete.
|
|
81
|
-
*
|
|
82
|
-
* ```gherkin
|
|
77
|
+
* @example
|
|
83
78
|
* When I scroll to "bottom"
|
|
84
|
-
* ```
|
|
85
|
-
*
|
|
86
79
|
* @param direction - One of: "top", "bottom", "left", "right".
|
|
87
80
|
*/
|
|
88
|
-
|
|
81
|
+
async function scrollToDirection(page, direction) {
|
|
89
82
|
const validDirections = ["top", "bottom", "left", "right"];
|
|
90
83
|
const dir = direction.toLowerCase();
|
|
91
84
|
if (!validDirections.includes(dir)) {
|
|
@@ -112,39 +105,71 @@ exports.ScrollToDirection = (0, registry_1.Step)("I scroll to {string}", async (
|
|
|
112
105
|
console.log(`🖱️ Scrolled to "${dir}".`);
|
|
113
106
|
// Wait a moment for smooth scroll to finish
|
|
114
107
|
await page.waitForTimeout(500);
|
|
115
|
-
}
|
|
116
|
-
// ===================================================================================
|
|
117
|
-
// MOUSE ACTIONS: HOVERING / MOVEMENT
|
|
118
|
-
// ===================================================================================
|
|
108
|
+
}
|
|
119
109
|
/**
|
|
120
110
|
* Simulates a mouse hover over an element.
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* ```gherkin
|
|
111
|
+
* Sets the hovered element as the "Active Element" for subsequent steps.
|
|
112
|
+
* @example
|
|
124
113
|
* When I hover over the element ".dropdown-toggle"
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
114
|
* @param selector - The CSS selector to hover over.
|
|
128
115
|
*/
|
|
129
|
-
|
|
116
|
+
async function hoverElement(page, selector) {
|
|
130
117
|
const element = page.locator(selector);
|
|
131
118
|
await element.hover();
|
|
132
|
-
// 🔥 Store the hovered element so we can click/assert on it immediately after
|
|
133
119
|
(0, state_1.setActiveElement)(page, element);
|
|
134
120
|
console.log(`🖱️ Hovered over: "${selector}".`);
|
|
135
|
-
}
|
|
121
|
+
}
|
|
136
122
|
/**
|
|
137
123
|
* Moves the mouse cursor to specific absolute screen coordinates.
|
|
138
124
|
* Useful for canvas interactions or testing mouse tracking.
|
|
139
|
-
*
|
|
140
|
-
* ```gherkin
|
|
125
|
+
* @example
|
|
141
126
|
* When I move mouse to coordinates 100, 200
|
|
142
|
-
* ```
|
|
143
|
-
*
|
|
144
127
|
* @param x - The X-coordinate.
|
|
145
128
|
* @param y - The Y-coordinate.
|
|
146
129
|
*/
|
|
147
|
-
|
|
130
|
+
async function moveMouseToCoordinates(page, x, y) {
|
|
148
131
|
await page.mouse.move(x, y);
|
|
149
132
|
console.log(`🧭 Mouse moved to (${x}, ${y}).`);
|
|
150
|
-
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Hovers over the Nth element containing the specified text.
|
|
136
|
+
* @example
|
|
137
|
+
* When I hover on 1st element "Profile"
|
|
138
|
+
* When I hover on 3rd element "Settings"
|
|
139
|
+
* | timeout | 2000 |
|
|
140
|
+
*/
|
|
141
|
+
async function hoverNthElementByText(page, indexStr, text, table) {
|
|
142
|
+
const index = parseInt(indexStr, 10);
|
|
143
|
+
const options = (0, state_1.parseClickOptions)(table);
|
|
144
|
+
const locator = page.getByText(text, { exact: false }).nth(index - 1);
|
|
145
|
+
await locator.waitFor({ state: "visible", timeout: options.timeout || 5000 });
|
|
146
|
+
await locator.hover(options);
|
|
147
|
+
(0, state_1.setActiveElement)(page, locator);
|
|
148
|
+
console.log(`✨ Hovered over ${indexStr} element with text "${text}"`);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Hovers over the Nth element matching a CSS or XPath selector.
|
|
152
|
+
* @example
|
|
153
|
+
* When I hover on 1st selector ".user-avatar"
|
|
154
|
+
*/
|
|
155
|
+
async function hoverNthElementBySelector(page, indexStr, selector, table) {
|
|
156
|
+
const index = parseInt(indexStr, 10);
|
|
157
|
+
const options = (0, state_1.parseClickOptions)(table);
|
|
158
|
+
const locator = page.locator(selector).nth(index - 1);
|
|
159
|
+
await locator.waitFor({ state: "visible", timeout: options.timeout || 5000 });
|
|
160
|
+
await locator.hover(options);
|
|
161
|
+
(0, state_1.setActiveElement)(page, locator);
|
|
162
|
+
console.log(`✨ Hovered over ${indexStr} selector "${selector}"`);
|
|
163
|
+
}
|
|
164
|
+
// ==================================================
|
|
165
|
+
// GLUE STEPS
|
|
166
|
+
// ==================================================
|
|
167
|
+
(0, registry_1.Step)("I scroll {string} into view", scrollIntoView);
|
|
168
|
+
(0, registry_1.Step)("I scroll {string} to position x:{int} y:{int}", scrollElementToPosition);
|
|
169
|
+
(0, registry_1.Step)("I scroll to coordinates x:{int} y:{int}", scrollWindowToCoordinates);
|
|
170
|
+
(0, registry_1.Step)("I scroll mouse window to position top:{int} left:{int}", scrollWindowSmoothly);
|
|
171
|
+
(0, registry_1.Step)("I scroll to {string}", scrollToDirection);
|
|
172
|
+
(0, registry_1.Step)("I hover over the element {string}", hoverElement);
|
|
173
|
+
(0, registry_1.Step)("I move mouse to coordinates {int}, {int}", moveMouseToCoordinates);
|
|
174
|
+
(0, registry_1.Step)(/^I hover on (\d+)(?:st|nd|rd|th) element "([^"]+)"$/, hoverNthElementByText);
|
|
175
|
+
(0, registry_1.Step)(/^I hover on (\d+)(?:st|nd|rd|th) selector "([^"]+)"$/, hoverNthElementBySelector);
|
|
@@ -1,49 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Navigates the browser to a specific absolute URL.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Given I visit "[https://www.google.com](https://www.google.com)"
|
|
6
|
-
* ```
|
|
7
|
-
*
|
|
3
|
+
* @example
|
|
4
|
+
* Given I visit "https://www.google.com"
|
|
8
5
|
* @param url - The full URL string (must include http/https).
|
|
9
6
|
*/
|
|
10
|
-
export declare
|
|
7
|
+
export declare function visitUrl(page: any, url: string): Promise<void>;
|
|
11
8
|
/**
|
|
12
9
|
* Reloads the current page (simulates hitting the Refresh button).
|
|
13
|
-
*
|
|
14
|
-
* ```gherkin
|
|
10
|
+
* @example
|
|
15
11
|
* When I reload the page
|
|
16
|
-
* ```
|
|
17
12
|
*/
|
|
18
|
-
export declare
|
|
13
|
+
export declare function reloadPage(page: any): Promise<void>;
|
|
19
14
|
/**
|
|
20
15
|
* Navigates back one step in the browser history.
|
|
21
16
|
* Simulates clicking the browser's "Back" button.
|
|
22
|
-
*
|
|
23
|
-
* ```gherkin
|
|
17
|
+
* @example
|
|
24
18
|
* When I go back
|
|
25
|
-
* ```
|
|
26
19
|
*/
|
|
27
|
-
export declare
|
|
20
|
+
export declare function goBack(page: any): Promise<void>;
|
|
28
21
|
/**
|
|
29
22
|
* Navigates forward one step in the browser history.
|
|
30
23
|
* Simulates clicking the browser's "Forward" button.
|
|
31
|
-
*
|
|
32
|
-
* ```gherkin
|
|
24
|
+
* @example
|
|
33
25
|
* When I go forward
|
|
34
|
-
* ```
|
|
35
26
|
*/
|
|
36
|
-
export declare
|
|
27
|
+
export declare function goForward(page: any): Promise<void>;
|
|
37
28
|
/**
|
|
38
29
|
* Navigates to a specific path.
|
|
39
30
|
* If a `baseURL` is configured in your Playwright config, this is relative to it.
|
|
40
31
|
* Otherwise, it treats the string as a direct URL.
|
|
41
|
-
*
|
|
42
|
-
* ```gherkin
|
|
32
|
+
* @example
|
|
43
33
|
* When I navigate to "/dashboard/login"
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
34
|
* @param path - The relative path or URL to navigate to.
|
|
47
35
|
*/
|
|
48
|
-
export declare
|
|
36
|
+
export declare function navigateToPath(page: any, path: string): Promise<void>;
|
|
49
37
|
//# sourceMappingURL=navigation.d.ts.map
|