playwright-cucumber-ts-steps 0.1.6 → 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 (105) hide show
  1. package/README.md +21 -11
  2. package/package.json +9 -2
  3. package/src/actions/clickSteps.ts +429 -0
  4. package/src/actions/cookieSteps.ts +95 -0
  5. package/src/actions/debugSteps.ts +21 -0
  6. package/src/actions/elementFindSteps.ts +961 -0
  7. package/src/actions/fillFormSteps.ts +270 -0
  8. package/src/actions/index.ts +12 -0
  9. package/src/actions/inputSteps.ts +354 -0
  10. package/src/actions/interceptionSteps.ts +325 -0
  11. package/src/actions/miscSteps.ts +1144 -0
  12. package/src/actions/mouseSteps.ts +256 -0
  13. package/src/actions/scrollSteps.ts +122 -0
  14. package/src/actions/storageSteps.ts +308 -0
  15. package/src/assertions/buttonAndTextVisibilitySteps.ts +436 -0
  16. package/src/assertions/cookieSteps.ts +131 -0
  17. package/src/assertions/elementSteps.ts +432 -0
  18. package/src/assertions/formInputSteps.ts +377 -0
  19. package/src/assertions/index.ts +11 -0
  20. package/src/assertions/interceptionRequestsSteps.ts +640 -0
  21. package/src/assertions/locationSteps.ts +315 -0
  22. package/src/assertions/roleTestIdSteps.ts +254 -0
  23. package/src/assertions/semanticSteps.ts +267 -0
  24. package/src/assertions/storageSteps.ts +250 -0
  25. package/src/assertions/visualSteps.ts +275 -0
  26. package/src/custom_setups/loginHooks.ts +154 -0
  27. package/src/helpers/checkPeerDeps.ts +19 -0
  28. package/src/helpers/compareSnapshots.ts +35 -0
  29. package/src/helpers/hooks.ts +212 -0
  30. package/src/helpers/utils/fakerUtils.ts +64 -0
  31. package/src/helpers/utils/optionsUtils.ts +104 -0
  32. package/src/helpers/utils/resolveUtils.ts +74 -0
  33. package/src/helpers/utils/sessionUtils.ts +36 -0
  34. package/src/helpers/world.ts +119 -0
  35. package/src/iframes/frames.ts +15 -0
  36. package/src/index.ts +18 -0
  37. package/src/register.ts +4 -0
  38. package/lib/actions/clickSteps.d.ts +0 -1
  39. package/lib/actions/clickSteps.js +0 -165
  40. package/lib/actions/cookieSteps.d.ts +0 -1
  41. package/lib/actions/cookieSteps.js +0 -28
  42. package/lib/actions/debugSteps.d.ts +0 -1
  43. package/lib/actions/debugSteps.js +0 -8
  44. package/lib/actions/elementFindSteps.d.ts +0 -1
  45. package/lib/actions/elementFindSteps.js +0 -217
  46. package/lib/actions/fillFormSteps.d.ts +0 -1
  47. package/lib/actions/fillFormSteps.js +0 -130
  48. package/lib/actions/inputSteps.d.ts +0 -1
  49. package/lib/actions/inputSteps.js +0 -97
  50. package/lib/actions/interceptionSteps.d.ts +0 -1
  51. package/lib/actions/interceptionSteps.js +0 -71
  52. package/lib/actions/miscSteps.d.ts +0 -1
  53. package/lib/actions/miscSteps.js +0 -320
  54. package/lib/actions/mouseSteps.d.ts +0 -1
  55. package/lib/actions/mouseSteps.js +0 -66
  56. package/lib/actions/scrollSteps.d.ts +0 -1
  57. package/lib/actions/scrollSteps.js +0 -23
  58. package/lib/actions/storageSteps.d.ts +0 -1
  59. package/lib/actions/storageSteps.js +0 -72
  60. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -1
  61. package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -150
  62. package/lib/assertions/cookieSteps.d.ts +0 -1
  63. package/lib/assertions/cookieSteps.js +0 -45
  64. package/lib/assertions/elementSteps.d.ts +0 -1
  65. package/lib/assertions/elementSteps.js +0 -90
  66. package/lib/assertions/formInputSteps.d.ts +0 -1
  67. package/lib/assertions/formInputSteps.js +0 -87
  68. package/lib/assertions/interceptionRequestsSteps.d.ts +0 -1
  69. package/lib/assertions/interceptionRequestsSteps.js +0 -201
  70. package/lib/assertions/locationSteps.d.ts +0 -1
  71. package/lib/assertions/locationSteps.js +0 -87
  72. package/lib/assertions/roleTestIdSteps.d.ts +0 -1
  73. package/lib/assertions/roleTestIdSteps.js +0 -26
  74. package/lib/assertions/semanticSteps.d.ts +0 -1
  75. package/lib/assertions/semanticSteps.js +0 -67
  76. package/lib/assertions/storageSteps.d.ts +0 -1
  77. package/lib/assertions/storageSteps.js +0 -74
  78. package/lib/assertions/visualSteps.d.ts +0 -1
  79. package/lib/assertions/visualSteps.js +0 -76
  80. package/lib/custom_setups/loginHooks.d.ts +0 -1
  81. package/lib/custom_setups/loginHooks.js +0 -113
  82. package/lib/helpers/checkPeerDeps.d.ts +0 -1
  83. package/lib/helpers/checkPeerDeps.js +0 -19
  84. package/lib/helpers/compareSnapshots.d.ts +0 -6
  85. package/lib/helpers/compareSnapshots.js +0 -20
  86. package/lib/helpers/hooks.d.ts +0 -1
  87. package/lib/helpers/hooks.js +0 -210
  88. package/lib/helpers/utils/fakerUtils.d.ts +0 -1
  89. package/lib/helpers/utils/fakerUtils.js +0 -60
  90. package/lib/helpers/utils/index.js +0 -20
  91. package/lib/helpers/utils/optionsUtils.d.ts +0 -24
  92. package/lib/helpers/utils/optionsUtils.js +0 -88
  93. package/lib/helpers/utils/resolveUtils.d.ts +0 -6
  94. package/lib/helpers/utils/resolveUtils.js +0 -72
  95. package/lib/helpers/utils/sessionUtils.d.ts +0 -3
  96. package/lib/helpers/utils/sessionUtils.js +0 -40
  97. package/lib/helpers/world.d.ts +0 -31
  98. package/lib/helpers/world.js +0 -104
  99. package/lib/iframes/frames.d.ts +0 -1
  100. package/lib/iframes/frames.js +0 -11
  101. package/lib/index.d.ts +0 -28
  102. package/lib/index.js +0 -48
  103. package/lib/register.d.ts +0 -1
  104. package/lib/register.js +0 -6
  105. /package/{lib/helpers/utils/index.d.ts → src/helpers/utils/index.ts} +0 -0
