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.
Files changed (79) hide show
  1. package/README.md +21 -11
  2. package/lib/actions/clickSteps.d.ts +251 -1
  3. package/lib/actions/clickSteps.js +297 -47
  4. package/lib/actions/cookieSteps.d.ts +18 -1
  5. package/lib/actions/cookieSteps.js +65 -0
  6. package/lib/actions/debugSteps.d.ts +14 -1
  7. package/lib/actions/debugSteps.js +18 -3
  8. package/lib/actions/elementFindSteps.d.ts +668 -1
  9. package/lib/actions/elementFindSteps.js +808 -94
  10. package/lib/actions/fillFormSteps.d.ts +69 -1
  11. package/lib/actions/fillFormSteps.js +178 -71
  12. package/lib/actions/index.d.ts +11 -0
  13. package/lib/actions/index.js +28 -0
  14. package/lib/actions/inputSteps.d.ts +218 -1
  15. package/lib/actions/inputSteps.js +303 -57
  16. package/lib/actions/interceptionSteps.d.ts +169 -1
  17. package/lib/actions/interceptionSteps.js +258 -38
  18. package/lib/actions/miscSteps.d.ts +645 -1
  19. package/lib/actions/miscSteps.js +898 -157
  20. package/lib/actions/mouseSteps.d.ts +143 -1
  21. package/lib/actions/mouseSteps.js +200 -32
  22. package/lib/actions/scrollSteps.d.ts +82 -1
  23. package/lib/actions/scrollSteps.js +116 -16
  24. package/lib/actions/storageSteps.d.ts +174 -1
  25. package/lib/actions/storageSteps.js +253 -33
  26. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +245 -1
  27. package/lib/assertions/buttonAndTextVisibilitySteps.js +342 -91
  28. package/lib/assertions/cookieSteps.d.ts +75 -1
  29. package/lib/assertions/cookieSteps.js +97 -29
  30. package/lib/assertions/elementSteps.d.ts +264 -1
  31. package/lib/assertions/elementSteps.js +376 -78
  32. package/lib/assertions/formInputSteps.d.ts +248 -1
  33. package/lib/assertions/formInputSteps.js +342 -79
  34. package/lib/assertions/index.d.ts +10 -0
  35. package/lib/assertions/index.js +27 -0
  36. package/lib/assertions/interceptionRequestsSteps.d.ts +353 -1
  37. package/lib/assertions/interceptionRequestsSteps.js +569 -177
  38. package/lib/assertions/locationSteps.d.ts +217 -1
  39. package/lib/assertions/locationSteps.js +287 -64
  40. package/lib/assertions/roleTestIdSteps.d.ts +159 -1
  41. package/lib/assertions/roleTestIdSteps.js +217 -22
  42. package/lib/assertions/semanticSteps.d.ts +176 -1
  43. package/lib/assertions/semanticSteps.js +245 -60
  44. package/lib/assertions/storageSteps.d.ts +149 -1
  45. package/lib/assertions/storageSteps.js +201 -65
  46. package/lib/assertions/visualSteps.d.ts +74 -1
  47. package/lib/assertions/visualSteps.js +178 -45
  48. package/lib/custom_setups/loginHooks.js +19 -2
  49. package/lib/helpers/world.d.ts +3 -0
  50. package/lib/helpers/world.js +11 -5
  51. package/lib/index.d.ts +3 -21
  52. package/lib/index.js +3 -23
  53. package/package.json +9 -2
  54. package/src/actions/clickSteps.ts +364 -142
  55. package/src/actions/cookieSteps.ts +66 -0
  56. package/src/actions/debugSteps.ts +17 -3
  57. package/src/actions/elementFindSteps.ts +822 -117
  58. package/src/actions/fillFormSteps.ts +234 -177
  59. package/src/actions/index.ts +12 -0
  60. package/src/actions/inputSteps.ts +318 -82
  61. package/src/actions/interceptionSteps.ts +295 -57
  62. package/src/actions/miscSteps.ts +984 -254
  63. package/src/actions/mouseSteps.ts +212 -55
  64. package/src/actions/scrollSteps.ts +114 -16
  65. package/src/actions/storageSteps.ts +267 -42
  66. package/src/assertions/buttonAndTextVisibilitySteps.ts +353 -95
  67. package/src/assertions/cookieSteps.ts +115 -36
  68. package/src/assertions/elementSteps.ts +414 -85
  69. package/src/assertions/formInputSteps.ts +375 -108
  70. package/src/assertions/index.ts +11 -0
  71. package/src/assertions/interceptionRequestsSteps.ts +619 -195
  72. package/src/assertions/locationSteps.ts +280 -64
  73. package/src/assertions/roleTestIdSteps.ts +244 -26
  74. package/src/assertions/semanticSteps.ts +257 -69
  75. package/src/assertions/storageSteps.ts +234 -73
  76. package/src/assertions/visualSteps.ts +245 -68
  77. package/src/custom_setups/loginHooks.ts +21 -2
  78. package/src/helpers/world.ts +30 -4
  79. package/src/index.ts +4 -25
