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.
Files changed (137) hide show
  1. package/README.md +270 -244
  2. package/dist/backend/actions/formTable.js +34 -0
  3. package/dist/backend/actions/index.js +5 -0
  4. package/dist/backend/actions/interactions.js +23 -0
  5. package/dist/backend/actions/navigation.js +19 -0
  6. package/dist/backend/api/assertions.js +26 -0
  7. package/dist/backend/api/index.js +5 -0
  8. package/dist/backend/api/mock.js +75 -0
  9. package/dist/backend/api/requests.js +86 -0
  10. package/dist/backend/api/state.js +15 -0
  11. package/dist/backend/assertions/expectVisible.js +8 -0
  12. package/dist/backend/assertions/index.js +5 -0
  13. package/dist/backend/assertions/pageState.js +25 -0
  14. package/dist/backend/assertions/text.js +20 -0
  15. package/dist/backend/assertions/visibility.js +20 -0
  16. package/dist/backend/auth/index.js +71 -0
  17. package/dist/backend/db/index.js +6 -0
  18. package/dist/backend/db/state.js +24 -0
  19. package/dist/backend/db/steps.js +43 -0
  20. package/dist/backend/elements/alerts.js +21 -0
  21. package/dist/backend/elements/forms.js +59 -0
  22. package/dist/backend/elements/frames.js +25 -0
  23. package/dist/backend/elements/index.js +5 -0
  24. package/dist/core/registry.js +20 -0
  25. package/dist/core/runner.js +151 -0
  26. package/dist/index.js +10 -0
  27. package/dist/reporting/index.js +43 -0
  28. package/package.json +19 -101
  29. package/LICENSE +0 -21
  30. package/lib/actions/clickSteps.d.ts +0 -251
  31. package/lib/actions/clickSteps.js +0 -415
  32. package/lib/actions/cookieSteps.d.ts +0 -18
  33. package/lib/actions/cookieSteps.js +0 -93
  34. package/lib/actions/debugSteps.d.ts +0 -14
  35. package/lib/actions/debugSteps.js +0 -23
  36. package/lib/actions/elementFindSteps.d.ts +0 -668
  37. package/lib/actions/elementFindSteps.js +0 -931
  38. package/lib/actions/fillFormSteps.d.ts +0 -69
  39. package/lib/actions/fillFormSteps.js +0 -237
  40. package/lib/actions/index.d.ts +0 -11
  41. package/lib/actions/index.js +0 -28
  42. package/lib/actions/inputSteps.d.ts +0 -218
  43. package/lib/actions/inputSteps.js +0 -343
  44. package/lib/actions/interceptionSteps.d.ts +0 -169
  45. package/lib/actions/interceptionSteps.js +0 -291
  46. package/lib/actions/miscSteps.d.ts +0 -645
  47. package/lib/actions/miscSteps.js +0 -1061
  48. package/lib/actions/mouseSteps.d.ts +0 -143
  49. package/lib/actions/mouseSteps.js +0 -234
  50. package/lib/actions/scrollSteps.d.ts +0 -82
  51. package/lib/actions/scrollSteps.js +0 -123
  52. package/lib/actions/storageSteps.d.ts +0 -174
  53. package/lib/actions/storageSteps.js +0 -292
  54. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -245
  55. package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -401
  56. package/lib/assertions/cookieSteps.d.ts +0 -75
  57. package/lib/assertions/cookieSteps.js +0 -113
  58. package/lib/assertions/elementSteps.d.ts +0 -264
  59. package/lib/assertions/elementSteps.js +0 -388
  60. package/lib/assertions/formInputSteps.d.ts +0 -248
  61. package/lib/assertions/formInputSteps.js +0 -350
  62. package/lib/assertions/index.d.ts +0 -10
  63. package/lib/assertions/index.js +0 -27
  64. package/lib/assertions/interceptionRequestsSteps.d.ts +0 -353
  65. package/lib/assertions/interceptionRequestsSteps.js +0 -593
  66. package/lib/assertions/locationSteps.d.ts +0 -217
  67. package/lib/assertions/locationSteps.js +0 -310
  68. package/lib/assertions/roleTestIdSteps.d.ts +0 -159
  69. package/lib/assertions/roleTestIdSteps.js +0 -221
  70. package/lib/assertions/semanticSteps.d.ts +0 -176
  71. package/lib/assertions/semanticSteps.js +0 -252
  72. package/lib/assertions/storageSteps.d.ts +0 -149
  73. package/lib/assertions/storageSteps.js +0 -210
  74. package/lib/assertions/visualSteps.d.ts +0 -74
  75. package/lib/assertions/visualSteps.js +0 -209
  76. package/lib/custom_setups/loginHooks.d.ts +0 -1
  77. package/lib/custom_setups/loginHooks.js +0 -130
  78. package/lib/helpers/checkPeerDeps.d.ts +0 -1
  79. package/lib/helpers/checkPeerDeps.js +0 -19
  80. package/lib/helpers/compareSnapshots.d.ts +0 -6
  81. package/lib/helpers/compareSnapshots.js +0 -20
  82. package/lib/helpers/hooks.d.ts +0 -1
  83. package/lib/helpers/hooks.js +0 -210
  84. package/lib/helpers/utils/fakerUtils.d.ts +0 -1
  85. package/lib/helpers/utils/fakerUtils.js +0 -60
  86. package/lib/helpers/utils/index.d.ts +0 -4
  87. package/lib/helpers/utils/index.js +0 -20
  88. package/lib/helpers/utils/optionsUtils.d.ts +0 -24
  89. package/lib/helpers/utils/optionsUtils.js +0 -88
  90. package/lib/helpers/utils/resolveUtils.d.ts +0 -6
  91. package/lib/helpers/utils/resolveUtils.js +0 -72
  92. package/lib/helpers/utils/sessionUtils.d.ts +0 -3
  93. package/lib/helpers/utils/sessionUtils.js +0 -40
  94. package/lib/helpers/world.d.ts +0 -34
  95. package/lib/helpers/world.js +0 -110
  96. package/lib/iframes/frames.d.ts +0 -1
  97. package/lib/iframes/frames.js +0 -11
  98. package/lib/index.d.ts +0 -10
  99. package/lib/index.js +0 -28
  100. package/lib/register.d.ts +0 -1
  101. package/lib/register.js +0 -6
  102. package/src/actions/clickSteps.ts +0 -429
  103. package/src/actions/cookieSteps.ts +0 -95
  104. package/src/actions/debugSteps.ts +0 -21
  105. package/src/actions/elementFindSteps.ts +0 -961
  106. package/src/actions/fillFormSteps.ts +0 -270
  107. package/src/actions/index.ts +0 -12
  108. package/src/actions/inputSteps.ts +0 -354
  109. package/src/actions/interceptionSteps.ts +0 -325
  110. package/src/actions/miscSteps.ts +0 -1144
  111. package/src/actions/mouseSteps.ts +0 -256
  112. package/src/actions/scrollSteps.ts +0 -122
  113. package/src/actions/storageSteps.ts +0 -308
  114. package/src/assertions/buttonAndTextVisibilitySteps.ts +0 -436
  115. package/src/assertions/cookieSteps.ts +0 -131
  116. package/src/assertions/elementSteps.ts +0 -432
  117. package/src/assertions/formInputSteps.ts +0 -377
  118. package/src/assertions/index.ts +0 -11
  119. package/src/assertions/interceptionRequestsSteps.ts +0 -640
  120. package/src/assertions/locationSteps.ts +0 -315
  121. package/src/assertions/roleTestIdSteps.ts +0 -254
  122. package/src/assertions/semanticSteps.ts +0 -267
  123. package/src/assertions/storageSteps.ts +0 -250
  124. package/src/assertions/visualSteps.ts +0 -275
  125. package/src/custom_setups/loginHooks.ts +0 -154
  126. package/src/helpers/checkPeerDeps.ts +0 -19
  127. package/src/helpers/compareSnapshots.ts +0 -35
  128. package/src/helpers/hooks.ts +0 -212
  129. package/src/helpers/utils/fakerUtils.ts +0 -64
  130. package/src/helpers/utils/index.ts +0 -4
  131. package/src/helpers/utils/optionsUtils.ts +0 -104
  132. package/src/helpers/utils/resolveUtils.ts +0 -74
  133. package/src/helpers/utils/sessionUtils.ts +0 -36
  134. package/src/helpers/world.ts +0 -119
  135. package/src/iframes/frames.ts +0 -15
  136. package/src/index.ts +0 -18
  137. package/src/register.ts +0 -4