@@ -0,0 +1,377 @@
1
+ import { Then } from "@cucumber/cucumber";
2
+ import { expect } from "@playwright/test";
3
+ import { CustomWorld } from "../helpers/world"; // Assuming this path is correct
4
+
5
+ // ===================================================================================
6
+ // ASSERTIONS: INPUT VALUES
7
+ // ===================================================================================
8
+
9
+ /**
10
+ * Asserts that an input element matching the given selector has an exact expected value.
11
+ *
12
+ * ```gherkin
13
+ * Then I see input {string} has value {string}
14
+ * ```
15
+ *
16
+ * @param selector - The CSS selector of the input element (e.g., "input[name='email']").
17
+ * @param expectedValue - The exact value the input is expected to have.
18
+ *
19
+ * @example
20
+ * Then I see input "input[name='email']" has value "user@example.com"
21
+ *
22
+ * @remarks
23
+ * This step uses Playwright's `expect(locator).toHaveValue()` which automatically waits
24
+ * for the input to have the specified value.
25
+ * @category Input Assertion Steps
26
+ */
27
+ export async function Then_I_see_input_has_value(
28
+ this: CustomWorld,
29
+ selector: string,
30
+ expectedValue: string
31
+ ) {
32
+ const locator = this.page.locator(selector);
33
+ await expect(locator).toHaveValue(expectedValue, { timeout: 5000 });
34
+ this.log?.(`✅ Verified input "${selector}" has value: "${expectedValue}".`);
35
+ }
36
+ Then(/^I see input "([^"]+)" has value "(.*)"$/, Then_I_see_input_has_value);
37
+
38
+ /**
39
+ * Asserts that the previously stored input element has an exact expected value.
40
+ *
41
+ * ```gherkin
42
+ * Then I see input value {string}
43
+ * ```
44
+ *
45
+ * @param expectedValue - The exact value the stored input is expected to have.
46
+ *
47
+ * @example
48
+ * When I find element by selector "input[name='email']"
49
+ * Then I see input value "user@example.com"
50
+ *
51
+ * @remarks
52
+ * This step requires a preceding step that sets the {@link CustomWorld.element | current element}
53
+ * to an input element. It uses Playwright's `locator.inputValue()` to get the current value
54
+ * and asserts strict equality.
55
+ * @category Input Assertion Steps
56
+ */
57
+ export async function Then_I_see_stored_input_value(this: CustomWorld, expectedValue: string) {
58
+ if (!this.element)
59
+ throw new Error("No element stored in context. Use a 'find' step to select an input.");
60
+ await expect(this.element).toHaveValue(expectedValue, { timeout: 5000 });
61
+ this.log?.(`✅ Verified stored input has value: "${expectedValue}".`);
62
+ }
63
+ Then("I see input value {string}", Then_I_see_stored_input_value);
64
+
65
+ /**
66
+ * Asserts that the previously stored input element's value contains a given substring.
67
+ *
68
+ * ```gherkin
69
+ * Then I see input value contains {string}
70
+ * ```
71
+ *
72
+ * @param part - The substring expected to be contained within the input's value.
73
+ *
74
+ * @example
75
+ * When I find element by selector "input[name='email']"
76
+ * Then I see input value contains "@gmail.com"
77
+ *
78
+ * @remarks
79
+ * This step requires a preceding step that sets the {@link CustomWorld.element | current element}
80
+ * to an input element. It uses Playwright's `locator.inputValue()` and then checks for substring presence.
81
+ * @category Input Assertion Steps
82
+ */
83
+ export async function Then_I_see_stored_input_value_contains(this: CustomWorld, part: string) {
84
+ if (!this.element)
85
+ throw new Error("No element stored in context. Use a 'find' step to select an input.");
86
+ // Use Playwright's toHaveValue with a regex for 'contains'
87
+ await expect(this.element).toHaveValue(new RegExp(part), { timeout: 5000 });
88
+ this.log?.(`✅ Verified stored input value contains: "${part}".`);
89
+ }
90
+ Then("I see input value contains {string}", Then_I_see_stored_input_value_contains);
91
+
92
+ /**
93
+ * Asserts that an input element matching the given selector's value contains a given substring.
94
+ *
95
+ * ```gherkin
96
+ * Then I see input {string} value contains {string}
97
+ * ```
98
+ *
99
+ * @param selector - The CSS selector of the input element.
100
+ * @param partial - The substring expected to be contained within the input's value.
101
+ *
102
+ * @example
103
+ * Then I see input "input[name='email']" value contains "@gmail.com"
104
+ *
105
+ * @remarks
106
+ * This step uses Playwright's `locator.inputValue()` and asserts that the value includes the substring.
107
+ * @category Input Assertion Steps
108
+ */
109
+ export async function Then_I_see_input_value_contains(
110
+ this: CustomWorld,
111
+ selector: string,
112
+ partial: string
113
+ ) {
114
+ const locator = this.page.locator(selector);
115
+ // Use Playwright's toHaveValue with a regex for 'contains'
116
+ await expect(locator).toHaveValue(new RegExp(partial), { timeout: 5000 });
117
+ this.log?.(`✅ Verified input "${selector}" value contains: "${partial}".`);
118
+ }
119
+ Then(/^I see input "([^"]+)" value contains "(.*)"$/, Then_I_see_input_value_contains);
120
+
121
+ // ===================================================================================
122
+ // ASSERTIONS: TEXTAREA VALUES
123
+ // ===================================================================================
124
+
125
+ /**
126
+ * Asserts that a textarea element matching the given selector has an exact expected value.
127
+ *
128
+ * ```gherkin
129
+ * Then I see textarea {string} has value {string}
130
+ * ```
131
+ *
132
+ * @param selector - The CSS selector of the textarea element (e.g., "textarea[name='bio']").
133
+ * @param expectedValue - The exact value the textarea is expected to have.
134
+ *
135
+ * @example
136
+ * Then I see textarea "textarea[name='bio']" has value "Hello"
137
+ *
138
+ * @remarks
139
+ * This step uses Playwright's `expect(locator).toHaveValue()` which automatically waits
140
+ * for the textarea to have the specified value.
141
+ * @category Textarea Assertion Steps
142
+ */
143
+ export async function Then_I_see_textarea_has_value(
144
+ this: CustomWorld,
145
+ selector: string,
146
+ expectedValue: string
147
+ ) {
148
+ const locator = this.page.locator(selector);
149
+ await expect(locator).toHaveValue(expectedValue, { timeout: 5000 });
150
+ this.log?.(`✅ Verified textarea "${selector}" has value: "${expectedValue}".`);
151
+ }
152
+ Then(/^I see textarea "([^"]+)" has value "(.*)"$/, Then_I_see_textarea_has_value);
153
+
154
+ /**
155
+ * Asserts that the previously stored textarea element has an exact expected value.
156
+ *
157
+ * ```gherkin
158
+ * Then I see textarea value {string}
159
+ * ```
160
+ *
161
+ * @param expectedValue - The exact value the stored textarea is expected to have.
162
+ *
163
+ * @example
164
+ * When I find element by selector "textarea[name='bio']"
165
+ * Then I see textarea value "Hello"
166
+ *
167
+ * @remarks
168
+ * This step requires a preceding step that sets the {@link CustomWorld.element | current element}
169
+ * to a textarea element. It uses Playwright's `locator.inputValue()` to get the current value
170
+ * and asserts strict equality.
171
+ * @category Textarea Assertion Steps
172
+ */
173
+ export async function Then_I_see_stored_textarea_value(this: CustomWorld, expectedValue: string) {
174
+ if (!this.element)
175
+ throw new Error("No textarea selected. Use a 'find' step to select a textarea.");
176
+ await expect(this.element).toHaveValue(expectedValue, { timeout: 5000 });
177
+ this.log?.(`✅ Verified stored textarea has value: "${expectedValue}".`);
178
+ }
179
+ Then("I see textarea value {string}", Then_I_see_stored_textarea_value);
180
+
181
+ /**
182
+ * Asserts that the previously stored textarea element's value contains a given substring.
183
+ *
184
+ * ```gherkin
185
+ * Then I see textarea value contains {string}
186
+ * ```
187
+ *
188
+ * @param part - The substring expected to be contained within the textarea's value.
189
+ *
190
+ * @example
191
+ * When I find element by selector "textarea[name='bio']"
192
+ * Then I see textarea value contains "Hello"
193
+ *
194
+ * @remarks
195
+ * This step requires a preceding step that sets the {@link CustomWorld.element | current element}
196
+ * to a textarea element. It uses Playwright's `locator.inputValue()` and then checks for substring presence.
197
+ * @category Textarea Assertion Steps
198
+ */
199
+ export async function Then_I_see_stored_textarea_value_contains(this: CustomWorld, part: string) {
200
+ if (!this.element)
201
+ throw new Error("No textarea selected. Use a 'find' step to select a textarea.");
202
+ // Use Playwright's toHaveValue with a regex for 'contains'
203
+ await expect(this.element).toHaveValue(new RegExp(part), { timeout: 5000 });
204
+ this.log?.(`✅ Verified stored textarea value contains: "${part}".`);
205
+ }
206
+ Then("I see textarea value contains {string}", Then_I_see_stored_textarea_value_contains);
207
+
208
+ /**
209
+ * Asserts that a textarea element matching the given selector's value contains a given substring.
210
+ *
211
+ * ```gherkin
212
+ * Then I see textarea {string} value contains {string}
213
+ * ```
214
+ *
215
+ * @param selector - The CSS selector of the textarea element.
216
+ * @param partial - The substring expected to be contained within the textarea's value.
217
+ *
218
+ * @example
219
+ * Then I see textarea "textarea[name='bio']" value contains "Hello"
220
+ *
221
+ * @remarks
222
+ * This step uses Playwright's `locator.inputValue()` and asserts that the value includes the substring.
223
+ * @category Textarea Assertion Steps
224
+ */
225
+ export async function Then_I_see_textarea_value_contains(
226
+ this: CustomWorld,
227
+ selector: string,
228
+ partial: string
229
+ ) {
230
+ const locator = this.page.locator(selector);
231
+ // Use Playwright's toHaveValue with a regex for 'contains'
232
+ await expect(locator).toHaveValue(new RegExp(partial), { timeout: 5000 });
233
+ this.log?.(`✅ Verified textarea "${selector}" value contains: "${partial}".`);
234
+ }
235
+ Then(/^I see textarea "([^"]+)" value contains "(.*)"$/, Then_I_see_textarea_value_contains);
236
+
237
+ // ===================================================================================
238
+ // ASSERTIONS: GENERIC VALUE MATCHING (by Selector)
239
+ // ===================================================================================
240
+
241
+ /**
242
+ * Asserts that an element matching the given selector has an exact expected value.
243
+ * This step is generic and can be used for inputs, textareas, or other elements
244
+ * whose value can be retrieved by Playwright's `toHaveValue`.
245
+ *
246
+ * ```gherkin
247
+ * Then I see value {string} in {string}
248
+ * ```
249
+ *
250
+ * @param expectedValue - The exact value expected.
251
+ * @param selector - The CSS selector of the element to check.
252
+ *
253
+ * @example
254
+ * Then I see value "foo" in "input[name='foo']"
255
+ * Then I see value "true" in "input[type='checkbox'][name='terms']"
256
+ *
257
+ * @remarks
258
+ * This step uses Playwright's `expect(locator).toHaveValue()` which is suitable
259
+ * for `<input>`, `<textarea>`, and `<select>` elements.
260
+ * @category Generic Assertion Steps
261
+ */
262
+ export async function Then_I_see_value_in_element(
263
+ this: CustomWorld,
264
+ expectedValue: string,
265
+ selector: string
266
+ ) {
267
+ const locator = this.page.locator(selector);
268
+ await expect(locator).toHaveValue(expectedValue, { timeout: 5000 });
269
+ this.log?.(`✅ Verified value "${expectedValue}" in element "${selector}".`);
270
+ }
271
+ Then(/^I see value "(.*)" in "([^"]+)"$/, Then_I_see_value_in_element);
272
+
273
+ /**
274
+ * Asserts that an element matching the given selector does NOT have a specific value.
275
+ *
276
+ * ```gherkin
277
+ * Then I do not see value {string} in {string}
278
+ * ```
279
+ *
280
+ * @param unwantedValue - The value that is expected NOT to be found.
281
+ * @param selector - The CSS selector of the element to check.
282
+ *
283
+ * @example
284
+ * Then I do not see value "guest" in "input[name='userRole']"
285
+ *
286
+ * @remarks
287
+ * This step uses Playwright's `expect(locator).not.toHaveValue()` for robust assertion.
288
+ * @category Generic Assertion Steps
289
+ */
290
+ export async function Then_I_do_not_see_value_in_element(
291
+ this: CustomWorld,
292
+ unwantedValue: string,
293
+ selector: string
294
+ ) {
295
+ const locator = this.page.locator(selector);
296
+ await expect(locator).not.toHaveValue(unwantedValue, { timeout: 5000 });
297
+ this.log?.(`✅ Verified value "${unwantedValue}" is NOT in element "${selector}".`);
298
+ }
299
+ Then(/^I do not see value "(.*)" in "([^"]+)"$/, Then_I_do_not_see_value_in_element);
300
+
301
+ // ===================================================================================
302
+ // ASSERTIONS: OPTION IN SELECT ELEMENTS
303
+ // ===================================================================================
304
+
305
+ /**
306
+ * Asserts that an `<option>` element with the given text exists in the DOM.
307
+ * It does not necessarily assert that it is selected or visible within a `<select>` element.
308
+ *
309
+ * ```gherkin
310
+ * Then I see option {string}
311
+ * ```
312
+ *
313
+ * @param optionText - The text of the option expected to exist.
314
+ *
315
+ * @example
316
+ * Then I see option "Admin"
317
+ *
318
+ * @remarks
319
+ * This step directly targets `<option>` tags by their text content.
320
+ * It asserts that at least one such option exists in the DOM.
321
+ * @category Select Option Assertion Steps
322
+ */
323
+ export async function Then_I_see_option(this: CustomWorld, optionText: string) {
324
+ const locator = this.page.locator(`option`, { hasText: optionText });
325
+ await expect(locator).toHaveCount(1, { timeout: 5000 });
326
+ this.log?.(`✅ Verified option "${optionText}" exists.`);
327
+ }
328
+ Then(/^I see option "(.*)"$/, Then_I_see_option); // Regex for flexibility
329
+ Then("I see option {string}", Then_I_see_option); // Strict string for clarity, links to same implementation
330
+
331
+ /**
332
+ * Asserts that an `<option>` element with the given text is NOT visible.
333
+ *
334
+ * ```gherkin
335
+ * Then I do not see option {string}
336
+ * ```
337
+ *
338
+ * @param optionText - The text of the option expected NOT to be visible.
339
+ *
340
+ * @example
341
+ * Then I do not see option "Deprecated Feature"
342
+ *
343
+ * @remarks
344
+ * This step targets `<option>` tags by their text content and asserts that
345
+ * any matching options are not visible. This is useful for dynamically hidden options.
346
+ * @category Select Option Assertion Steps
347
+ */
348
+ export async function Then_I_do_not_see_option(this: CustomWorld, optionText: string) {
349
+ const locator = this.page.locator(`option`, { hasText: optionText });
350
+ await expect(locator).not.toBeVisible({ timeout: 5000 });
351
+ this.log?.(`✅ Verified option "${optionText}" is NOT visible.`);
352
+ }
353
+ Then("I do not see option {string}", Then_I_do_not_see_option);
354
+
355
+ /**
356
+ * Asserts that an `<option>` element with the given text does NOT exist in the DOM.
357
+ *
358
+ * ```gherkin
359
+ * Then I do not see option {string} (regex pattern)
360
+ * ```
361
+ *
362
+ * @param optionText - The text of the option expected NOT to exist in the DOM.
363
+ *
364
+ * @example
365
+ * Then I do not see option "Super Admin"
366
+ *
367
+ * @remarks
368
+ * This step targets `<option>` tags by their text content and asserts that
369
+ * no such option is present in the DOM. This is useful for verifying removed options.
370
+ * @category Select Option Assertion Steps
371
+ */
372
+ export async function Then_I_do_not_see_option_exists(this: CustomWorld, optionText: string) {
373
+ const locator = this.page.locator(`option`, { hasText: optionText });
374
+ await expect(locator).toHaveCount(0, { timeout: 5000 });
375
+ this.log?.(`✅ Verified option "${optionText}" does NOT exist.`);
376
+ }
377
+ Then(/^I do not see option "(.*)"$/, Then_I_do_not_see_option_exists);
@@ -0,0 +1,11 @@
1
+ // Assertions
2
+ export * from "./buttonAndTextVisibilitySteps";
3
+ export * from "./cookieSteps";
4
+ export * from "./elementSteps";
5
+ export * from "./formInputSteps";
6
+ export * from "./interceptionRequestsSteps";
7
+ export * from "./locationSteps";
8
+ export * from "./roleTestIdSteps";
9
+ export * from "./semanticSteps";
10
+ export * from "./storageSteps";
11
+ export * from "./visualSteps";