playwright-cucumber-ts-steps 1.1.8 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/dist/backend/actions/click.d.ts +132 -1
  3. package/dist/backend/actions/click.d.ts.map +1 -1
  4. package/dist/backend/actions/click.js +122 -53
  5. package/dist/backend/actions/find.d.ts +243 -1
  6. package/dist/backend/actions/find.d.ts.map +1 -1
  7. package/dist/backend/actions/find.js +196 -72
  8. package/dist/backend/actions/form.d.ts +37 -1
  9. package/dist/backend/actions/form.d.ts.map +1 -1
  10. package/dist/backend/actions/form.js +55 -3
  11. package/dist/backend/actions/formTable.d.ts +25 -1
  12. package/dist/backend/actions/formTable.d.ts.map +1 -1
  13. package/dist/backend/actions/formTable.js +27 -5
  14. package/dist/backend/actions/frames.d.ts +53 -1
  15. package/dist/backend/actions/frames.d.ts.map +1 -1
  16. package/dist/backend/actions/frames.js +48 -11
  17. package/dist/backend/actions/inputs.d.ts +139 -1
  18. package/dist/backend/actions/inputs.d.ts.map +1 -1
  19. package/dist/backend/actions/inputs.js +113 -43
  20. package/dist/backend/actions/interactions.d.ts +61 -1
  21. package/dist/backend/actions/interactions.d.ts.map +1 -1
  22. package/dist/backend/actions/interactions.js +65 -10
  23. package/dist/backend/actions/keyboard.d.ts +70 -1
  24. package/dist/backend/actions/keyboard.d.ts.map +1 -1
  25. package/dist/backend/actions/keyboard.js +59 -23
  26. package/dist/backend/actions/misc.d.ts +134 -1
  27. package/dist/backend/actions/misc.d.ts.map +1 -1
  28. package/dist/backend/actions/misc.js +106 -42
  29. package/dist/backend/actions/mobile.d.ts +74 -1
  30. package/dist/backend/actions/mobile.d.ts.map +1 -1
  31. package/dist/backend/actions/mobile.js +74 -13
  32. package/dist/backend/actions/mouse.d.ts +79 -1
  33. package/dist/backend/actions/mouse.d.ts.map +1 -1
  34. package/dist/backend/actions/mouse.js +66 -21
  35. package/dist/backend/actions/navigation.d.ts +48 -1
  36. package/dist/backend/actions/navigation.d.ts.map +1 -1
  37. package/dist/backend/actions/navigation.js +42 -15
  38. package/dist/backend/actions/waits.d.ts +55 -1
  39. package/dist/backend/actions/waits.d.ts.map +1 -1
  40. package/dist/backend/actions/waits.js +49 -17
  41. package/dist/backend/api/assertions.d.ts +32 -1
  42. package/dist/backend/api/assertions.d.ts.map +1 -1
  43. package/dist/backend/api/assertions.js +37 -9
  44. package/dist/backend/api/mock.d.ts +34 -1
  45. package/dist/backend/api/mock.d.ts.map +1 -1
  46. package/dist/backend/api/mock.js +37 -10
  47. package/dist/backend/api/network.d.ts +60 -1
  48. package/dist/backend/api/network.d.ts.map +1 -1
  49. package/dist/backend/api/network.js +53 -21
  50. package/dist/backend/api/requests.d.ts +43 -1
  51. package/dist/backend/api/requests.d.ts.map +1 -1
  52. package/dist/backend/api/requests.js +49 -17
  53. package/dist/backend/assertions/pageState.d.ts +40 -1
  54. package/dist/backend/assertions/pageState.d.ts.map +1 -1
  55. package/dist/backend/assertions/pageState.js +33 -12
  56. package/dist/backend/assertions/text.d.ts +46 -1
  57. package/dist/backend/assertions/text.d.ts.map +1 -1
  58. package/dist/backend/assertions/text.js +51 -8
  59. package/dist/backend/assertions/visibility.d.ts +102 -1
  60. package/dist/backend/assertions/visibility.d.ts.map +1 -1
  61. package/dist/backend/assertions/visibility.js +86 -36
  62. package/dist/backend/auth/index.js +2 -2
  63. package/dist/backend/db/steps.d.ts +35 -1
  64. package/dist/backend/db/steps.d.ts.map +1 -1
  65. package/dist/backend/db/steps.js +48 -15
  66. package/dist/backend/elements/alerts.d.ts +35 -1
  67. package/dist/backend/elements/alerts.d.ts.map +1 -1
  68. package/dist/backend/elements/alerts.js +39 -6
  69. package/dist/backend/elements/forms.d.ts +44 -1
  70. package/dist/backend/elements/forms.d.ts.map +1 -1
  71. package/dist/backend/elements/forms.js +50 -11
  72. package/dist/backend/elements/frames.d.ts +36 -1
  73. package/dist/backend/elements/frames.d.ts.map +1 -1
  74. package/dist/backend/elements/frames.js +43 -13
  75. package/dist/core/runner.d.ts.map +1 -1
  76. package/dist/core/runner.js +3 -4
  77. package/package.json +51 -12