@@ -1,267 +0,0 @@
1
- import { Then, DataTable } from "@cucumber/cucumber";
2
- import { expect } from "@playwright/test";
3
- import { parseExpectOptions } from "../helpers/utils/optionsUtils"; // Assuming this path is correct
4
- import type { CustomWorld } from "../helpers/world"; // Assuming this path is correct
5
-
6
- // ===================================================================================
7
- // ASSERTIONS: HEADINGS (H1-H6)
8
- // ===================================================================================
9
-
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);
35
-
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);
60
-
61
- // ===================================================================================
62
- // ASSERTIONS: LABELS
63
- // ===================================================================================
64
-
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);
90
-
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);
114
-
115
- // ===================================================================================
116
- // ASSERTIONS: LINKS
117
- // ===================================================================================
118
-
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,250 +0,0 @@
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
6
-
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) {
29
- const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
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);
34
-
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) {
53
- const value = await this.page.evaluate((k) => localStorage.getItem(k), key);
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);
61
-
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);
93
-
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);
126
-
127
- // ===================================================================================
128
- // ASSERTIONS: SESSION STORAGE
129
- // ===================================================================================
130
-
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) {
149
- const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
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);
154
-
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) {
173
- const value = await this.page.evaluate((k) => sessionStorage.getItem(k), key);
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);
181
-
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);
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
- }
247
- Then(
248
- "I see session storage item {string} contains {string}",
249
- Then_I_see_session_storage_item_contains
250
- );