playwright-cucumber-ts-steps 0.1.7 → 1.0.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.
Files changed (96) hide show
  1. package/README.md +21 -11
  2. package/package.json +9 -2
  3. package/src/actions/clickSteps.ts +364 -142
  4. package/src/actions/cookieSteps.ts +66 -0
  5. package/src/actions/debugSteps.ts +17 -3
  6. package/src/actions/elementFindSteps.ts +822 -117
  7. package/src/actions/fillFormSteps.ts +234 -177
  8. package/src/actions/index.ts +12 -0
  9. package/src/actions/inputSteps.ts +318 -82
  10. package/src/actions/interceptionSteps.ts +295 -57
  11. package/src/actions/miscSteps.ts +984 -254
  12. package/src/actions/mouseSteps.ts +212 -55
  13. package/src/actions/scrollSteps.ts +114 -16
  14. package/src/actions/storageSteps.ts +267 -42
  15. package/src/assertions/buttonAndTextVisibilitySteps.ts +353 -95
  16. package/src/assertions/cookieSteps.ts +115 -36
  17. package/src/assertions/elementSteps.ts +414 -85
  18. package/src/assertions/formInputSteps.ts +375 -108
  19. package/src/assertions/index.ts +11 -0
  20. package/src/assertions/interceptionRequestsSteps.ts +619 -195
  21. package/src/assertions/locationSteps.ts +280 -64
  22. package/src/assertions/roleTestIdSteps.ts +244 -26
  23. package/src/assertions/semanticSteps.ts +257 -69
  24. package/src/assertions/storageSteps.ts +234 -73
  25. package/src/assertions/visualSteps.ts +245 -68
  26. package/src/custom_setups/loginHooks.ts +21 -2
  27. package/src/helpers/world.ts +30 -4
  28. package/src/index.ts +4 -25
  29. package/lib/actions/clickSteps.d.ts +0 -1
  30. package/lib/actions/clickSteps.js +0 -165
  31. package/lib/actions/cookieSteps.d.ts +0 -1
  32. package/lib/actions/cookieSteps.js +0 -28
  33. package/lib/actions/debugSteps.d.ts +0 -1
  34. package/lib/actions/debugSteps.js +0 -8
  35. package/lib/actions/elementFindSteps.d.ts +0 -1
  36. package/lib/actions/elementFindSteps.js +0 -217
  37. package/lib/actions/fillFormSteps.d.ts +0 -1
  38. package/lib/actions/fillFormSteps.js +0 -130
  39. package/lib/actions/inputSteps.d.ts +0 -1
  40. package/lib/actions/inputSteps.js +0 -97
  41. package/lib/actions/interceptionSteps.d.ts +0 -1
  42. package/lib/actions/interceptionSteps.js +0 -71
  43. package/lib/actions/miscSteps.d.ts +0 -1
  44. package/lib/actions/miscSteps.js +0 -320
  45. package/lib/actions/mouseSteps.d.ts +0 -1
  46. package/lib/actions/mouseSteps.js +0 -66
  47. package/lib/actions/scrollSteps.d.ts +0 -1
  48. package/lib/actions/scrollSteps.js +0 -23
  49. package/lib/actions/storageSteps.d.ts +0 -1
  50. package/lib/actions/storageSteps.js +0 -72
  51. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -1
  52. package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -150
  53. package/lib/assertions/cookieSteps.d.ts +0 -1
  54. package/lib/assertions/cookieSteps.js +0 -45
  55. package/lib/assertions/elementSteps.d.ts +0 -1
  56. package/lib/assertions/elementSteps.js +0 -90
  57. package/lib/assertions/formInputSteps.d.ts +0 -1
  58. package/lib/assertions/formInputSteps.js +0 -87
  59. package/lib/assertions/interceptionRequestsSteps.d.ts +0 -1
  60. package/lib/assertions/interceptionRequestsSteps.js +0 -201
  61. package/lib/assertions/locationSteps.d.ts +0 -1
  62. package/lib/assertions/locationSteps.js +0 -87
  63. package/lib/assertions/roleTestIdSteps.d.ts +0 -1
  64. package/lib/assertions/roleTestIdSteps.js +0 -26
  65. package/lib/assertions/semanticSteps.d.ts +0 -1
  66. package/lib/assertions/semanticSteps.js +0 -67
  67. package/lib/assertions/storageSteps.d.ts +0 -1
  68. package/lib/assertions/storageSteps.js +0 -74
  69. package/lib/assertions/visualSteps.d.ts +0 -1
  70. package/lib/assertions/visualSteps.js +0 -76
  71. package/lib/custom_setups/loginHooks.d.ts +0 -1
  72. package/lib/custom_setups/loginHooks.js +0 -113
  73. package/lib/helpers/checkPeerDeps.d.ts +0 -1
  74. package/lib/helpers/checkPeerDeps.js +0 -19
  75. package/lib/helpers/compareSnapshots.d.ts +0 -6
  76. package/lib/helpers/compareSnapshots.js +0 -20
  77. package/lib/helpers/hooks.d.ts +0 -1
  78. package/lib/helpers/hooks.js +0 -210
  79. package/lib/helpers/utils/fakerUtils.d.ts +0 -1
  80. package/lib/helpers/utils/fakerUtils.js +0 -60
  81. package/lib/helpers/utils/index.d.ts +0 -4
  82. package/lib/helpers/utils/index.js +0 -20
  83. package/lib/helpers/utils/optionsUtils.d.ts +0 -24
  84. package/lib/helpers/utils/optionsUtils.js +0 -88
  85. package/lib/helpers/utils/resolveUtils.d.ts +0 -6
  86. package/lib/helpers/utils/resolveUtils.js +0 -72
  87. package/lib/helpers/utils/sessionUtils.d.ts +0 -3
  88. package/lib/helpers/utils/sessionUtils.js +0 -40
  89. package/lib/helpers/world.d.ts +0 -31
  90. package/lib/helpers/world.js +0 -104
  91. package/lib/iframes/frames.d.ts +0 -1
  92. package/lib/iframes/frames.js +0 -11
  93. package/lib/index.d.ts +0 -28
  94. package/lib/index.js +0 -48
  95. package/lib/register.d.ts +0 -1
  96. package/lib/register.js +0 -6
