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,98 +1,87 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.pressKey = pressKey;
|
|
4
|
+
exports.pressKeyOnElement = pressKeyOnElement;
|
|
5
|
+
exports.typeKeysGlobal = typeKeysGlobal;
|
|
6
|
+
exports.pressShortcut = pressShortcut;
|
|
7
|
+
exports.holdDownKey = holdDownKey;
|
|
8
|
+
exports.releaseKey = releaseKey;
|
|
4
9
|
const registry_1 = require("../../core/registry");
|
|
5
10
|
const state_1 = require("../utils/state");
|
|
6
11
|
// ==================================================
|
|
7
|
-
//
|
|
12
|
+
// CORE FUNCTIONS
|
|
8
13
|
// ==================================================
|
|
9
14
|
/**
|
|
10
15
|
* Presses a specific key globally on the page.
|
|
11
|
-
* This simulates a user pressing a key without targeting any specific element
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* ```gherkin
|
|
16
|
+
* This simulates a user pressing a key without targeting any specific element.
|
|
17
|
+
* @example
|
|
15
18
|
* When I press key "Enter"
|
|
16
19
|
* When I press key "Escape"
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
20
|
* @param key - The name of the key (e.g., "Enter", "Tab", "ArrowDown").
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
+
async function pressKey(page, key) {
|
|
22
23
|
await page.keyboard.press(key);
|
|
23
24
|
console.log(`⌨️ Pressed key: "${key}"`);
|
|
24
|
-
}
|
|
25
|
+
}
|
|
25
26
|
/**
|
|
26
27
|
* Presses a specific key targeted at the currently stored (active) element.
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* ```gherkin
|
|
28
|
+
* @example
|
|
30
29
|
* When I press key "Enter" on element
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
30
|
* @param key - The name of the key to press.
|
|
34
31
|
*/
|
|
35
|
-
|
|
32
|
+
async function pressKeyOnElement(page, key) {
|
|
36
33
|
const element = (0, state_1.getActiveElement)(page);
|
|
37
34
|
await element.press(key);
|
|
38
35
|
console.log(`⌨️ Pressed key "${key}" on stored element`);
|
|
39
|
-
}
|
|
36
|
+
}
|
|
40
37
|
/**
|
|
41
38
|
* Types text globally using the keyboard, character by character.
|
|
42
|
-
*
|
|
43
|
-
* `keydown`, `keypress`, and `keyup` events for each character.
|
|
44
|
-
*
|
|
45
|
-
* ```gherkin
|
|
39
|
+
* @example
|
|
46
40
|
* When I press keys "Hello World"
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
41
|
* @param text - The string of text to type.
|
|
50
42
|
*/
|
|
51
|
-
|
|
43
|
+
async function typeKeysGlobal(page, text) {
|
|
52
44
|
await page.keyboard.type(text);
|
|
53
45
|
console.log(`⌨️ Typed keys: "${text}"`);
|
|
54
|
-
}
|
|
46
|
+
}
|
|
55
47
|
/**
|
|
56
48
|
* Performs a specific keyboard shortcut or combination.
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* ```gherkin
|
|
49
|
+
* @example
|
|
60
50
|
* When I press shortcut "Control+C"
|
|
61
51
|
* When I press shortcut "Meta+Shift+P"
|
|
62
|
-
* ```
|
|
63
|
-
*
|
|
64
52
|
* @param shortcut - The key combination string (e.g., "Control+V").
|
|
65
53
|
*/
|
|
66
|
-
|
|
67
|
-
// Playwright's keyboard.press supports combinations like "Control+KeyC"
|
|
54
|
+
async function pressShortcut(page, shortcut) {
|
|
68
55
|
await page.keyboard.press(shortcut);
|
|
69
56
|
console.log(`⌨️ Performed shortcut: "${shortcut}"`);
|
|
70
|
-
}
|
|
57
|
+
}
|
|
71
58
|
/**
|
|
72
59
|
* Holds down a specific key.
|
|
73
60
|
* Useful for operations like multiple selections (holding Shift) or drag-and-drop.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* ```gherkin
|
|
61
|
+
* @example
|
|
77
62
|
* When I hold down key "Shift"
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
63
|
* @param key - The name of the key to hold down.
|
|
81
64
|
*/
|
|
82
|
-
|
|
65
|
+
async function holdDownKey(page, key) {
|
|
83
66
|
await page.keyboard.down(key);
|
|
84
67
|
console.log(`⬇️ Holding down key: "${key}"`);
|
|
85
|
-
}
|
|
68
|
+
}
|
|
86
69
|
/**
|
|
87
70
|
* Releases a specific key that was previously held down.
|
|
88
|
-
*
|
|
89
|
-
* ```gherkin
|
|
71
|
+
* @example
|
|
90
72
|
* When I release key "Shift"
|
|
91
|
-
* ```
|
|
92
|
-
*
|
|
93
73
|
* @param key - The name of the key to release.
|
|
94
74
|
*/
|
|
95
|
-
|
|
75
|
+
async function releaseKey(page, key) {
|
|
96
76
|
await page.keyboard.up(key);
|
|
97
77
|
console.log(`⬆️ Released key: "${key}"`);
|
|
98
|
-
}
|
|
78
|
+
}
|
|
79
|
+
// ==================================================
|
|
80
|
+
// GLUE STEPS
|
|
81
|
+
// ==================================================
|
|
82
|
+
(0, registry_1.Step)("I press key {string}", pressKey);
|
|
83
|
+
(0, registry_1.Step)("I press key {string} on element", pressKeyOnElement);
|
|
84
|
+
(0, registry_1.Step)("I press keys {string}", typeKeysGlobal);
|
|
85
|
+
(0, registry_1.Step)("I press shortcut {string}", pressShortcut);
|
|
86
|
+
(0, registry_1.Step)("I hold down key {string}", holdDownKey);
|
|
87
|
+
(0, registry_1.Step)("I release key {string}", releaseKey);
|
|
@@ -1,135 +1,95 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pauses execution for a specified number of milliseconds.
|
|
3
|
-
*
|
|
4
|
-
* ```gherkin
|
|
3
|
+
* @example
|
|
5
4
|
* When I wait for 1000 milliseconds
|
|
6
|
-
* ```
|
|
7
|
-
*
|
|
8
5
|
* @param ms - The duration to wait in milliseconds.
|
|
9
|
-
* @remarks
|
|
10
|
-
* **Note:** Use sparse waits to avoid flaky tests. Prefer explicit waits like `I wait for element to be visible`.
|
|
11
6
|
*/
|
|
12
|
-
export declare
|
|
7
|
+
export declare function waitMilliseconds(page: any, ms: number): Promise<void>;
|
|
13
8
|
/**
|
|
14
9
|
* Pauses execution for a specified number of seconds.
|
|
15
|
-
*
|
|
16
|
-
* ```gherkin
|
|
10
|
+
* @example
|
|
17
11
|
* When I wait for 5 seconds
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
12
|
* @param seconds - The duration to wait in seconds.
|
|
21
13
|
*/
|
|
22
|
-
export declare
|
|
14
|
+
export declare function waitSeconds(page: any, seconds: number): Promise<void>;
|
|
23
15
|
/**
|
|
24
16
|
* Pauses the test execution and opens the Playwright Inspector.
|
|
25
|
-
*
|
|
26
|
-
* You can inspect elements, view console logs, and step through execution.
|
|
27
|
-
*
|
|
28
|
-
* ```gherkin
|
|
17
|
+
* @example
|
|
29
18
|
* When I pause
|
|
30
|
-
* ```
|
|
31
19
|
*/
|
|
32
|
-
export declare
|
|
20
|
+
export declare function pauseExecution(page: any): Promise<void>;
|
|
33
21
|
/**
|
|
34
|
-
* Alias for
|
|
35
|
-
*
|
|
36
|
-
* ```gherkin
|
|
22
|
+
* Alias for pauseExecution. Pauses execution for debugging.
|
|
23
|
+
* @example
|
|
37
24
|
* When I debug
|
|
38
|
-
* ```
|
|
39
25
|
*/
|
|
40
|
-
export declare
|
|
26
|
+
export declare function debugExecution(page: any): Promise<void>;
|
|
41
27
|
/**
|
|
42
28
|
* Prints a custom message to the console logs.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* ```gherkin
|
|
29
|
+
* @example
|
|
46
30
|
* When I log "Starting Login Flow"
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
31
|
* @param message - The string to log.
|
|
50
32
|
*/
|
|
51
|
-
export declare
|
|
33
|
+
export declare function logMessage(page: any, message: string): Promise<void>;
|
|
52
34
|
/**
|
|
53
35
|
* Focuses on the currently stored (active) element.
|
|
54
|
-
*
|
|
55
|
-
* ```gherkin
|
|
36
|
+
* @example
|
|
56
37
|
* When I focus
|
|
57
|
-
* ```
|
|
58
38
|
*/
|
|
59
|
-
export declare
|
|
39
|
+
export declare function focusElement(page: any): Promise<void>;
|
|
60
40
|
/**
|
|
61
41
|
* Blurs (removes focus from) the currently stored element.
|
|
62
|
-
*
|
|
63
|
-
* ```gherkin
|
|
42
|
+
* @example
|
|
64
43
|
* When I blur
|
|
65
|
-
* ```
|
|
66
44
|
*/
|
|
67
|
-
export declare
|
|
45
|
+
export declare function blurElement(page: any): Promise<void>;
|
|
68
46
|
/**
|
|
69
47
|
* Sets a cookie for the current context/URL.
|
|
70
|
-
*
|
|
71
|
-
* ```gherkin
|
|
48
|
+
* @example
|
|
72
49
|
* When I set cookie "session_id" to "12345ABC"
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
50
|
* @param name - The name of the cookie.
|
|
76
51
|
* @param value - The value of the cookie.
|
|
77
52
|
*/
|
|
78
|
-
export declare
|
|
53
|
+
export declare function setCookie(page: any, name: string, value: string): Promise<void>;
|
|
79
54
|
/**
|
|
80
55
|
* Clears all cookies for the current browser context.
|
|
81
|
-
*
|
|
82
|
-
* ```gherkin
|
|
56
|
+
* @example
|
|
83
57
|
* When I clear all cookies
|
|
84
|
-
* ```
|
|
85
58
|
*/
|
|
86
|
-
export declare
|
|
59
|
+
export declare function clearAllCookies(page: any): Promise<void>;
|
|
87
60
|
/**
|
|
88
61
|
* Sets an item in Local Storage.
|
|
89
|
-
*
|
|
90
|
-
* ```gherkin
|
|
62
|
+
* @example
|
|
91
63
|
* When I set local storage item "theme" to "dark"
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
64
|
* @param key - The local storage key.
|
|
95
65
|
* @param value - The value to store.
|
|
96
66
|
*/
|
|
97
|
-
export declare
|
|
67
|
+
export declare function setLocalStorageItem(page: any, key: string, value: string): Promise<void>;
|
|
98
68
|
/**
|
|
99
69
|
* Retrieves a Local Storage item and logs it to the console.
|
|
100
|
-
*
|
|
101
|
-
* ```gherkin
|
|
70
|
+
* @example
|
|
102
71
|
* When I get local storage item "authToken"
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
72
|
* @param key - The key of the item to retrieve.
|
|
106
73
|
*/
|
|
107
|
-
export declare
|
|
74
|
+
export declare function getLocalStorageItem(page: any, key: string): Promise<void>;
|
|
108
75
|
/**
|
|
109
76
|
* Clears all data from Local Storage.
|
|
110
|
-
*
|
|
111
|
-
* ```gherkin
|
|
77
|
+
* @example
|
|
112
78
|
* When I clear local storage
|
|
113
|
-
* ```
|
|
114
79
|
*/
|
|
115
|
-
export declare
|
|
80
|
+
export declare function clearLocalStorage(page: any): Promise<void>;
|
|
116
81
|
/**
|
|
117
82
|
* Sets an item in Session Storage.
|
|
118
|
-
*
|
|
119
|
-
* ```gherkin
|
|
83
|
+
* @example
|
|
120
84
|
* When I set session storage item "user_role" to "admin"
|
|
121
|
-
* ```
|
|
122
|
-
*
|
|
123
85
|
* @param key - The session storage key.
|
|
124
86
|
* @param value - The value to store.
|
|
125
87
|
*/
|
|
126
|
-
export declare
|
|
88
|
+
export declare function setSessionStorageItem(page: any, key: string, value: string): Promise<void>;
|
|
127
89
|
/**
|
|
128
90
|
* Clears all data from Session Storage.
|
|
129
|
-
*
|
|
130
|
-
* ```gherkin
|
|
91
|
+
* @example
|
|
131
92
|
* When I clear session storage
|
|
132
|
-
* ```
|
|
133
93
|
*/
|
|
134
|
-
export declare
|
|
94
|
+
export declare function clearSessionStorage(page: any): Promise<void>;
|
|
135
95
|
//# sourceMappingURL=misc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/misc.ts"],"names":[],"mappings":"AAOA
|
|
1
|
+
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/misc.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3E;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3E;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7D;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAG7D;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1E;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAI3D;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAM1D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAKrF;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAI9D;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM9F;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG/E;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhE;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMhG;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAGlE"}
|
|
@@ -1,208 +1,187 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.waitMilliseconds = waitMilliseconds;
|
|
4
|
+
exports.waitSeconds = waitSeconds;
|
|
5
|
+
exports.pauseExecution = pauseExecution;
|
|
6
|
+
exports.debugExecution = debugExecution;
|
|
7
|
+
exports.logMessage = logMessage;
|
|
8
|
+
exports.focusElement = focusElement;
|
|
9
|
+
exports.blurElement = blurElement;
|
|
10
|
+
exports.setCookie = setCookie;
|
|
11
|
+
exports.clearAllCookies = clearAllCookies;
|
|
12
|
+
exports.setLocalStorageItem = setLocalStorageItem;
|
|
13
|
+
exports.getLocalStorageItem = getLocalStorageItem;
|
|
14
|
+
exports.clearLocalStorage = clearLocalStorage;
|
|
15
|
+
exports.setSessionStorageItem = setSessionStorageItem;
|
|
16
|
+
exports.clearSessionStorage = clearSessionStorage;
|
|
4
17
|
const registry_1 = require("../../core/registry");
|
|
5
18
|
const state_1 = require("../utils/state");
|
|
6
19
|
// ==================================================
|
|
7
|
-
//
|
|
20
|
+
// CORE FUNCTIONS
|
|
8
21
|
// ==================================================
|
|
9
22
|
/**
|
|
10
23
|
* Pauses execution for a specified number of milliseconds.
|
|
11
|
-
*
|
|
12
|
-
* ```gherkin
|
|
24
|
+
* @example
|
|
13
25
|
* When I wait for 1000 milliseconds
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
26
|
* @param ms - The duration to wait in milliseconds.
|
|
17
|
-
* @remarks
|
|
18
|
-
* **Note:** Use sparse waits to avoid flaky tests. Prefer explicit waits like `I wait for element to be visible`.
|
|
19
27
|
*/
|
|
20
|
-
|
|
28
|
+
async function waitMilliseconds(page, ms) {
|
|
21
29
|
await page.waitForTimeout(ms);
|
|
22
30
|
console.log(`⏳ Waited for ${ms}ms`);
|
|
23
|
-
}
|
|
31
|
+
}
|
|
24
32
|
/**
|
|
25
33
|
* Pauses execution for a specified number of seconds.
|
|
26
|
-
*
|
|
27
|
-
* ```gherkin
|
|
34
|
+
* @example
|
|
28
35
|
* When I wait for 5 seconds
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
36
|
* @param seconds - The duration to wait in seconds.
|
|
32
37
|
*/
|
|
33
|
-
|
|
38
|
+
async function waitSeconds(page, seconds) {
|
|
34
39
|
await page.waitForTimeout(seconds * 1000);
|
|
35
40
|
console.log(`⏳ Waited for ${seconds}s`);
|
|
36
|
-
}
|
|
37
|
-
// ==================================================
|
|
38
|
-
// 2. DEBUGGING
|
|
39
|
-
// ==================================================
|
|
41
|
+
}
|
|
40
42
|
/**
|
|
41
43
|
* Pauses the test execution and opens the Playwright Inspector.
|
|
42
|
-
*
|
|
43
|
-
* You can inspect elements, view console logs, and step through execution.
|
|
44
|
-
*
|
|
45
|
-
* ```gherkin
|
|
44
|
+
* @example
|
|
46
45
|
* When I pause
|
|
47
|
-
* ```
|
|
48
46
|
*/
|
|
49
|
-
|
|
47
|
+
async function pauseExecution(page) {
|
|
50
48
|
console.log("⏸️ Pausing test execution...");
|
|
51
49
|
await page.pause();
|
|
52
|
-
}
|
|
50
|
+
}
|
|
53
51
|
/**
|
|
54
|
-
* Alias for
|
|
55
|
-
*
|
|
56
|
-
* ```gherkin
|
|
52
|
+
* Alias for pauseExecution. Pauses execution for debugging.
|
|
53
|
+
* @example
|
|
57
54
|
* When I debug
|
|
58
|
-
* ```
|
|
59
55
|
*/
|
|
60
|
-
|
|
56
|
+
async function debugExecution(page) {
|
|
61
57
|
console.log("🐞 Debugging...");
|
|
62
58
|
await page.pause();
|
|
63
|
-
}
|
|
59
|
+
}
|
|
64
60
|
/**
|
|
65
61
|
* Prints a custom message to the console logs.
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* ```gherkin
|
|
62
|
+
* @example
|
|
69
63
|
* When I log "Starting Login Flow"
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
64
|
* @param message - The string to log.
|
|
73
65
|
*/
|
|
74
|
-
|
|
66
|
+
async function logMessage(page, message) {
|
|
75
67
|
console.log(`📝 LOG: ${message}`);
|
|
76
|
-
}
|
|
77
|
-
// ==================================================
|
|
78
|
-
// 3. FOCUS & BLUR
|
|
79
|
-
// ==================================================
|
|
68
|
+
}
|
|
80
69
|
/**
|
|
81
70
|
* Focuses on the currently stored (active) element.
|
|
82
|
-
*
|
|
83
|
-
* ```gherkin
|
|
71
|
+
* @example
|
|
84
72
|
* When I focus
|
|
85
|
-
* ```
|
|
86
73
|
*/
|
|
87
|
-
|
|
74
|
+
async function focusElement(page) {
|
|
88
75
|
const element = (0, state_1.getActiveElement)(page);
|
|
89
76
|
await element.focus();
|
|
90
77
|
console.log("👀 Focused on stored element");
|
|
91
|
-
}
|
|
78
|
+
}
|
|
92
79
|
/**
|
|
93
80
|
* Blurs (removes focus from) the currently stored element.
|
|
94
|
-
*
|
|
95
|
-
* ```gherkin
|
|
81
|
+
* @example
|
|
96
82
|
* When I blur
|
|
97
|
-
* ```
|
|
98
83
|
*/
|
|
99
|
-
|
|
84
|
+
async function blurElement(page) {
|
|
100
85
|
const element = (0, state_1.getActiveElement)(page);
|
|
101
|
-
// Playwright doesn't have a direct .blur(), so we use JS evaluation
|
|
102
86
|
await element.evaluate((el) => {
|
|
103
87
|
if (el instanceof HTMLElement)
|
|
104
88
|
el.blur();
|
|
105
89
|
});
|
|
106
90
|
console.log("🌫️ Blurred stored element");
|
|
107
|
-
}
|
|
108
|
-
// ==================================================
|
|
109
|
-
// 4. BROWSER STORAGE (Cookies / Local Storage)
|
|
110
|
-
// ==================================================
|
|
91
|
+
}
|
|
111
92
|
/**
|
|
112
93
|
* Sets a cookie for the current context/URL.
|
|
113
|
-
*
|
|
114
|
-
* ```gherkin
|
|
94
|
+
* @example
|
|
115
95
|
* When I set cookie "session_id" to "12345ABC"
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
96
|
* @param name - The name of the cookie.
|
|
119
97
|
* @param value - The value of the cookie.
|
|
120
98
|
*/
|
|
121
|
-
|
|
99
|
+
async function setCookie(page, name, value) {
|
|
122
100
|
const context = page.context();
|
|
123
101
|
const url = page.url();
|
|
124
|
-
// We need a domain or url to set cookies. We use the current page URL.
|
|
125
102
|
await context.addCookies([{ name, value, url }]);
|
|
126
103
|
console.log(`🍪 Set cookie "${name}"`);
|
|
127
|
-
}
|
|
104
|
+
}
|
|
128
105
|
/**
|
|
129
106
|
* Clears all cookies for the current browser context.
|
|
130
|
-
*
|
|
131
|
-
* ```gherkin
|
|
107
|
+
* @example
|
|
132
108
|
* When I clear all cookies
|
|
133
|
-
* ```
|
|
134
109
|
*/
|
|
135
|
-
|
|
110
|
+
async function clearAllCookies(page) {
|
|
136
111
|
const context = page.context();
|
|
137
112
|
await context.clearCookies();
|
|
138
113
|
console.log("🍪 Cleared all cookies");
|
|
139
|
-
}
|
|
114
|
+
}
|
|
140
115
|
/**
|
|
141
116
|
* Sets an item in Local Storage.
|
|
142
|
-
*
|
|
143
|
-
* ```gherkin
|
|
117
|
+
* @example
|
|
144
118
|
* When I set local storage item "theme" to "dark"
|
|
145
|
-
* ```
|
|
146
|
-
*
|
|
147
119
|
* @param key - The local storage key.
|
|
148
120
|
* @param value - The value to store.
|
|
149
121
|
*/
|
|
150
|
-
|
|
151
|
-
await page.evaluate((
|
|
122
|
+
async function setLocalStorageItem(page, key, value) {
|
|
123
|
+
await page.evaluate((args) => localStorage.setItem(args.k, args.v), {
|
|
152
124
|
k: key,
|
|
153
125
|
v: value,
|
|
154
126
|
});
|
|
155
127
|
console.log(`📦 Set local storage "${key}" = "${value}"`);
|
|
156
|
-
}
|
|
128
|
+
}
|
|
157
129
|
/**
|
|
158
130
|
* Retrieves a Local Storage item and logs it to the console.
|
|
159
|
-
*
|
|
160
|
-
* ```gherkin
|
|
131
|
+
* @example
|
|
161
132
|
* When I get local storage item "authToken"
|
|
162
|
-
* ```
|
|
163
|
-
*
|
|
164
133
|
* @param key - The key of the item to retrieve.
|
|
165
134
|
*/
|
|
166
|
-
|
|
135
|
+
async function getLocalStorageItem(page, key) {
|
|
167
136
|
const value = await page.evaluate((k) => localStorage.getItem(k), key);
|
|
168
137
|
console.log(`📦 Local Storage "${key}": ${value}`);
|
|
169
|
-
}
|
|
138
|
+
}
|
|
170
139
|
/**
|
|
171
140
|
* Clears all data from Local Storage.
|
|
172
|
-
*
|
|
173
|
-
* ```gherkin
|
|
141
|
+
* @example
|
|
174
142
|
* When I clear local storage
|
|
175
|
-
* ```
|
|
176
143
|
*/
|
|
177
|
-
|
|
144
|
+
async function clearLocalStorage(page) {
|
|
178
145
|
await page.evaluate(() => localStorage.clear());
|
|
179
146
|
console.log("📦 Cleared local storage");
|
|
180
|
-
}
|
|
147
|
+
}
|
|
181
148
|
/**
|
|
182
149
|
* Sets an item in Session Storage.
|
|
183
|
-
*
|
|
184
|
-
* ```gherkin
|
|
150
|
+
* @example
|
|
185
151
|
* When I set session storage item "user_role" to "admin"
|
|
186
|
-
* ```
|
|
187
|
-
*
|
|
188
152
|
* @param key - The session storage key.
|
|
189
153
|
* @param value - The value to store.
|
|
190
154
|
*/
|
|
191
|
-
|
|
192
|
-
await page.evaluate((
|
|
155
|
+
async function setSessionStorageItem(page, key, value) {
|
|
156
|
+
await page.evaluate((args) => sessionStorage.setItem(args.k, args.v), {
|
|
193
157
|
k: key,
|
|
194
158
|
v: value,
|
|
195
159
|
});
|
|
196
160
|
console.log(`📦 Set session storage "${key}" = "${value}"`);
|
|
197
|
-
}
|
|
161
|
+
}
|
|
198
162
|
/**
|
|
199
163
|
* Clears all data from Session Storage.
|
|
200
|
-
*
|
|
201
|
-
* ```gherkin
|
|
164
|
+
* @example
|
|
202
165
|
* When I clear session storage
|
|
203
|
-
* ```
|
|
204
166
|
*/
|
|
205
|
-
|
|
167
|
+
async function clearSessionStorage(page) {
|
|
206
168
|
await page.evaluate(() => sessionStorage.clear());
|
|
207
169
|
console.log("📦 Cleared session storage");
|
|
208
|
-
}
|
|
170
|
+
}
|
|
171
|
+
// ==================================================
|
|
172
|
+
// GLUE STEPS
|
|
173
|
+
// ==================================================
|
|
174
|
+
(0, registry_1.Step)("I wait for {int} milliseconds", waitMilliseconds);
|
|
175
|
+
(0, registry_1.Step)("I wait for {int} seconds", waitSeconds);
|
|
176
|
+
(0, registry_1.Step)("I pause", pauseExecution);
|
|
177
|
+
(0, registry_1.Step)("I debug", debugExecution);
|
|
178
|
+
(0, registry_1.Step)("I log {string}", logMessage);
|
|
179
|
+
(0, registry_1.Step)("I focus", focusElement);
|
|
180
|
+
(0, registry_1.Step)("I blur", blurElement);
|
|
181
|
+
(0, registry_1.Step)("I set cookie {string} to {string}", setCookie);
|
|
182
|
+
(0, registry_1.Step)("I clear all cookies", clearAllCookies);
|
|
183
|
+
(0, registry_1.Step)("I set local storage item {string} to {string}", setLocalStorageItem);
|
|
184
|
+
(0, registry_1.Step)("I get local storage item {string}", getLocalStorageItem);
|
|
185
|
+
(0, registry_1.Step)("I clear local storage", clearLocalStorage);
|
|
186
|
+
(0, registry_1.Step)("I set session storage item {string} to {string}", setSessionStorageItem);
|
|
187
|
+
(0, registry_1.Step)("I clear session storage", clearSessionStorage);
|