@@ -1 +1,174 @@
1
- export {};
1
+ import { CustomWorld } from "../helpers/world";
2
+ /**
3
+ * Clears all items from the browser's Local Storage for the current page's origin.
4
+ *
5
+ * ```gherkin
6
+ * When I clear all local storage
7
+ * ```
8
+ *
9
+ * @example
10
+ * When I clear all local storage
11
+ *
12
+ * @remarks
13
+ * This step executes `localStorage.clear()` in the browser's context.
14
+ * Local Storage items are persistent across browser sessions until explicitly cleared.
15
+ * This step will only affect local storage for the current page's origin.
16
+ * @category Storage Steps
17
+ */
18
+ export declare function When_I_clear_all_local_storage(this: CustomWorld): Promise<void>;
19
+ /**
20
+ * Clears all items from the browser's Local Storage for the current page's origin.
21
+ * This is an alias for "When I clear all local storage".
22
+ *
23
+ * ```gherkin
24
+ * When I clear local storage
25
+ * ```
26
+ *
27
+ * @example
28
+ * When I clear local storage
29
+ *
30
+ * @remarks
31
+ * This step is functionally identical to {@link When_I_clear_all_local_storage | "When I clear all local storage"}.
32
+ * It executes `localStorage.clear()` in the browser's context.
33
+ * Consider using one consistent step pattern.
34
+ * @category Storage Steps
35
+ */
36
+ export declare function When_I_clear_local_storage(this: CustomWorld): Promise<void>;
37
+ /**
38
+ * Clears all items from the browser's Session Storage for the current page's origin.
39
+ *
40
+ * ```gherkin
41
+ * When I clear session storage
42
+ * ```
43
+ *
44
+ * @example
45
+ * When I clear session storage
46
+ *
47
+ * @remarks
48
+ * This step executes `sessionStorage.clear()` in the browser's context.
49
+ * Session Storage items are cleared when the browser session ends.
50
+ * This step will only affect session storage for the current page's origin.
51
+ * @category Storage Steps
52
+ */
53
+ export declare function When_I_clear_session_storage(this: CustomWorld): Promise<void>;
54
+ /**
55
+ * Clears all browser storage: cookies, local storage, and session storage.
56
+ * It first navigates to the `BASE_URL` to ensure the correct origin's storage is cleared.
57
+ *
58
+ * ```gherkin
59
+ * When I clear all browser storage
60
+ * ```
61
+ *
62
+ * @example
63
+ * When I clear all browser storage
64
+ *
65
+ * @remarks
66
+ * This is a comprehensive cleanup step. It uses `context.clearCookies()` for cookies
67
+ * and `page.evaluate()` to clear `localStorage` and `sessionStorage`.
68
+ * Navigating to `BASE_URL` before clearing local/session storage is crucial to ensure
69
+ * the storage for the primary application domain is targeted. Ensure `process.env.BASE_URL` is set.
70
+ * @category Storage Steps
71
+ */
72
+ export declare function When_I_clear_all_browser_storage(this: CustomWorld): Promise<void>;
73
+ /**
74
+ * Sets a specific item in the browser's Local Storage to the given value.
75
+ *
76
+ * ```gherkin
77
+ * When I set local storage item {string} to {string}
78
+ * ```
79
+ *
80
+ * @param key - The key of the local storage item.
81
+ * @param value - The value to set for the local storage item.
82
+ *
83
+ * @example
84
+ * When I set local storage item "token" to "abc123"
85
+ *
86
+ * @remarks
87
+ * This step executes `localStorage.setItem(key, value)` in the browser's context.
88
+ * This is useful for injecting authentication tokens, feature flags, or other data
89
+ * directly into local storage for test setup.
90
+ * @category Storage Steps
91
+ */
92
+ export declare function When_I_set_local_storage_item(this: CustomWorld, key: string, value: string): Promise<void>;
93
+ /**
94
+ * Sets a specific item in the browser's Session Storage to the given value.
95
+ *
96
+ * ```gherkin
97
+ * When I set session storage item {string} to {string}
98
+ * ```
99
+ *
100
+ * @param key - The key of the session storage item.
101
+ * @param value - The value to set for the session storage item.
102
+ *
103
+ * @example
104
+ * When I set session storage item "sessionId" to "xyz789"
105
+ *
106
+ * @remarks
107
+ * This step executes `sessionStorage.setItem(key, value)` in the browser's context.
108
+ * This is useful for injecting data that needs to persist only for the current browser session.
109
+ * @category Storage Steps
110
+ */
111
+ export declare function When_I_set_session_storage_item(this: CustomWorld, key: string, value: string): Promise<void>;
112
+ /**
113
+ * Stores the value of the currently focused input or textarea as an alias in the test data.
114
+ *
115
+ * ```gherkin
116
+ * When I store input text as {string}
117
+ * ```
118
+ *
119
+ * @param alias - The alias name under which to store the input's value.
120
+ *
121
+ * @example
122
+ * Given I find element by placeholder text "Enter your email"
123
+ * And I type "user@example.com"
124
+ * When I store input text as "userEmail"
125
+ * Then the value of alias "userEmail" should be "user@example.com"
126
+ *
127
+ * @remarks
128
+ * This step requires an input or textarea element to be currently focused. It retrieves
129
+ * the `value` attribute of that element and stores it in {@link CustomWorld.data | this.data}
130
+ * under the provided `alias`. This is useful for capturing dynamically generated input values.
131
+ * @category Data Manipulation Steps
132
+ */
133
+ export declare function When_I_store_input_text_as(this: CustomWorld, alias: string): Promise<void>;
134
+ /**
135
+ * Deletes a session file with the given name from the artifact directory.
136
+ * These session files are typically used for storing browser session state (e.g., cookies, local storage).
137
+ *
138
+ * ```gherkin
139
+ * When I clear session {string}
140
+ * ```
141
+ *
142
+ * @param fileName - The name of the session file to delete (e.g., "my-session.json").
143
+ *
144
+ * @example
145
+ * Given I save session as "admin-session.json"
146
+ * # ... later in a cleanup scenario
147
+ * When I clear session "admin-session.json"
148
+ *
149
+ * @remarks
150
+ * The `fileName` is resolved relative to a base directory, which defaults to
151
+ * `test-artifacts/auth-cookies` or can be configured via `this.parameters?.artifactDir`
152
+ * or `process.env.TEST_ARTIFACT_DIR`.
153
+ * This step ensures clean-up of saved session states, which is crucial for isolated tests.
154
+ * @category File System Steps
155
+ */
156
+ export declare function When_I_clear_session_file(this: CustomWorld, fileName: string): Promise<void>;
157
+ /**
158
+ * Clears all saved session files from the authentication directory.
159
+ * This is useful for ensuring a clean slate before or after tests that rely on persistent sessions.
160
+ *
161
+ * ```gherkin
162
+ * When I clear all saved session files
163
+ * ```
164
+ *
165
+ * @example
166
+ * When I clear all saved session files
167
+ *
168
+ * @remarks
169
+ * This step reads the `e2e/support/helper/auth` directory (hardcoded path) and deletes
170
+ * all files found within it. It's crucial for managing test artifacts related to user sessions.
171
+ * Ensure the directory path is correct for your project structure.
172
+ * @category File System Steps
173
+ */
174
+ export declare function When_I_clear_all_saved_session_files(this: CustomWorld): Promise<void>;
@@ -3,70 +3,290 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.When_I_clear_all_local_storage = When_I_clear_all_local_storage;
7
+ exports.When_I_clear_local_storage = When_I_clear_local_storage;
8
+ exports.When_I_clear_session_storage = When_I_clear_session_storage;
9
+ exports.When_I_clear_all_browser_storage = When_I_clear_all_browser_storage;
10
+ exports.When_I_set_local_storage_item = When_I_set_local_storage_item;
11
+ exports.When_I_set_session_storage_item = When_I_set_session_storage_item;
12
+ exports.When_I_store_input_text_as = When_I_store_input_text_as;
13
+ exports.When_I_clear_session_file = When_I_clear_session_file;
14
+ exports.When_I_clear_all_saved_session_files = When_I_clear_all_saved_session_files;
6
15
  // e2e/step_definitions/common/actions/storageSteps.ts