@@ -1,79 +1,267 @@
1
1
  import { Then, DataTable } from "@cucumber/cucumber";
2
2
  import { expect } from "@playwright/test";
3
- import { parseExpectOptions } from "../helpers/utils/optionsUtils";
4
- import type { CustomWorld } from "../helpers/world";
5
- //
6
- // 🧠 HEADINGS
7
- //
3
+ import { parseExpectOptions } from "../helpers/utils/optionsUtils"; // Assuming this path is correct
4
+ import type { CustomWorld } from "../helpers/world"; // Assuming this path is correct
8
5
 
9
- Then("I see heading {string}", async function (this: CustomWorld, text: string) {
10
- const heading = await this.page.locator("h1, h2, h3, h4, h5, h6", { hasText: text }).first();
11
- if (!(await heading.isVisible())) {
12
- throw new Error(`Heading "${text}" not found or not visible`);
13
- }
14
- });
6
+ // ===================================================================================
7
+ // ASSERTIONS: HEADINGS (H1-H6)
8
+ // ===================================================================================
15
9
 
16
- Then("I do not see heading {string}", async function (this: CustomWorld, text: string) {
17
- const heading = this.page.locator("h1, h2, h3, h4, h5, h6", {
18
- hasText: text,
19
- });
20
- if ((await heading.count()) > 0) {
21
- const visible = await heading.first().isVisible();
22
- if (visible) throw new Error(`Heading "${text}" is visible but should not be`);
23
- }
24
- });
10
+ /**
11
+ * Asserts that a heading element (h1-h6) containing the given text is visible on the page.
12
+ *
13
+ * ```gherkin
14
+ * Then I see heading {string}
15
+ * ```
16
+ *
17
+ * @param text - The text content expected within the heading.
18
+ *
19
+ * @example
20
+ * Then I see heading "Welcome to your account"
21
+ *
22
+ * @remarks
23
+ * This step searches for any HTML heading tag (`<h1>` through `<h6>`) that contains the specified text.
24
+ * It uses Playwright's `expect().toBeVisible()` to confirm both existence and visibility, which
25
+ * includes automatic waiting.
26
+ * @category Heading Assertion Steps
27
+ */
28
+ export async function Then_I_see_heading(this: CustomWorld, text: string) {
29
+ // Use `hasText` for partial or full text match
30
+ const headingLocator = this.page.locator("h1, h2, h3, h4, h5, h6", { hasText: text }).first();
31
+ await expect(headingLocator).toBeVisible({ timeout: 5000 });
32
+ this.log?.(`✅ Verified heading "${text}" is visible.`);
33
+ }
34
+ Then("I see heading {string}", Then_I_see_heading);
25
35
 
