playwright-cucumber-ts-steps 1.0.1 โ 1.0.3
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 +270 -244
- package/dist/backend/actions/formTable.js +34 -0
- package/dist/backend/actions/index.js +5 -0
- package/dist/backend/actions/interactions.js +23 -0
- package/dist/backend/actions/navigation.js +19 -0
- package/dist/backend/api/assertions.js +26 -0
- package/dist/backend/api/index.js +5 -0
- package/dist/backend/api/mock.js +75 -0
- package/dist/backend/api/requests.js +86 -0
- package/dist/backend/api/state.js +15 -0
- package/dist/backend/assertions/expectVisible.js +8 -0
- package/dist/backend/assertions/index.js +5 -0
- package/dist/backend/assertions/pageState.js +25 -0
- package/dist/backend/assertions/text.js +20 -0
- package/dist/backend/assertions/visibility.js +20 -0
- package/dist/backend/auth/index.js +71 -0
- package/dist/backend/db/index.js +6 -0
- package/dist/backend/db/state.js +24 -0
- package/dist/backend/db/steps.js +43 -0
- package/dist/backend/elements/alerts.js +21 -0
- package/dist/backend/elements/forms.js +59 -0
- package/dist/backend/elements/frames.js +25 -0
- package/dist/backend/elements/index.js +5 -0
- package/dist/core/registry.js +20 -0
- package/dist/core/runner.js +151 -0
- package/dist/index.js +10 -0
- package/dist/reporting/index.js +43 -0
- package/package.json +19 -101
- package/LICENSE +0 -21
- package/lib/actions/clickSteps.d.ts +0 -251
- package/lib/actions/clickSteps.js +0 -415
- package/lib/actions/cookieSteps.d.ts +0 -18
- package/lib/actions/cookieSteps.js +0 -93
- package/lib/actions/debugSteps.d.ts +0 -14
- package/lib/actions/debugSteps.js +0 -23
- package/lib/actions/elementFindSteps.d.ts +0 -668
- package/lib/actions/elementFindSteps.js +0 -931
- package/lib/actions/fillFormSteps.d.ts +0 -69
- package/lib/actions/fillFormSteps.js +0 -237
- package/lib/actions/index.d.ts +0 -11
- package/lib/actions/index.js +0 -28
- package/lib/actions/inputSteps.d.ts +0 -218
- package/lib/actions/inputSteps.js +0 -343
- package/lib/actions/interceptionSteps.d.ts +0 -169
- package/lib/actions/interceptionSteps.js +0 -291
- package/lib/actions/miscSteps.d.ts +0 -645
- package/lib/actions/miscSteps.js +0 -1061
- package/lib/actions/mouseSteps.d.ts +0 -143
- package/lib/actions/mouseSteps.js +0 -234
- package/lib/actions/scrollSteps.d.ts +0 -82
- package/lib/actions/scrollSteps.js +0 -123
- package/lib/actions/storageSteps.d.ts +0 -174
- package/lib/actions/storageSteps.js +0 -292
- package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -245
- package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -401
- package/lib/assertions/cookieSteps.d.ts +0 -75
- package/lib/assertions/cookieSteps.js +0 -113
- package/lib/assertions/elementSteps.d.ts +0 -264
- package/lib/assertions/elementSteps.js +0 -388
- package/lib/assertions/formInputSteps.d.ts +0 -248
- package/lib/assertions/formInputSteps.js +0 -350
- package/lib/assertions/index.d.ts +0 -10
- package/lib/assertions/index.js +0 -27
- package/lib/assertions/interceptionRequestsSteps.d.ts +0 -353
- package/lib/assertions/interceptionRequestsSteps.js +0 -593
- package/lib/assertions/locationSteps.d.ts +0 -217
- package/lib/assertions/locationSteps.js +0 -310
- package/lib/assertions/roleTestIdSteps.d.ts +0 -159
- package/lib/assertions/roleTestIdSteps.js +0 -221
- package/lib/assertions/semanticSteps.d.ts +0 -176
- package/lib/assertions/semanticSteps.js +0 -252
- package/lib/assertions/storageSteps.d.ts +0 -149
- package/lib/assertions/storageSteps.js +0 -210
- package/lib/assertions/visualSteps.d.ts +0 -74
- package/lib/assertions/visualSteps.js +0 -209
- package/lib/custom_setups/loginHooks.d.ts +0 -1
- package/lib/custom_setups/loginHooks.js +0 -130
- package/lib/helpers/checkPeerDeps.d.ts +0 -1
- package/lib/helpers/checkPeerDeps.js +0 -19
- package/lib/helpers/compareSnapshots.d.ts +0 -6
- package/lib/helpers/compareSnapshots.js +0 -20
- package/lib/helpers/hooks.d.ts +0 -1
- package/lib/helpers/hooks.js +0 -210
- package/lib/helpers/utils/fakerUtils.d.ts +0 -1
- package/lib/helpers/utils/fakerUtils.js +0 -60
- package/lib/helpers/utils/index.d.ts +0 -4
- package/lib/helpers/utils/index.js +0 -20
- package/lib/helpers/utils/optionsUtils.d.ts +0 -24
- package/lib/helpers/utils/optionsUtils.js +0 -88
- package/lib/helpers/utils/resolveUtils.d.ts +0 -6
- package/lib/helpers/utils/resolveUtils.js +0 -72
- package/lib/helpers/utils/sessionUtils.d.ts +0 -3
- package/lib/helpers/utils/sessionUtils.js +0 -40
- package/lib/helpers/world.d.ts +0 -34
- package/lib/helpers/world.js +0 -110
- package/lib/iframes/frames.d.ts +0 -1
- package/lib/iframes/frames.js +0 -11
- package/lib/index.d.ts +0 -10
- package/lib/index.js +0 -28
- package/lib/register.d.ts +0 -1
- package/lib/register.js +0 -6
- package/src/actions/clickSteps.ts +0 -429
- package/src/actions/cookieSteps.ts +0 -95
- package/src/actions/debugSteps.ts +0 -21
- package/src/actions/elementFindSteps.ts +0 -961
- package/src/actions/fillFormSteps.ts +0 -270
- package/src/actions/index.ts +0 -12
- package/src/actions/inputSteps.ts +0 -354
- package/src/actions/interceptionSteps.ts +0 -325
- package/src/actions/miscSteps.ts +0 -1144
- package/src/actions/mouseSteps.ts +0 -256
- package/src/actions/scrollSteps.ts +0 -122
- package/src/actions/storageSteps.ts +0 -308
- package/src/assertions/buttonAndTextVisibilitySteps.ts +0 -436
- package/src/assertions/cookieSteps.ts +0 -131
- package/src/assertions/elementSteps.ts +0 -432
- package/src/assertions/formInputSteps.ts +0 -377
- package/src/assertions/index.ts +0 -11
- package/src/assertions/interceptionRequestsSteps.ts +0 -640
- package/src/assertions/locationSteps.ts +0 -315
- package/src/assertions/roleTestIdSteps.ts +0 -254
- package/src/assertions/semanticSteps.ts +0 -267
- package/src/assertions/storageSteps.ts +0 -250
- package/src/assertions/visualSteps.ts +0 -275
- package/src/custom_setups/loginHooks.ts +0 -154
- package/src/helpers/checkPeerDeps.ts +0 -19
- package/src/helpers/compareSnapshots.ts +0 -35
- package/src/helpers/hooks.ts +0 -212
- package/src/helpers/utils/fakerUtils.ts +0 -64
- package/src/helpers/utils/index.ts +0 -4
- package/src/helpers/utils/optionsUtils.ts +0 -104
- package/src/helpers/utils/resolveUtils.ts +0 -74
- package/src/helpers/utils/sessionUtils.ts +0 -36
- package/src/helpers/world.ts +0 -119
- package/src/iframes/frames.ts +0 -15
- package/src/index.ts +0 -18
- package/src/register.ts +0 -4
|
@@ -1,174 +0,0 @@
|
|
|
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>;
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
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;
|
|
15
|
-
// e2e/step_definitions/common/actions/storageSteps.ts
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const cucumber_1 = require("@cucumber/cucumber");
|
|
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() {
|
|
39
|
-
await this.page.evaluate(() => localStorage.clear());
|
|
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() {
|
|
61
|
-
await this.page.evaluate(() => localStorage.clear());
|
|
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() {
|
|
86
|
-
await this.page.evaluate(() => sessionStorage.clear());
|
|
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() {
|
|
109
|
-
const { context, page } = this;
|
|
110
|
-
// Clear cookies for the entire browser context
|
|
111
|
-
await context.clearCookies();
|
|
112
|
-
this.log?.("๐๏ธ Cleared all cookies.");
|
|
113
|
-
// Clear local/session storage by navigating to base URL first
|
|
114
|
-
const baseUrl = process.env.BASE_URL;
|
|
115
|
-
if (!baseUrl)
|
|
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
|
|
118
|
-
await page.goto(baseUrl);
|
|
119
|
-
this.log?.(`๐ Navigated to BASE_URL (${baseUrl}) to ensure correct origin for storage clearing.`);
|
|
120
|
-
await page.evaluate(() => {
|
|
121
|
-
localStorage.clear();
|
|
122
|
-
sessionStorage.clear();
|
|
123
|
-
});
|
|
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
|
|
149
|
-
await this.page.evaluate(([k, v]) => localStorage.setItem(k, v), [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
|
|
173
|
-
await this.page.evaluate(([k, v]) => sessionStorage.setItem(k, v), [key, value]);
|
|
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) {
|
|
199
|
-
const activeElementHandle = await this.page.evaluateHandle(() => document.activeElement);
|
|
200
|
-
// Check if activeElementHandle is not null and is an HTMLInputElement or HTMLTextAreaElement
|
|
201
|
-
const tagName = await activeElementHandle.evaluate((el) => el ? el.tagName.toLowerCase() : "");
|
|
202
|
-
if (tagName !== "input" && tagName !== "textarea") {
|
|
203
|
-
throw new Error(`Active element is not an input or textarea (found: "${tagName || "none"}"). Cannot store text.`);
|
|
204
|
-
}
|
|
205
|
-
// Cast el to HTMLInputElement as both input and textarea have a 'value' property
|
|
206
|
-
const value = await activeElementHandle.evaluate((el) => el.value);
|
|
207
|
-
this.data[alias] = value;
|
|
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) {
|
|
234
|
-
const baseDir = this.parameters?.artifactDir || process.env.TEST_ARTIFACT_DIR || "test-artifacts";
|
|
235
|
-
const sessionDirPath = path_1.default.resolve(baseDir, "auth-cookies"); // Assuming sessions are stored here
|
|
236
|
-
const fullPath = path_1.default.resolve(sessionDirPath, fileName);
|
|
237
|
-
try {
|
|
238
|
-
if (fs_1.default.existsSync(fullPath)) {
|
|
239
|
-
fs_1.default.unlinkSync(fullPath);
|
|
240
|
-
this.log?.(`๐๏ธ Session file deleted: "${fullPath}".`);
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
this.log?.(`โน๏ธ Session file not found, nothing to delete: "${fullPath}".`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
catch (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.`);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
(0, cucumber_1.When)("I clear all saved session files", When_I_clear_all_saved_session_files);
|