7
16
  const fs_1 = __importDefault(require("fs"));
8
17
  const path_1 = __importDefault(require("path"));
9
18
  const cucumber_1 = require("@cucumber/cucumber");
10
- (0, cucumber_1.When)("I clear all local storage", async function () {
19
+ // ===================================================================================
20
+ // BROWSER STORAGE ACTIONS (LOCAL STORAGE, SESSION STORAGE, COOKIES)
21
+ // ===================================================================================
22
+ /**
23
+ * Clears all items from the browser's Local Storage for the current page's origin.
24
+ *
25
+ * ```gherkin
26
+ * When I clear all local storage
27
+ * ```
28
+ *
29
+ * @example
30
+ * When I clear all local storage
31
+ *
32
+ * @remarks
33
+ * This step executes `localStorage.clear()` in the browser's context.
34
+ * Local Storage items are persistent across browser sessions until explicitly cleared.
35
+ * This step will only affect local storage for the current page's origin.
36
+ * @category Storage Steps
37
+ */
38
+ async function When_I_clear_all_local_storage() {
11
39
  await this.page.evaluate(() => localStorage.clear());
12
- this.log("Cleared all local storage");
13
- });
14
- (0, cucumber_1.When)("I clear local storage", async function () {
40
+ this.log?.("๐Ÿ—‘๏ธ Cleared all local storage.");
41
+ }
42
+ (0, cucumber_1.When)("I clear all local storage", When_I_clear_all_local_storage);
43
+ /**
44
+ * Clears all items from the browser's Local Storage for the current page's origin.
45
+ * This is an alias for "When I clear all local storage".
46
+ *
47
+ * ```gherkin
48
+ * When I clear local storage
49
+ * ```
50
+ *
51
+ * @example
52
+ * When I clear local storage
53
+ *
54
+ * @remarks
55
+ * This step is functionally identical to {@link When_I_clear_all_local_storage | "When I clear all local storage"}.
56
+ * It executes `localStorage.clear()` in the browser's context.
57
+ * Consider using one consistent step pattern.
58
+ * @category Storage Steps
59
+ */
60
+ async function When_I_clear_local_storage() {
15
61
  await this.page.evaluate(() => localStorage.clear());
16
- this.log("Cleared local storage (alias)");
17
- });
18
- (0, cucumber_1.When)("I clear session storage", async function () {
62
+ this.log?.("๐Ÿ—‘๏ธ Cleared local storage (alias).");
63
+ }
64
+ // Note: You have two steps with the exact same Gherkin pattern:
65
+ // When("I clear local storage", async function () { ... });
66
+ // When("I clear local storage", async function (this: CustomWorld) { ... });
67
+ // I've consolidated them into one export and linked the When call.
68
+ (0, cucumber_1.When)("I clear local storage", When_I_clear_local_storage);
69
+ /**
70
+ * Clears all items from the browser's Session Storage for the current page's origin.
71
+ *
72
+ * ```gherkin
73
+ * When I clear session storage
74
+ * ```
75
+ *
76
+ * @example
77
+ * When I clear session storage
78
+ *
79
+ * @remarks
80
+ * This step executes `sessionStorage.clear()` in the browser's context.
81
+ * Session Storage items are cleared when the browser session ends.
82
+ * This step will only affect session storage for the current page's origin.
83
+ * @category Storage Steps
84
+ */
85
+ async function When_I_clear_session_storage() {
19
86
  await this.page.evaluate(() => sessionStorage.clear());
20
- this.log("Cleared session storage");
21
- });
22
- (0, cucumber_1.When)("I clear all browser storage", async function () {
87
+ this.log?.("๐Ÿ—‘๏ธ Cleared session storage.");
88
+ }
89
+ (0, cucumber_1.When)("I clear session storage", When_I_clear_session_storage);
90
+ /**
91
+ * Clears all browser storage: cookies, local storage, and session storage.
92
+ * It first navigates to the `BASE_URL` to ensure the correct origin's storage is cleared.
93
+ *
94
+ * ```gherkin
95
+ * When I clear all browser storage
96
+ * ```
97
+ *
98
+ * @example
99
+ * When I clear all browser storage
100
+ *
101
+ * @remarks
102
+ * This is a comprehensive cleanup step. It uses `context.clearCookies()` for cookies
103
+ * and `page.evaluate()` to clear `localStorage` and `sessionStorage`.
104
+ * Navigating to `BASE_URL` before clearing local/session storage is crucial to ensure
105
+ * the storage for the primary application domain is targeted. Ensure `process.env.BASE_URL` is set.
106
+ * @category Storage Steps
107
+ */
108
+ async function When_I_clear_all_browser_storage() {
23
109
  const { context, page } = this;
24
- // Clear cookies
110
+ // Clear cookies for the entire browser context
25
111
  await context.clearCookies();
112
+ this.log?.("๐Ÿ—‘๏ธ Cleared all cookies.");
26
113
  // Clear local/session storage by navigating to base URL first
27
114
  const baseUrl = process.env.BASE_URL;
28
115
  if (!baseUrl)
29
- throw new Error("Missing BASE_URL");
116
+ throw new Error("Missing BASE_URL environment variable. Cannot clear local/session storage effectively.");
117
+ // Navigate to base URL to ensure we are on the correct origin to clear its storage
30
118
  await page.goto(baseUrl);
119
+ this.log?.(`๐ŸŒ Navigated to BASE_URL (${baseUrl}) to ensure correct origin for storage clearing.`);
31
120
  await page.evaluate(() => {
32
121
  localStorage.clear();
33
122
  sessionStorage.clear();
34
123
  });
35
- this.log("โœ… Cleared all cookies and storage");
36
- });
37
- (0, cucumber_1.When)("I set local storage item {string} to {string}", async function (key, value) {
124
+ this.log?.("๐Ÿ—‘๏ธ Cleared all local and session storage.");
125
+ this.log?.("โœ… Cleared all browser cookies and storage.");
126
+ }
127
+ (0, cucumber_1.When)("I clear all browser storage", When_I_clear_all_browser_storage);
128
+ /**
129
+ * Sets a specific item in the browser's Local Storage to the given value.
130
+ *
131
+ * ```gherkin
132
+ * When I set local storage item {string} to {string}
133
+ * ```
134
+ *
135
+ * @param key - The key of the local storage item.
136
+ * @param value - The value to set for the local storage item.
137
+ *
138
+ * @example
139
+ * When I set local storage item "token" to "abc123"
140
+ *
141
+ * @remarks
142
+ * This step executes `localStorage.setItem(key, value)` in the browser's context.
143
+ * This is useful for injecting authentication tokens, feature flags, or other data
144
+ * directly into local storage for test setup.
145
+ * @category Storage Steps
146
+ */
147
+ async function When_I_set_local_storage_item(key, value) {
148
+ // FIX: Use object for evaluate arguments to avoid TypeScript overload issues
38
149
  await this.page.evaluate(([k, v]) => localStorage.setItem(k, v), [key, value]);
39
- });
40
- (0, cucumber_1.When)("I set session storage item {string} to {string}", async function (key, value) {
150
+ this.log?.(`๐Ÿ“ฆ Set local storage item "${key}" to "${value.slice(0, 50)}...".`);
151
+ }
152
+ (0, cucumber_1.When)("I set local storage item {string} to {string}", When_I_set_local_storage_item);
153
+ /**
154
+ * Sets a specific item in the browser's Session Storage to the given value.
155
+ *
156
+ * ```gherkin
157
+ * When I set session storage item {string} to {string}
158
+ * ```
159
+ *
160
+ * @param key - The key of the session storage item.
161
+ * @param value - The value to set for the session storage item.
162
+ *
163
+ * @example
164
+ * When I set session storage item "sessionId" to "xyz789"
165
+ *
166
+ * @remarks
167
+ * This step executes `sessionStorage.setItem(key, value)` in the browser's context.
168
+ * This is useful for injecting data that needs to persist only for the current browser session.
169
+ * @category Storage Steps
170
+ */
171
+ async function When_I_set_session_storage_item(key, value) {
172
+ // FIX: Use object for evaluate arguments to avoid TypeScript overload issues
41
173
  await this.page.evaluate(([k, v]) => sessionStorage.setItem(k, v), [key, value]);
42
- });
43
- (0, cucumber_1.When)("I clear local storage", async function () {
44
- await this.page.evaluate(() => localStorage.clear());
45
- });
46
- (0, cucumber_1.When)("I store input text as {string}", async function (alias) {
174
+ this.log?.(`๐Ÿ“ฆ Set session storage item "${key}" to "${value.slice(0, 50)}...".`);
175
+ }
176
+ (0, cucumber_1.When)("I set session storage item {string} to {string}", When_I_set_session_storage_item);
177
+ /**
178
+ * Stores the value of the currently focused input or textarea as an alias in the test data.
179
+ *
180
+ * ```gherkin
181
+ * When I store input text as {string}
182
+ * ```
183
+ *
184
+ * @param alias - The alias name under which to store the input's value.
185
+ *
186
+ * @example
187
+ * Given I find element by placeholder text "Enter your email"
188
+ * And I type "user@example.com"
189
+ * When I store input text as "userEmail"
190
+ * Then the value of alias "userEmail" should be "user@example.com"
191
+ *
192
+ * @remarks
193
+ * This step requires an input or textarea element to be currently focused. It retrieves
194
+ * the `value` attribute of that element and stores it in {@link CustomWorld.data | this.data}
195
+ * under the provided `alias`. This is useful for capturing dynamically generated input values.
196
+ * @category Data Manipulation Steps
197
+ */
198
+ async function When_I_store_input_text_as(alias) {
47
199
  const activeElementHandle = await this.page.evaluateHandle(() => document.activeElement);
48
- const tagName = await activeElementHandle.evaluate((el) => (el ? el.tagName.toLowerCase() : ""));
200
+ // Check if activeElementHandle is not null and is an HTMLInputElement or HTMLTextAreaElement
201
+ const tagName = await activeElementHandle.evaluate((el) => el ? el.tagName.toLowerCase() : "");
49
202
  if (tagName !== "input" && tagName !== "textarea") {
50
- throw new Error(`Active element is not an input or textarea (found: ${tagName})`);
203
+ throw new Error(`Active element is not an input or textarea (found: "${tagName || "none"}"). Cannot store text.`);
51
204
  }
205
+ // Cast el to HTMLInputElement as both input and textarea have a 'value' property
52
206
  const value = await activeElementHandle.evaluate((el) => el.value);
53
207
  this.data[alias] = value;
54
- this.log?.(`๐Ÿ“ฅ Stored value from input as "${alias}": ${value}`);
55
- });
56
- (0, cucumber_1.When)("I clear session {string}", async function (fileName) {
208
+ this.log?.(`๐Ÿ“ฅ Stored value from active input as "${alias}": "${value}".`);
209
+ }
210
+ (0, cucumber_1.When)("I store input text as {string}", When_I_store_input_text_as);
211
+ /**
212
+ * Deletes a session file with the given name from the artifact directory.
213
+ * These session files are typically used for storing browser session state (e.g., cookies, local storage).
214
+ *
215
+ * ```gherkin
216
+ * When I clear session {string}
217
+ * ```
218
+ *
219
+ * @param fileName - The name of the session file to delete (e.g., "my-session.json").
220
+ *
221
+ * @example
222
+ * Given I save session as "admin-session.json"
223
+ * # ... later in a cleanup scenario
224
+ * When I clear session "admin-session.json"
225
+ *
226
+ * @remarks
227
+ * The `fileName` is resolved relative to a base directory, which defaults to
228
+ * `test-artifacts/auth-cookies` or can be configured via `this.parameters?.artifactDir`
229
+ * or `process.env.TEST_ARTIFACT_DIR`.
230
+ * This step ensures clean-up of saved session states, which is crucial for isolated tests.
231
+ * @category File System Steps
232
+ */
233
+ async function When_I_clear_session_file(fileName) {
57
234
  const baseDir = this.parameters?.artifactDir || process.env.TEST_ARTIFACT_DIR || "test-artifacts";
58
- const fullPath = path_1.default.resolve(baseDir, "auth-cookies", fileName);
235
+ const sessionDirPath = path_1.default.resolve(baseDir, "auth-cookies"); // Assuming sessions are stored here
236
+ const fullPath = path_1.default.resolve(sessionDirPath, fileName);
59
237
  try {
60
238
  if (fs_1.default.existsSync(fullPath)) {
61
239
  fs_1.default.unlinkSync(fullPath);
62
- this.log?.(`๐Ÿ—‘๏ธ Session file deleted: ${fullPath}`);
240
+ this.log?.(`๐Ÿ—‘๏ธ Session file deleted: "${fullPath}".`);
63
241
  }
64
242
  else {
65
- this.log?.(`โ„น๏ธ Session file not found, nothing to delete: ${fullPath}`);
243
+ this.log?.(`โ„น๏ธ Session file not found, nothing to delete: "${fullPath}".`);
66
244
  }
67
245
  }
68
246
  catch (err) {
69
- this.log?.(`โŒ Failed to delete session file: ${err.message}`);
70
- throw err;
247
+ const message = err instanceof Error ? err.message : String(err);
248
+ this.log?.(`โŒ Failed to delete session file "${fullPath}": ${message}`);
249
+ throw err; // Re-throw to fail the step if deletion truly failed
250
+ }
251
+ }
252
+ (0, cucumber_1.When)("I clear session {string}", When_I_clear_session_file);
253
+ // ===================================================================================
254
+ // FILE SYSTEM ACTIONS: SAVED SESSIONS
255
+ // ===================================================================================
256
+ /**
257
+ * Clears all saved session files from the authentication directory.
258
+ * This is useful for ensuring a clean slate before or after tests that rely on persistent sessions.
259
+ *
260
+ * ```gherkin
261
+ * When I clear all saved session files
262
+ * ```
263
+ *
264
+ * @example
265
+ * When I clear all saved session files
266
+ *
267
+ * @remarks
268
+ * This step reads the `e2e/support/helper/auth` directory (hardcoded path) and deletes
269
+ * all files found within it. It's crucial for managing test artifacts related to user sessions.
270
+ * Ensure the directory path is correct for your project structure.
271
+ * @category File System Steps
272
+ */
273
+ async function When_I_clear_all_saved_session_files() {
274
+ // Hardcoded path based on your original snippet
275
+ const authDir = path_1.default.resolve("e2e/support/helper/auth");
276
+ if (fs_1.default.existsSync(authDir)) {
277
+ const files = fs_1.default.readdirSync(authDir);
278
+ for (const file of files) {
279
+ const filePath = path_1.default.join(authDir, file);
280
+ // Ensure it's a file, not a subdirectory
281
+ if (fs_1.default.lstatSync(filePath).isFile()) {
282
+ fs_1.default.unlinkSync(filePath);
283
+ this.log?.(`๐Ÿงน Deleted session file: "${file}".`);
284
+ }
285
+ }
286
+ this.log?.(`โœ… All saved session files cleared from "${authDir}".`);
287
+ }
288
+ else {
289
+ this.log?.(`โš ๏ธ Auth directory not found at "${authDir}". No session files to clear.`);
71
290
  }
72
- });
291
+ }
292
+ (0, cucumber_1.When)("I clear all saved session files", When_I_clear_all_saved_session_files);