26
- //
27
- // 🏷️ LABELS
28
- //
36
+ /**
37
+ * Asserts that a heading element (h1-h6) containing the given text is NOT visible on the page.
38
+ *
39
+ * ```gherkin
40
+ * Then I do not see heading {string}
41
+ * ```
42
+ *
43
+ * @param text - The text content expected NOT to be visible within a heading.
44
+ *
45
+ * @example
46
+ * Then I do not see heading "Hidden Section"
47
+ *
48
+ * @remarks
49
+ * This step searches for any HTML heading tag (`<h1>` through `<h6>`) that contains the specified text.
50
+ * It uses Playwright's `expect().not.toBeVisible()` to confirm both absence and non-visibility,
51
+ * which includes automatic waiting.
52
+ * @category Heading Assertion Steps
53
+ */
54
+ export async function Then_I_do_not_see_heading(this: CustomWorld, text: string) {
55
+ const headingLocator = this.page.locator("h1, h2, h3, h4, h5, h6", { hasText: text }).first();
56
+ await expect(headingLocator).not.toBeVisible({ timeout: 5000 });
57
+ this.log?.(`✅ Verified heading "${text}" is NOT visible.`);
58
+ }
59
+ Then("I do not see heading {string}", Then_I_do_not_see_heading);
29
60
 
30
- Then("I see label {string}", async function (this: CustomWorld, text: string) {
31
- const label = this.page.getByLabel(text);
32
- if (!(await label.isVisible())) {
33
- throw new Error(`Label "${text}" not visible`);
34
- }
35
- });
61
+ // ===================================================================================
62
+ // ASSERTIONS: LABELS
63
+ // ===================================================================================
36
64
 
37
- Then("I do not see label {string}", async function (this: CustomWorld, text: string) {
38
- const label = this.page.getByLabel(text);
39
- if ((await label.count()) > 0 && (await label.first().isVisible())) {
40
- throw new Error(`Label "${text}" is visible but should not be`);
41
- }
42
- });
65
+ /**
66
+ * Asserts that a `<label>` element with the given text is visible on the page.
67
+ *
68
+ * ```gherkin
69
+ * Then I see label {string}
70
+ * ```
71
+ *
72
+ * @param text - The text content of the label expected to be visible.
73
+ *
74
+ * @example
75
+ * Then I see label "Username"
76
+ * Then I see label "I agree to the terms and conditions"
77
+ *
78
+ * @remarks
79
+ * This step uses Playwright's `page.getByLabel()` which is designed to find labels
80
+ * and implicitly connected form controls. It then uses `expect().toBeVisible()`
81
+ * to confirm visibility.
82
+ * @category Label Assertion Steps
83
+ */
84
+ export async function Then_I_see_label(this: CustomWorld, text: string) {
85
+ const labelLocator = this.page.getByLabel(text);
86
+ await expect(labelLocator).toBeVisible({ timeout: 5000 });
87
+ this.log?.(`✅ Verified label "${text}" is visible.`);
88
+ }
89
+ Then("I see label {string}", Then_I_see_label);
43
90
 
44
- //
45
- // 🔗 LINKS
46
- //
47
- Then("I see link {string}", async function (this: CustomWorld, text: string) {
48
- const link = this.page.getByRole("link", { name: text });
49
- if (!(await link.isVisible())) {
50
- throw new Error(`Link "${text}" not visible`);
51
- }
52
- });
91
+ /**
92
+ * Asserts that a `<label>` element with the given text is NOT visible on the page.
93
+ *
94
+ * ```gherkin
95
+ * Then I do not see label {string}
96
+ * ```
97
+ *
98
+ * @param text - The text content of the label expected NOT to be visible.
99
+ *
100
+ * @example
101
+ * Then I do not see label "Old Feature Toggle"
102
+ *
103
+ * @remarks
104
+ * This step uses Playwright's `page.getByLabel()` and then `expect().not.toBeVisible()`
105
+ * to confirm its non-visibility.
106
+ * @category Label Assertion Steps
107
+ */
108
+ export async function Then_I_do_not_see_label(this: CustomWorld, text: string) {
109
+ const labelLocator = this.page.getByLabel(text);
110
+ await expect(labelLocator).not.toBeVisible({ timeout: 5000 });
111
+ this.log?.(`✅ Verified label "${text}" is NOT visible.`);
112
+ }
113
+ Then("I do not see label {string}", Then_I_do_not_see_label);
53
114
 