@@ -1,23 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HardWait = exports.PressKeyGlobal = exports.FillElement = exports.ForceClickElement = exports.ClickElement = void 0;
3
4
  const registry_1 = require("../../core/registry");
4
- // Click
5
- (0, registry_1.Step)("I click {string}", async (page, selector) => {
5
+ // =============================
6
+ // BASIC INTERACTIONS (Direct)
7
+ // =============================
8
+ /**
9
+ * Performs a standard click on the element matching the selector.
10
+ *
11
+ * ```gherkin
12
+ * When I click "#submit-button"
13
+ * ```
14
+ *
15
+ * @param selector - The CSS or XPath selector of the element to click.
16
+ */
17
+ exports.ClickElement = (0, registry_1.Step)("I click {string}", async (page, selector) => {
6
18
  await page.click(selector);
7
19
  });
8
- // Force Click (sometimes needed for stubborn elements)
9
- (0, registry_1.Step)("I force click {string}", async (page, selector) => {
20
+ /**
21
+ * Performs a forced click on the element, bypassing visibility checks.
22
+ * Useful for elements obscured by overlays or technically "hidden" but interactable.
23
+ *
24
+ * ```gherkin
25
+ * When I force click "#hidden-checkbox"
26
+ * ```
27
+ *
28
+ * @param selector - The CSS or XPath selector.
29
+ * @remarks
30
+ * **Warning:** Use this sparingly. It disables Playwright's "actionability" checks,
31
+ * meaning it might click an element that a real user technically cannot click.
32
+ */
33
+ exports.ForceClickElement = (0, registry_1.Step)("I force click {string}", async (page, selector) => {
10
34
  await page.click(selector, { force: true });
11
35
  });
12
- // Type/Fill
13
- (0, registry_1.Step)("I fill {string} with {string}", async (page, selector, value) => {
36
+ /**
37
+ * Fills an input field with the specified value.
38
+ *
39
+ * ```gherkin
40
+ * When I fill "#username" with "testuser"
41
+ * ```
42
+ *
43
+ * @param selector - The CSS selector of the input field.
44
+ * @param value - The text value to type/fill.
45
+ */
46
+ exports.FillElement = (0, registry_1.Step)("I fill {string} with {string}", async (page, selector, value) => {
14
47
  await page.fill(selector, value);
15
48
  });
16
- // Press Key (e.g., "Enter")
17
- (0, registry_1.Step)("I press {string}", async (page, key) => {
49
+ /**
50
+ * Presses a specific key on the keyboard globally.
51
+ * Useful for submitting forms (Enter) or closing modals (Escape).
52
+ *
53
+ * ```gherkin
54
+ * When I press "Enter"
55
+ * When I press "Escape"
56
+ * ```
57
+ *
58
+ * @param key - The name of the key (e.g., "Enter", "Tab", "ArrowDown").
59
+ */
60
+ exports.PressKeyGlobal = (0, registry_1.Step)("I press {string}", async (page, key) => {
18
61
  await page.keyboard.press(key);
19
62
  });
20
- // Wait (Hard wait - use sparingly!)
21
- (0, registry_1.Step)("I wait for {int} milliseconds", async (page, ms) => {
63
+ /**
64
+ * Pauses the test execution for a fixed amount of time.
65
+ *
66
+ * ```gherkin
67
+ * When I wait for 5000 milliseconds
68
+ * ```
69
+ *
70
+ * @param ms - The duration to wait in milliseconds.
71
+ * @remarks
72
+ * **Anti-Pattern Warning:** Avoid using hard waits whenever possible.
73
+ * They make tests slower and flaky. Prefer `I wait for element to be visible`
74
+ * or `I wait for network idle` instead.
75
+ */
76
+ exports.HardWait = (0, registry_1.Step)("I wait for {int} milliseconds", async (page, ms) => {
22
77
  await page.waitForTimeout(ms);
23
78
  });
@@ -1,2 +1,71 @@
1
- export {};
1
+ /**
2
+ * Presses a specific key globally on the page.
3
+ * This simulates a user pressing a key without targeting any specific element,
4
+ * although the event will be delivered to the currently focused element.
5
+ *
6
+ * ```gherkin
7
+ * When I press key "Enter"
8
+ * When I press key "Escape"
9
+ * ```
10
+ *
11
+ * @param key - The name of the key (e.g., "Enter", "Tab", "ArrowDown").
12
+ */
13
+ export declare const PressKey: void;
14
+ /**
15
+ * Presses a specific key targeted at the currently stored (active) element.
16
+ * This ensures the element is focused before the key is pressed.
17
+ *
18
+ * ```gherkin
19
+ * When I press key "Enter" on element
20
+ * ```
21
+ *
22
+ * @param key - The name of the key to press.
23
+ */
24
+ export declare const PressKeyOnElement: void;
25
+ /**
26
+ * Types text globally using the keyboard, character by character.
27
+ * This acts like a real user typing on a physical keyboard, sending
28
+ * `keydown`, `keypress`, and `keyup` events for each character.
29
+ *
30
+ * ```gherkin
31
+ * When I press keys "Hello World"
32
+ * ```
33
+ *
34
+ * @param text - The string of text to type.
35
+ */
36
+ export declare const TypeKeysGlobal: void;
37
+ /**
38
+ * Performs a specific keyboard shortcut or combination.
39
+ * Playwright supports combinations using the "+" delimiter.
40
+ *
41
+ * ```gherkin
42
+ * When I press shortcut "Control+C"
43
+ * When I press shortcut "Meta+Shift+P"
44
+ * ```
45
+ *
46
+ * @param shortcut - The key combination string (e.g., "Control+V").
47
+ */
48
+ export declare const PressShortcut: void;
49
+ /**
50
+ * Holds down a specific key.
51
+ * Useful for operations like multiple selections (holding Shift) or drag-and-drop.
52
+ * **Important:** You must release the key later using `I release key`.
53
+ *
54
+ * ```gherkin
55
+ * When I hold down key "Shift"
56
+ * ```
57
+ *
58
+ * @param key - The name of the key to hold down.
59
+ */
60
+ export declare const HoldDownKey: void;
61
+ /**
62
+ * Releases a specific key that was previously held down.
63
+ *
64
+ * ```gherkin
65
+ * When I release key "Shift"
66
+ * ```
67
+ *
68
+ * @param key - The name of the key to release.
69
+ */
70
+ export declare const ReleaseKey: void;
2
71
  //# sourceMappingURL=keyboard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/keyboard.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/keyboard.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,MAGnB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,MAI5B,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,MAGzB,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,MAIxB,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,MAGtB,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,MAGrB,CAAC"}
@@ -1,62 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReleaseKey = exports.HoldDownKey = exports.PressShortcut = exports.TypeKeysGlobal = exports.PressKeyOnElement = exports.PressKey = void 0;
3
4
  const registry_1 = require("../../core/registry");
4
5
  const state_1 = require("../utils/state");
5
6
  // ==================================================
6
7
  // KEYBOARD INTERACTIONS
7
8
  // ==================================================
8
9
  /**
9
- * Presses a specific key globally (on the page).
10
- * Useful for global shortcuts like closing modals (Escape) or scrolling (PageDown).
11
- * Pattern: When I press key "Enter"
10
+ * Presses a specific key globally on the page.
11
+ * This simulates a user pressing a key without targeting any specific element,
12
+ * although the event will be delivered to the currently focused element.
13
+ *
14
+ * ```gherkin
15
+ * When I press key "Enter"
16
+ * When I press key "Escape"
17
+ * ```
18
+ *
19
+ * @param key - The name of the key (e.g., "Enter", "Tab", "ArrowDown").
12
20
  */
13
- (0, registry_1.Step)("I press key {string}", async (page, key) => {
21
+ exports.PressKey = (0, registry_1.Step)("I press key {string}", async (page, key) => {
14
22
  await page.keyboard.press(key);
15
23
  console.log(`⌨️ Pressed key: "${key}"`);
16
24
  });
17
25
  /**
18
- * Presses a key on the currently stored/active element.
19
- * Useful for input fields or buttons.
20
- * Pattern: When I press key "Enter" on element
26
+ * Presses a specific key targeted at the currently stored (active) element.
27
+ * This ensures the element is focused before the key is pressed.
28
+ *
29
+ * ```gherkin
30
+ * When I press key "Enter" on element
31
+ * ```
32
+ *
33
+ * @param key - The name of the key to press.
21
34
  */
22
- (0, registry_1.Step)("I press key {string} on element", async (page, key) => {
35
+ exports.PressKeyOnElement = (0, registry_1.Step)("I press key {string} on element", async (page, key) => {
23
36
  const element = (0, state_1.getActiveElement)(page);
24
37
  await element.press(key);
25
38
  console.log(`⌨️ Pressed key "${key}" on stored element`);
26
39
  });
27
40
  /**
28
- * Types text directly using the keyboard (global typing).
29
- * Unlike 'I type', this sends keystrokes one by one to the page,
30
- * regardless of which element is focused.
31
- * Pattern: When I press keys "Hello World"
41
+ * Types text globally using the keyboard, character by character.
42
+ * This acts like a real user typing on a physical keyboard, sending
43
+ * `keydown`, `keypress`, and `keyup` events for each character.
44
+ *
45
+ * ```gherkin
46
+ * When I press keys "Hello World"
47
+ * ```
48
+ *
49
+ * @param text - The string of text to type.
32
50
  */
33
- (0, registry_1.Step)("I press keys {string}", async (page, text) => {
51
+ exports.TypeKeysGlobal = (0, registry_1.Step)("I press keys {string}", async (page, text) => {
34
52
  await page.keyboard.type(text);
35
53
  console.log(`⌨️ Typed keys: "${text}"`);
36
54
  });
37
55
  /**
38
- * Performs a keyboard shortcut (e.g., Ctrl+C, Meta+S).
39
- * Pattern: When I press shortcut "Control+C"
56
+ * Performs a specific keyboard shortcut or combination.
57
+ * Playwright supports combinations using the "+" delimiter.
58
+ *
59
+ * ```gherkin
60
+ * When I press shortcut "Control+C"
61
+ * When I press shortcut "Meta+Shift+P"
62
+ * ```
63
+ *
64
+ * @param shortcut - The key combination string (e.g., "Control+V").
40
65
  */
41
- (0, registry_1.Step)("I press shortcut {string}", async (page, shortcut) => {
66
+ exports.PressShortcut = (0, registry_1.Step)("I press shortcut {string}", async (page, shortcut) => {
42
67
  // Playwright's keyboard.press supports combinations like "Control+KeyC"
43
68
  await page.keyboard.press(shortcut);
44
69
  console.log(`⌨️ Performed shortcut: "${shortcut}"`);
45
70
  });
46
71
  /**
47
- * Holds down a specific key (e.g., Shift) for subsequent actions.
48
- * Make sure to release it later!
49
- * Pattern: When I hold down key "Shift"
72
+ * Holds down a specific key.
73
+ * Useful for operations like multiple selections (holding Shift) or drag-and-drop.
74
+ * **Important:** You must release the key later using `I release key`.
75
+ *
76
+ * ```gherkin
77
+ * When I hold down key "Shift"
78
+ * ```
79
+ *
80
+ * @param key - The name of the key to hold down.
50
81
  */
51
- (0, registry_1.Step)("I hold down key {string}", async (page, key) => {
82
+ exports.HoldDownKey = (0, registry_1.Step)("I hold down key {string}", async (page, key) => {
52
83
  await page.keyboard.down(key);
53
84
  console.log(`⬇️ Holding down key: "${key}"`);
54
85
  });
55
86
  /**
56
- * Releases a specific key.
57
- * Pattern: When I release key "Shift"
87
+ * Releases a specific key that was previously held down.
88
+ *
89
+ * ```gherkin
90
+ * When I release key "Shift"
91
+ * ```
92
+ *
93
+ * @param key - The name of the key to release.
58
94
  */
59
- (0, registry_1.Step)("I release key {string}", async (page, key) => {
95
+ exports.ReleaseKey = (0, registry_1.Step)("I release key {string}", async (page, key) => {
60
96
  await page.keyboard.up(key);
61
97
  console.log(`⬆️ Released key: "${key}"`);
62
98
  });
@@ -1,2 +1,135 @@
1
- export {};
1
+ /**
2
+ * Pauses execution for a specified number of milliseconds.
3
+ *
4
+ * ```gherkin
5
+ * When I wait for 1000 milliseconds
6
+ * ```
7
+ *
8
+ * @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
+ */
12
+ export declare const WaitMilliseconds: void;
13
+ /**
14
+ * Pauses execution for a specified number of seconds.
15
+ *
16
+ * ```gherkin
17
+ * When I wait for 5 seconds
18
+ * ```
19
+ *
20
+ * @param seconds - The duration to wait in seconds.
21
+ */
22
+ export declare const WaitSeconds: void;
23
+ /**
24
+ * Pauses the test execution and opens the Playwright Inspector.
25
+ * This is incredibly useful for manual debugging during a test run.
26
+ * You can inspect elements, view console logs, and step through execution.
27
+ *
28
+ * ```gherkin
29
+ * When I pause
30
+ * ```
31
+ */
32
+ export declare const PauseExecution: void;
33
+ /**
34
+ * Alias for `I pause`. Pauses execution for debugging.
35
+ *
36
+ * ```gherkin
37
+ * When I debug
38
+ * ```
39
+ */
40
+ export declare const DebugExecution: void;
41
+ /**
42
+ * Prints a custom message to the console logs.
43
+ * Useful for marking sections of a test output or debugging variable states.
44
+ *
45
+ * ```gherkin
46
+ * When I log "Starting Login Flow"
47
+ * ```
48
+ *
49
+ * @param message - The string to log.
50
+ */
51
+ export declare const LogMessage: void;
52
+ /**
53
+ * Focuses on the currently stored (active) element.
54
+ *
55
+ * ```gherkin
56
+ * When I focus
57
+ * ```
58
+ */
59
+ export declare const FocusElement: void;
60
+ /**
61
+ * Blurs (removes focus from) the currently stored element.
62
+ *
63
+ * ```gherkin
64
+ * When I blur
65
+ * ```
66
+ */
67
+ export declare const BlurElement: void;
68
+ /**
69
+ * Sets a cookie for the current context/URL.
70
+ *
71
+ * ```gherkin
72
+ * When I set cookie "session_id" to "12345ABC"
73
+ * ```
74
+ *
75
+ * @param name - The name of the cookie.
76
+ * @param value - The value of the cookie.
77
+ */
78
+ export declare const SetCookie: void;
79
+ /**
80
+ * Clears all cookies for the current browser context.
81
+ *
82
+ * ```gherkin
83
+ * When I clear all cookies
84
+ * ```
85
+ */
86
+ export declare const ClearAllCookies: void;
87
+ /**
88
+ * Sets an item in Local Storage.
89
+ *
90
+ * ```gherkin
91
+ * When I set local storage item "theme" to "dark"
92
+ * ```
93
+ *
94
+ * @param key - The local storage key.
95
+ * @param value - The value to store.
96
+ */
97
+ export declare const SetLocalStorageItem: void;
98
+ /**
99
+ * Retrieves a Local Storage item and logs it to the console.
100
+ *
101
+ * ```gherkin
102
+ * When I get local storage item "authToken"
103
+ * ```
104
+ *
105
+ * @param key - The key of the item to retrieve.
106
+ */
107
+ export declare const GetLocalStorageItem: void;
108
+ /**
109
+ * Clears all data from Local Storage.
110
+ *
111
+ * ```gherkin
112
+ * When I clear local storage
113
+ * ```
114
+ */
115
+ export declare const ClearLocalStorage: void;
116
+ /**
117
+ * Sets an item in Session Storage.
118
+ *
119
+ * ```gherkin
120
+ * When I set session storage item "user_role" to "admin"
121
+ * ```
122
+ *
123
+ * @param key - The session storage key.
124
+ * @param value - The value to store.
125
+ */
126
+ export declare const SetSessionStorageItem: void;
127
+ /**
128
+ * Clears all data from Session Storage.
129
+ *
130
+ * ```gherkin
131
+ * When I clear session storage
132
+ * ```
133
+ */
134
+ export declare const ClearSessionStorage: void;
2
135
  //# sourceMappingURL=misc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/misc.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../../src/backend/actions/misc.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,MAG3B,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,MAGtB,CAAC;AAMH;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,MAGzB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,MAGzB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,MAErB,CAAC;AAMH;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,MAIvB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,MAOtB,CAAC;AAMH;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,MAMpB,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,MAI1B,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,MAS/B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,MAG9B,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,MAG5B,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,MASjC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,MAG9B,CAAC"}
@@ -1,23 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClearSessionStorage = exports.SetSessionStorageItem = exports.ClearLocalStorage = exports.GetLocalStorageItem = exports.SetLocalStorageItem = exports.ClearAllCookies = exports.SetCookie = exports.BlurElement = exports.FocusElement = exports.LogMessage = exports.DebugExecution = exports.PauseExecution = exports.WaitSeconds = exports.WaitMilliseconds = void 0;
3
4
  const registry_1 = require("../../core/registry");
4
5
  const state_1 = require("../utils/state");
5
6
  // ==================================================
6
7
  // 1. TIMING & WAITS
7
8
  // ==================================================
8
9
  /**
9
- * Pauses execution for a set amount of time.
10
- * Pattern: When I wait for 1000 milliseconds
10
+ * Pauses execution for a specified number of milliseconds.
11
+ *
12
+ * ```gherkin
13
+ * When I wait for 1000 milliseconds
14
+ * ```
15
+ *
16
+ * @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`.
11
19
  */
12
- (0, registry_1.Step)("I wait for {int} milliseconds", async (page, ms) => {
20
+ exports.WaitMilliseconds = (0, registry_1.Step)("I wait for {int} milliseconds", async (page, ms) => {
13
21
  await page.waitForTimeout(ms);
14
22
  console.log(`⏳ Waited for ${ms}ms`);
15
23
  });
16
24
  /**
17
- * Pauses execution for a set amount of seconds.
18
- * Pattern: When I wait for 5 seconds
25
+ * Pauses execution for a specified number of seconds.
26
+ *
27
+ * ```gherkin
28
+ * When I wait for 5 seconds
29
+ * ```
30
+ *
31
+ * @param seconds - The duration to wait in seconds.
19
32
  */
20
- (0, registry_1.Step)("I wait for {int} seconds", async (page, seconds) => {
33
+ exports.WaitSeconds = (0, registry_1.Step)("I wait for {int} seconds", async (page, seconds) => {
21
34
  await page.waitForTimeout(seconds * 1000);
22
35
  console.log(`⏳ Waited for ${seconds}s`);
23
36
  });
@@ -26,45 +39,64 @@ const state_1 = require("../utils/state");
26
39
  // ==================================================
27
40
  /**
28
41
  * Pauses the test execution and opens the Playwright Inspector.
29
- * Useful for manual debugging during a run.
30
- * Pattern: When I pause
42
+ * This is incredibly useful for manual debugging during a test run.
43
+ * You can inspect elements, view console logs, and step through execution.
44
+ *
45
+ * ```gherkin
46
+ * When I pause
47
+ * ```
31
48
  */
32
- (0, registry_1.Step)("I pause", async (page) => {
49
+ exports.PauseExecution = (0, registry_1.Step)("I pause", async (page) => {
33
50
  console.log("⏸️ Pausing test execution...");
34
51
  await page.pause();
35
52
  });
36
53
  /**
37
- * Alias for pause.
38
- * Pattern: When I debug
54
+ * Alias for `I pause`. Pauses execution for debugging.
55
+ *
56
+ * ```gherkin
57
+ * When I debug
58
+ * ```
39
59
  */
40
- (0, registry_1.Step)("I debug", async (page) => {
60
+ exports.DebugExecution = (0, registry_1.Step)("I debug", async (page) => {
41
61
  console.log("🐞 Debugging...");
42
62
  await page.pause();
43
63
  });
44
64
  /**
45
- * Prints a message to the console logs.
46
- * Pattern: When I log "Hello World"
65
+ * Prints a custom message to the console logs.
66
+ * Useful for marking sections of a test output or debugging variable states.
67
+ *
68
+ * ```gherkin
69
+ * When I log "Starting Login Flow"
70
+ * ```
71
+ *
72
+ * @param message - The string to log.
47
73
  */
48
- (0, registry_1.Step)("I log {string}", async (page, message) => {
74
+ exports.LogMessage = (0, registry_1.Step)("I log {string}", async (page, message) => {
49
75
  console.log(`📝 LOG: ${message}`);
50
76
  });
51
77
  // ==================================================
52
78
  // 3. FOCUS & BLUR
53
79
  // ==================================================
54
80
  /**
55
- * Focuses on the currently stored element.
56
- * Pattern: When I focus
81
+ * Focuses on the currently stored (active) element.
82
+ *
83
+ * ```gherkin
84
+ * When I focus
85
+ * ```
57
86
  */
58
- (0, registry_1.Step)("I focus", async (page) => {
87
+ exports.FocusElement = (0, registry_1.Step)("I focus", async (page) => {
59
88
  const element = (0, state_1.getActiveElement)(page);
60
89
  await element.focus();
61
90
  console.log("👀 Focused on stored element");
62
91
  });
63
92
  /**
64
- * Blurs (un-focuses) the currently stored element.
65
- * Pattern: When I blur
93
+ * Blurs (removes focus from) the currently stored element.
94
+ *
95
+ * ```gherkin
96
+ * When I blur
97
+ * ```
66
98
  */
67
- (0, registry_1.Step)("I blur", async (page) => {
99
+ exports.BlurElement = (0, registry_1.Step)("I blur", async (page) => {
68
100
  const element = (0, state_1.getActiveElement)(page);
69
101
  // Playwright doesn't have a direct .blur(), so we use JS evaluation
70
102
  await element.evaluate((el) => {
@@ -77,10 +109,16 @@ const state_1 = require("../utils/state");
77
109
  // 4. BROWSER STORAGE (Cookies / Local Storage)
78
110
  // ==================================================
79
111
  /**
80
- * Sets a cookie for the current context.
81
- * Pattern: When I set cookie "session_id" to "12345"
112
+ * Sets a cookie for the current context/URL.
113
+ *
114
+ * ```gherkin
115
+ * When I set cookie "session_id" to "12345ABC"
116
+ * ```
117
+ *
118
+ * @param name - The name of the cookie.
119
+ * @param value - The value of the cookie.
82
120
  */
83
- (0, registry_1.Step)("I set cookie {string} to {string}", async (page, name, value) => {
121
+ exports.SetCookie = (0, registry_1.Step)("I set cookie {string} to {string}", async (page, name, value) => {
84
122
  const context = page.context();
85
123
  const url = page.url();
86
124
  // We need a domain or url to set cookies. We use the current page URL.
@@ -88,19 +126,28 @@ const state_1 = require("../utils/state");
88
126
  console.log(`🍪 Set cookie "${name}"`);
89
127
  });
90
128
  /**
91
- * Clears all cookies.
92
- * Pattern: When I clear all cookies
129
+ * Clears all cookies for the current browser context.
130
+ *
131
+ * ```gherkin
132
+ * When I clear all cookies
133
+ * ```
93
134
  */
94
- (0, registry_1.Step)("I clear all cookies", async (page) => {
135
+ exports.ClearAllCookies = (0, registry_1.Step)("I clear all cookies", async (page) => {
95
136
  const context = page.context();
96
137
  await context.clearCookies();
97
138
  console.log("🍪 Cleared all cookies");
98
139
  });
99
140
  /**
100
- * Sets a Local Storage item.
101
- * Pattern: When I set local storage item "theme" to "dark"
141
+ * Sets an item in Local Storage.
142
+ *
143
+ * ```gherkin
144
+ * When I set local storage item "theme" to "dark"
145
+ * ```
146
+ *
147
+ * @param key - The local storage key.
148
+ * @param value - The value to store.
102
149
  */
103
- (0, registry_1.Step)("I set local storage item {string} to {string}", async (page, key, value) => {
150
+ exports.SetLocalStorageItem = (0, registry_1.Step)("I set local storage item {string} to {string}", async (page, key, value) => {
104
151
  await page.evaluate(({ k, v }) => localStorage.setItem(k, v), {
105
152
  k: key,
106
153
  v: value,
@@ -108,26 +155,40 @@ const state_1 = require("../utils/state");
108
155
  console.log(`📦 Set local storage "${key}" = "${value}"`);
109
156
  });
110
157
  /**
111
- * Gets a Local Storage item and prints it.
112
- * Pattern: When I get local storage item "token"
158
+ * Retrieves a Local Storage item and logs it to the console.
159
+ *
160
+ * ```gherkin
161
+ * When I get local storage item "authToken"
162
+ * ```
163
+ *
164
+ * @param key - The key of the item to retrieve.
113
165
  */
114
- (0, registry_1.Step)("I get local storage item {string}", async (page, key) => {
166
+ exports.GetLocalStorageItem = (0, registry_1.Step)("I get local storage item {string}", async (page, key) => {
115
167
  const value = await page.evaluate((k) => localStorage.getItem(k), key);
116
168
  console.log(`📦 Local Storage "${key}": ${value}`);
117
169
  });
118
170
  /**
119
- * Clears all Local Storage.
120
- * Pattern: When I clear local storage
171
+ * Clears all data from Local Storage.
172
+ *
173
+ * ```gherkin
174
+ * When I clear local storage
175
+ * ```
121
176
  */
122
- (0, registry_1.Step)("I clear local storage", async (page) => {
177
+ exports.ClearLocalStorage = (0, registry_1.Step)("I clear local storage", async (page) => {
123
178
  await page.evaluate(() => localStorage.clear());
124
179
  console.log("📦 Cleared local storage");
125
180
  });
126
181
  /**
127
- * Sets a Session Storage item.
128
- * Pattern: When I set session storage item "user" to "admin"
182
+ * Sets an item in Session Storage.
183
+ *
184
+ * ```gherkin
185
+ * When I set session storage item "user_role" to "admin"
186
+ * ```
187
+ *
188
+ * @param key - The session storage key.
189
+ * @param value - The value to store.
129
190
  */
130
- (0, registry_1.Step)("I set session storage item {string} to {string}", async (page, key, value) => {
191
+ exports.SetSessionStorageItem = (0, registry_1.Step)("I set session storage item {string} to {string}", async (page, key, value) => {
131
192
  await page.evaluate(({ k, v }) => sessionStorage.setItem(k, v), {
132
193
  k: key,
133
194
  v: value,
@@ -135,10 +196,13 @@ const state_1 = require("../utils/state");
135
196
  console.log(`📦 Set session storage "${key}" = "${value}"`);
136
197
  });
137
198
  /**
138
- * Clears all Session Storage.
139
- * Pattern: When I clear session storage
199
+ * Clears all data from Session Storage.
200
+ *
201
+ * ```gherkin
202
+ * When I clear session storage
203
+ * ```
140
204
  */
141
- (0, registry_1.Step)("I clear session storage", async (page) => {
205
+ exports.ClearSessionStorage = (0, registry_1.Step)("I clear session storage", async (page) => {
142
206
  await page.evaluate(() => sessionStorage.clear());
143
207
  console.log("📦 Cleared session storage");
144
208
  });