54
- Then("I do not see link {string}", async function (this: CustomWorld, text: string) {
55
- const link = this.page.getByRole("link", { name: text });
56
- if ((await link.count()) > 0 && (await link.first().isVisible())) {
57
- throw new Error(`Link "${text}" is visible but should not be`);
58
- }
59
- });
60
- Then("I count {int} element", async function (count: number) {
61
- const locator = this.currentLocator ?? this.page.locator("*");
62
- await expect(locator).toHaveCount(count);
63
- });
64
- //document title assertions
65
- Then(
66
- "I see document title {string}",
67
- async function (this: CustomWorld, expected: string, table?: DataTable) {
68
- const options = parseExpectOptions(table);
69
- await expect(this.page).toHaveTitle(expected, options);
70
- }
71
- );
115
+ // ===================================================================================
116
+ // ASSERTIONS: LINKS
117
+ // ===================================================================================
72
118
 
73
- Then(
74
- "I see document title contains {string}",
75
- async function (this: CustomWorld, substring: string, table?: DataTable) {
76
- const options = parseExpectOptions(table);
77
- await expect(this.page).toHaveTitle(new RegExp(substring, "i"), options);
78
- }
79
- );
119
+ /**
120
+ * Asserts that a link (`<a>` tag) with the given accessible name (text content) is visible on the page.
121
+ *
122
+ * ```gherkin
123
+ * Then I see link {string}
124
+ * ```
125
+ *
126
+ * @param text - The accessible name (text) of the link expected to be visible.
127
+ *
128
+ * @example
129
+ * Then I see link "Home"
130
+ * Then I see link "View Details"
131
+ *
132
+ * @remarks
133
+ * This step uses Playwright's `page.getByRole("link", { name: text })` for robust
134
+ * link finding based on accessible name, then `expect().toBeVisible()` for visibility.
135
+ * @category Link Assertion Steps
136
+ */
137
+ export async function Then_I_see_link(this: CustomWorld, text: string) {
138
+ const linkLocator = this.page.getByRole("link", { name: text });
139
+ await expect(linkLocator).toBeVisible({ timeout: 5000 });
140
+ this.log?.(`✅ Verified link "${text}" is visible.`);
141
+ }
142
+ Then("I see link {string}", Then_I_see_link);
143
+
144
+ /**
145
+ * Asserts that a link (`<a>` tag) with the given accessible name (text content) is NOT visible on the page.
146
+ *
147
+ * ```gherkin
148
+ * Then I do not see link {string}
149
+ * ```
150
+ *
151
+ * @param text - The accessible name (text) of the link expected NOT to be visible.
152
+ *
153
+ * @example
154
+ * Then I do not see link "Admin Panel"
155
+ *
156
+ * @remarks
157
+ * This step uses Playwright's `page.getByRole("link", { name: text })` and then
158
+ * `expect().not.toBeVisible()` to confirm its non-visibility.
159
+ * @category Link Assertion Steps
160
+ */
161
+ export async function Then_I_do_not_see_link(this: CustomWorld, text: string) {
162
+ const linkLocator = this.page.getByRole("link", { name: text });
163
+ await expect(linkLocator).not.toBeVisible({ timeout: 5000 });
164
+ this.log?.(`✅ Verified link "${text}" is NOT visible.`);
165
+ }
166
+ Then("I do not see link {string}", Then_I_do_not_see_link);
167
+
168
+ // ===================================================================================
169
+ // ASSERTIONS: LOCATOR COUNT
170
+ // ===================================================================================
171
+
172
+ /**
173
+ * Asserts that the number of elements found by the {@link CustomWorld.currentLocator | currentLocator}
174
+ * matches the expected count. If no `currentLocator` is set, it defaults to counting all elements (`*`).
175
+ *
176
+ * ```gherkin
177
+ * Then I count {int} element
178
+ * ```
179
+ *
180
+ * @param expectedCount - The expected number of elements.
181
+ *
182
+ * @example
183
+ * When I find elements by selector ".product-item"
184
+ * Then I count 10 element
185
+ *
186
+ * @remarks
187
+ * This step is designed to follow a "find elements" step that sets `this.currentLocator`
188
+ * or `this.elements` (if `this.elements` is the intended source, you might prefer a
189
+ * step like `Then I count {int} elements` which specifically targets `this.elements`).
190
+ * The current implementation uses `this.currentLocator` or defaults to `this.page.locator("*")`.
191
+ * @category Count Assertion Steps
192
+ */
193
+ export async function Then_I_count_current_locator_elements(
194
+ this: CustomWorld,
195
+ expectedCount: number
196
+ ) {
197
+ // If currentLocator is not set, default to finding all elements on the page.
198
+ // This might lead to unexpected behavior if not intended.
199
+ const locatorToCount = this.currentLocator ?? this.page.locator("*");
200
+ await expect(locatorToCount).toHaveCount(expectedCount, { timeout: 5000 });
201
+ this.log?.(`✅ Verified current locator has ${expectedCount} element(s).`);
202
+ }
203
+ Then("I count {int} element", Then_I_count_current_locator_elements);
204
+
205
+ // ===================================================================================
206
+ // ASSERTIONS: DOCUMENT TITLE
207
+ // ===================================================================================
208
+
209
+ /**
210
+ * Asserts that the current document title exactly matches the expected string.
211
+ *
212
+ * ```gherkin
213
+ * Then I see document title {string}
214
+ * ```
215
+ *
216
+ * @param expectedTitle - The exact title string expected for the document.
217
+ * @param table - (Optional) A Cucumber DataTable for Playwright `ExpectOptions` (e.g., `timeout`).
218
+ *
219
+ * @example
220
+ * Then I see document title "My Application Dashboard"
221
+ *
222
+ * @remarks
223
+ * This step uses Playwright's `expect(page).toHaveTitle()` for robust assertion,
224
+ * including automatic waiting for the title to become correct.
225
+ * @category Page State Assertion Steps
226
+ */
227
+ export async function Then_I_see_document_title(
228
+ this: CustomWorld,
229
+ expectedTitle: string,
230
+ table?: DataTable
231
+ ) {
232
+ const options = parseExpectOptions(table);
233
+ await expect(this.page).toHaveTitle(expectedTitle, options);
234
+ this.log?.(`✅ Verified document title is "${expectedTitle}".`);
235
+ }
236
+ Then("I see document title {string}", Then_I_see_document_title);
237
+
238
+ /**
239
+ * Asserts that the current document title contains the expected substring (case-insensitive).
240
+ *
241
+ * ```gherkin
242
+ * Then I see document title contains {string}
243
+ * ```
244
+ *
245
+ * @param substring - The substring expected to be contained within the document title.
246
+ * @param table - (Optional) A Cucumber DataTable for Playwright `ExpectOptions`.
247
+ *
248
+ * @example
249
+ * Then I see document title contains "App Name"
250
+ * Then I see document title contains "Dashboard"
251
+ *
252
+ * @remarks
253
+ * This step uses Playwright's `expect(page).toHaveTitle()` with a case-insensitive regular
254
+ * expression for partial matching, ensuring automatic waiting.
255
+ * @category Page State Assertion Steps
256
+ */
257
+ export async function Then_I_see_document_title_contains(
258
+ this: CustomWorld,
259
+ substring: string,
260
+ table?: DataTable
261
+ ) {
262
+ const options = parseExpectOptions(table);
263
+ // Use RegExp for case-insensitive partial match
264
+ await expect(this.page).toHaveTitle(new RegExp(substring, "i"), options);
265
+ this.log?.(`✅ Verified document title contains "${substring}".`);
266
+ }
267
+ Then("I see document title contains {string}", Then_I_see_document_title_contains);
@@ -1,89 +1,250 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { When, Then } from "@cucumber/cucumber";
4
- import type { CustomWorld } from "../helpers/world";
5
- //
6
- // 🗃 LOCAL STORAGE
7
- //
1
+ // import fs from "fs";
2
+ // import path from "path";
3
+ import { Then } from "@cucumber/cucumber";
4
+ import { expect } from "@playwright/test"; // Import expect for assertions
5
+ import type { CustomWorld } from "../helpers/world"; // Assuming this path is correct
8
6
 
9
- Then("I see local storage item {string}", async function (this: CustomWorld, key: string) {
7
+ // ===================================================================================
8
+ // ASSERTIONS: LOCAL STORAGE
9
+ // ===================================================================================
10
+
11
+ /**
12
+ * Asserts that a Local Storage item with the given key exists for the current page's origin.
13
+ *
14
+ * ```gherkin
15
+ * Then I see local storage item {string}
16
+ * ```
17
+ *
18
+ * @param key - The key of the Local Storage item expected to exist.
19
+ *
20
+ * @example
21
+ * Then I see local storage item "token"
22
+ *
23
+ * @remarks
24
+ * This step executes `localStorage.getItem(key)` in the browser's context.
25
+ * It asserts that the returned value is not `null`, indicating the item exists.
26
+ * @category Storage Assertion Steps
27
+ */
28
+ export async function Then_I_see_local_storage_item(this: CustomWorld, key: string) {
10
29
  const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
11
- if (value === null) throw new Error(`Local storage item "${key}" not found`);
12
- });
30
+ expect(value, `Local storage item "${key}" should exist but was not found.`).not.toBeNull();
31
+ this.log?.(`✅ Verified local storage item "${key}" exists.`);
32
+ }
33
+ Then("I see local storage item {string}", Then_I_see_local_storage_item);
13
34
 
14
- Then("I do not see local storage item {string}", async function (this: CustomWorld, key: string) {
35
+ /**
36
+ * Asserts that a Local Storage item with the given key does NOT exist for the current page's origin.
37
+ *
38
+ * ```gherkin
39
+ * Then I do not see local storage item {string}
40
+ * ```
41
+ *
42
+ * @param key - The key of the Local Storage item expected NOT to exist.
43
+ *
44
+ * @example
45
+ * Then I do not see local storage item "oldFeatureFlag"
46
+ *
47
+ * @remarks
48
+ * This step executes `localStorage.getItem(key)` in the browser's context.
49
+ * It asserts that the returned value is strictly `null`, indicating the item does not exist.
50
+ * @category Storage Assertion Steps
51
+ */
52
+ export async function Then_I_do_not_see_local_storage_item(this: CustomWorld, key: string) {
15
53
  const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
16
- if (value !== null)
17
- throw new Error(`Expected localStorage["${key}"] to be null, but got "${value}"`);
18
- });
54
+ expect(
55
+ value,
56
+ `Expected localStorage["${key}"] to be null, but it exists with value "${value}".`
57
+ ).toBeNull();
58
+ this.log?.(`✅ Verified local storage item "${key}" does NOT exist.`);
59
+ }
60
+ Then("I do not see local storage item {string}", Then_I_do_not_see_local_storage_item);
19
61
 
20
- Then(
21
- "I see local storage item {string} equals {string}",
22
- async function (this: CustomWorld, key: string, expected: string) {
23
- const actual = await this.page.evaluate((k) => localStorage.getItem(k), key);
24
- if (actual !== expected) {
25
- throw new Error(`Expected localStorage["${key}"] to be "${expected}", but got "${actual}"`);
26
- }
27
- }
28
- );
62
+ /**
63
+ * Asserts that a Local Storage item with the given key exactly equals the expected value.
64
+ *
65
+ * ```gherkin
66
+ * Then I see local storage item {string} equals {string}
67
+ * ```
68
+ *
69
+ * @param key - The key of the Local Storage item.
70
+ * @param expectedValue - The exact value the item is expected to have.
71
+ *
72
+ * @example
73
+ * Then I see local storage item "token" equals "abc123"
74
+ *
75
+ * @remarks
76
+ * This step executes `localStorage.getItem(key)` in the browser's context.
77
+ * It asserts strict equality between the retrieved value and `expectedValue`.
78
+ * @category Storage Assertion Steps
79
+ */
80
+ export async function Then_I_see_local_storage_item_equals(
81
+ this: CustomWorld,
82
+ key: string,
83
+ expectedValue: string
84
+ ) {
85
+ const actualValue = await this.page.evaluate((k) => localStorage.getItem(k), key);
86
+ expect(
87
+ actualValue,
88
+ `Expected localStorage["${key}"] to be "${expectedValue}", but got "${actualValue}".`
89
+ ).toBe(expectedValue);
90
+ this.log?.(`✅ Verified local storage item "${key}" equals "${expectedValue}".`);
91
+ }
92
+ Then("I see local storage item {string} equals {string}", Then_I_see_local_storage_item_equals);
29
93
 
30
- Then(
31
- "I see local storage item {string} contains {string}",
32
- async function (this: CustomWorld, key: string, part: string) {
33
- const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
34
- if (!value || !value.includes(part)) {
35
- throw new Error(`localStorage["${key}"] does not contain "${part}". Got: "${value}"`);
36
- }
37
- }
38
- );
94
+ /**
95
+ * Asserts that a Local Storage item with the given key contains the expected substring.
96
+ *
97
+ * ```gherkin
98
+ * Then I see local storage item {string} contains {string}
99
+ * ```
100
+ *
101
+ * @param key - The key of the Local Storage item.
102
+ * @param part - The substring expected to be contained within the item's value.
103
+ *
104
+ * @example
105
+ * Then I see local storage item "userSession" contains "loggedIn"
106
+ *
107
+ * @remarks
108
+ * This step executes `localStorage.getItem(key)` in the browser's context.
109
+ * It asserts that the retrieved value (if not null) includes the `part` substring.
110
+ * @category Storage Assertion Steps
111
+ */
112
+ export async function Then_I_see_local_storage_item_contains(
113
+ this: CustomWorld,
114
+ key: string,
115
+ part: string
116
+ ) {
117
+ const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
118
+ expect(
119
+ value,
120
+ `Local storage item "${key}" not found or is null. Expected to contain "${part}".`
121
+ ).not.toBeNull();
122
+ expect(value, `localStorage["${key}"] ("${value}") does not contain "${part}".`).toContain(part);
123
+ this.log?.(`✅ Verified local storage item "${key}" contains "${part}".`);
124
+ }
125
+ Then("I see local storage item {string} contains {string}", Then_I_see_local_storage_item_contains);
39
126
 
40
- //
41
- // 🗂 SESSION STORAGE
42
- //
127
+ // ===================================================================================
128
+ // ASSERTIONS: SESSION STORAGE
129
+ // ===================================================================================
43
130
 
44
- Then("I see session storage item {string}", async function (this: CustomWorld, key: string) {
131
+ /**
132
+ * Asserts that a Session Storage item with the given key exists for the current page's origin.
133
+ *
134
+ * ```gherkin
135
+ * Then I see session storage item {string}
136
+ * ```
137
+ *
138
+ * @param key - The key of the Session Storage item expected to exist.
139
+ *
140
+ * @example
141
+ * Then I see session storage item "sessionId"
142
+ *
143
+ * @remarks
144
+ * This step executes `sessionStorage.getItem(key)` in the browser's context.
145
+ * It asserts that the returned value is not `null`, indicating the item exists.
146
+ * @category Storage Assertion Steps
147
+ */
148
+ export async function Then_I_see_session_storage_item(this: CustomWorld, key: string) {
45
149
  const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
46
- if (value === null) throw new Error(`Session storage item "${key}" not found`);
47
- });
150
+ expect(value, `Session storage item "${key}" should exist but was not found.`).not.toBeNull();
151
+ this.log?.(`✅ Verified session storage item "${key}" exists.`);
152
+ }
153
+ Then("I see session storage item {string}", Then_I_see_session_storage_item);
48
154
 
49
- Then("I do not see session storage item {string}", async function (this: CustomWorld, key: string) {
155
+ /**
156
+ * Asserts that a Session Storage item with the given key does NOT exist for the current page's origin.
157
+ *
158
+ * ```gherkin
159
+ * Then I do not see session storage item {string}
160
+ * ```
161
+ *
162
+ * @param key - The key of the Session Storage item expected NOT to exist.
163
+ *
164
+ * @example
165
+ * Then I do not see session storage item "tempData"
166
+ *
167
+ * @remarks
168
+ * This step executes `sessionStorage.getItem(key)` in the browser's context.
169
+ * It asserts that the returned value is strictly `null`, indicating the item does not exist.
170
+ * @category Storage Assertion Steps
171
+ */
172
+ export async function Then_I_do_not_see_session_storage_item(this: CustomWorld, key: string) {
50
173
  const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
51
- if (value !== null)
52
- throw new Error(`Expected sessionStorage["${key}"] to be null, but got "${value}"`);
53
- });
54
- When("I clear all saved session files", async function (this: CustomWorld) {
55
- const authDir = path.resolve("e2e/support/helper/auth");
174
+ expect(
175
+ value,
176
+ `Expected sessionStorage["${key}"] to be null, but it exists with value "${value}".`
177
+ ).toBeNull();
178
+ this.log?.(`✅ Verified session storage item "${key}" does NOT exist.`);
179
+ }
180
+ Then("I do not see session storage item {string}", Then_I_do_not_see_session_storage_item);
56
181
 
57
- if (fs.existsSync(authDir)) {
58
- const files = fs.readdirSync(authDir);
59
-
60
- for (const file of files) {
61
- const filePath = path.join(authDir, file);
62
- if (fs.lstatSync(filePath).isFile()) {
63
- fs.unlinkSync(filePath);
64
- this.log?.(`🧹 Deleted session file: ${file}`);
65
- }
66
- }
67
- } else {
68
- this.log?.(`⚠️ Auth directory not found at ${authDir}`);
69
- }
70
- });
71
- Then(
72
- "I see session storage item {string} equals {string}",
73
- async function (this: CustomWorld, key: string, expected: string) {
74
- const actual = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
75
- if (actual !== expected) {
76
- throw new Error(`Expected sessionStorage["${key}"] to be "${expected}", but got "${actual}"`);
77
- }
78
- }
79
- );
182
+ /**
183
+ * Asserts that a Session Storage item with the given key exactly equals the expected value.
184
+ *
185
+ * ```gherkin
186
+ * Then I see session storage item {string} equals {string}
187
+ * ```
188
+ *
189
+ * @param key - The key of the Session Storage item.
190
+ * @param expectedValue - The exact value the item is expected to have.
191
+ *
192
+ * @example
193
+ * Then I see session storage item "sessionId" equals "xyz789"
194
+ *
195
+ * @remarks
196
+ * This step executes `sessionStorage.getItem(key)` in the browser's context.
197
+ * It asserts strict equality between the retrieved value and `expectedValue`.
198
+ * @category Storage Assertion Steps
199
+ */
200
+ export async function Then_I_see_session_storage_item_equals(
201
+ this: CustomWorld,
202
+ key: string,
203
+ expectedValue: string
204
+ ) {
205
+ const actualValue = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
206
+ expect(
207
+ actualValue,
208
+ `Expected sessionStorage["${key}"] to be "${expectedValue}", but got "${actualValue}".`
209
+ ).toBe(expectedValue);
210
+ this.log?.(`✅ Verified session storage item "${key}" equals "${expectedValue}".`);
211
+ }
212
+ Then("I see session storage item {string} equals {string}", Then_I_see_session_storage_item_equals);
80
213
 
214
+ /**
215
+ * Asserts that a Session Storage item with the given key contains the expected substring.
216
+ *
217
+ * ```gherkin
218
+ * Then I see session storage item {string} contains {string}
219
+ * ```
220
+ *
221
+ * @param key - The key of the Session Storage item.
222
+ * @param part - The substring expected to be contained within the item's value.
223
+ *
224
+ * @example
225
+ * Then I see session storage item "userState" contains "authenticated"
226
+ *
227
+ * @remarks
228
+ * This step executes `sessionStorage.getItem(key)` in the browser's context.
229
+ * It asserts that the retrieved value (if not null) includes the `part` substring.
230
+ * @category Storage Assertion Steps
231
+ */
232
+ export async function Then_I_see_session_storage_item_contains(
233
+ this: CustomWorld,
234
+ key: string,
235
+ part: string
236
+ ) {
237
+ const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
238
+ expect(
239
+ value,
240
+ `Session storage item "${key}" not found or is null. Expected to contain "${part}".`
241
+ ).not.toBeNull();
242
+ expect(value, `sessionStorage["${key}"] ("${value}") does not contain "${part}".`).toContain(
243
+ part
244
+ );
245
+ this.log?.(`✅ Verified session storage item "${key}" contains "${part}".`);
246
+ }
81
247
  Then(
82
248
  "I see session storage item {string} contains {string}",
83
- async function (this: CustomWorld, key: string, part: string) {
84
- const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
85
- if (!value || !value.includes(part)) {
86
- throw new Error(`sessionStorage["${key}"] does not contain "${part}". Got: "${value}"`);
87
- }
88
- }
249
+ Then_I_see_session_storage_item_contains
89
250
  );