playwright-cucumber-ts-steps 1.0.0 → 1.0.2

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 (60) hide show
  1. package/README.md +195 -256
  2. package/dist/backend/actions/index.js +4 -0
  3. package/dist/backend/actions/interactions.js +23 -0
  4. package/dist/backend/actions/navigation.js +19 -0
  5. package/dist/backend/api/assertions.js +26 -0
  6. package/dist/backend/api/index.js +4 -0
  7. package/dist/backend/api/requests.js +24 -0
  8. package/dist/backend/api/state.js +15 -0
  9. package/dist/backend/assertions/expectVisible.js +8 -0
  10. package/dist/backend/assertions/index.js +5 -0
  11. package/dist/backend/assertions/pageState.js +25 -0
  12. package/dist/backend/assertions/text.js +20 -0
  13. package/dist/backend/assertions/visibility.js +20 -0
  14. package/dist/backend/auth/index.js +71 -0
  15. package/dist/backend/elements/alerts.js +21 -0
  16. package/dist/backend/elements/forms.js +59 -0
  17. package/dist/backend/elements/frames.js +25 -0
  18. package/dist/backend/elements/index.js +5 -0
  19. package/dist/core/registry.js +20 -0
  20. package/dist/core/runner.js +136 -0
  21. package/dist/index.js +10 -0
  22. package/dist/reporting/index.js +43 -0
  23. package/package.json +19 -101
  24. package/LICENSE +0 -21
  25. package/src/actions/clickSteps.ts +0 -429
  26. package/src/actions/cookieSteps.ts +0 -95
  27. package/src/actions/debugSteps.ts +0 -21
  28. package/src/actions/elementFindSteps.ts +0 -961
  29. package/src/actions/fillFormSteps.ts +0 -270
  30. package/src/actions/index.ts +0 -12
  31. package/src/actions/inputSteps.ts +0 -354
  32. package/src/actions/interceptionSteps.ts +0 -325
  33. package/src/actions/miscSteps.ts +0 -1144
  34. package/src/actions/mouseSteps.ts +0 -256
  35. package/src/actions/scrollSteps.ts +0 -122
  36. package/src/actions/storageSteps.ts +0 -308
  37. package/src/assertions/buttonAndTextVisibilitySteps.ts +0 -436
  38. package/src/assertions/cookieSteps.ts +0 -131
  39. package/src/assertions/elementSteps.ts +0 -432
  40. package/src/assertions/formInputSteps.ts +0 -377
  41. package/src/assertions/index.ts +0 -11
  42. package/src/assertions/interceptionRequestsSteps.ts +0 -640
  43. package/src/assertions/locationSteps.ts +0 -315
  44. package/src/assertions/roleTestIdSteps.ts +0 -254
  45. package/src/assertions/semanticSteps.ts +0 -267
  46. package/src/assertions/storageSteps.ts +0 -250
  47. package/src/assertions/visualSteps.ts +0 -275
  48. package/src/custom_setups/loginHooks.ts +0 -154
  49. package/src/helpers/checkPeerDeps.ts +0 -19
  50. package/src/helpers/compareSnapshots.ts +0 -35
  51. package/src/helpers/hooks.ts +0 -212
  52. package/src/helpers/utils/fakerUtils.ts +0 -64
  53. package/src/helpers/utils/index.ts +0 -4
  54. package/src/helpers/utils/optionsUtils.ts +0 -104
  55. package/src/helpers/utils/resolveUtils.ts +0 -74
  56. package/src/helpers/utils/sessionUtils.ts +0 -36
  57. package/src/helpers/world.ts +0 -119
  58. package/src/iframes/frames.ts +0 -15
  59. package/src/index.ts +0 -18
  60. package/src/register.ts +0 -4
@@ -1,432 +0,0 @@
1
- import { Then } from "@cucumber/cucumber";
2
- import { expect } from "@playwright/test";
3
- import type { CustomWorld } from "../helpers/world"; // Assuming this path is correct
4
-
5
- // ===================================================================================
6
- // ASSERTIONS: ELEMENT EXISTENCE (IN DOM)
7
- // ===================================================================================
8
-
9
- /**
10
- * Asserts that at least one element matching the given selector exists in the DOM.
11
- * It does not necessarily check for visibility.
12
- *
13
- * ```gherkin
14
- * Then I see element {string} exists
15
- * ```
16
- *
17
- * @param selector - The CSS selector of the element expected to exist.
18
- *
19
- * @example
20
- * Then I see element ".user-profile-card" exists
21
- *
22
- * @remarks
23
- * This step uses Playwright's `expect(locator).toHaveCount(1)` as a robust way to
24
- * assert that exactly one matching element is present in the DOM. If multiple elements
25
- * match, it will still pass as long as at least one exists (though `toHaveCount(1)`
26
- * would strictly mean *only one*). For asserting multiple elements, use "Then I count X elements".
27
- * @category Assertion Steps
28
- */
29
- export async function Then_I_see_element_exists(this: CustomWorld, selector: string) {
30
- const locator = this.page.locator(selector);
31
- // Using toHaveCount(1) for "exists" implies expecting at least one, or exactly one.
32
- // If the intent is *at least one*, expect(locator).first().waitFor({state: 'attached'}) is also an option.
33
- // For strict "exists", toHaveCount(1) is good if you expect uniqueness.
34
- await expect(locator).toHaveCount(1, { timeout: 5000 });
35
- this.log?.(`✅ Verified element "${selector}" exists in the DOM.`);
36
- }
37
- Then(/^I see element "([^"]+)" exists$/, Then_I_see_element_exists);
38
-
39
- /**
40
- * Asserts that the previously stored element exists in the DOM.
41
- * This checks for its presence, not necessarily its visibility.
42
- *
43
- * ```gherkin
44
- * Then I see element exists
45
- * ```
46
- *
47
- * @example
48
- * When I find element by selector ".my-dialog"
49
- * Then I see element exists
50
- *
51
- * @remarks
52
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
53
- * It asserts that the stored element is attached to the DOM.
54
- * @category Assertion Steps
55
- */
56
- export async function Then_I_see_stored_element_exists(this: CustomWorld) {
57
- if (!this.element)
58
- throw new Error("No element stored in context. Use a 'find' step before asserting.");
59
-
60
- // Playwright's toBeAttached is the most robust way to check for DOM existence
61
- await expect(this.element).toBeAttached({ timeout: 5000 });
62
- this.log?.(`✅ Verified stored element exists in the DOM.`);
63
- }
64
- Then("I see element exists", Then_I_see_stored_element_exists);
65
-
66
- /**
67
- * Asserts that the previously stored element does NOT exist in the DOM.
68
- *
69
- * ```gherkin
70
- * Then I see element does not exist
71
- * ```
72
- *
73
- * @example
74
- * When I find element by selector "#deleted-item"
75
- * Then I see element does not exist
76
- *
77
- * @remarks
78
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
79
- * It asserts that the stored element is detached from the DOM.
80
- * @category Assertion Steps
81
- */
82
- export async function Then_I_see_stored_element_does_not_exist(this: CustomWorld) {
83
- if (!this.element)
84
- throw new Error("No element stored in context. Use a 'find' step before asserting.");
85
-
86
- // Playwright's not.toBeAttached is the most robust way to check for DOM non-existence
87
- await expect(this.element).not.toBeAttached({ timeout: 5000 });
88
- this.log?.(`✅ Verified stored element does NOT exist in the DOM.`);
89
- }
90
- Then("I see element does not exist", Then_I_see_stored_element_does_not_exist);
91
-
92
- // ===================================================================================
93
- // ASSERTIONS: ELEMENT VISIBILITY (Stored Element)
94
- // ===================================================================================
95
-
96
- /**
97
- * Asserts that the previously stored element is visible in the viewport.
98
- *
99
- * ```gherkin
100
- * Then I see element is visible
101
- * ```
102
- *
103
- * @example
104
- * When I find element by selector ".success-message"
105
- * Then I see element is visible
106
- *
107
- * @remarks
108
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
109
- * It uses Playwright's `expect(locator).toBeVisible()` which automatically waits
110
- * for the element to become visible.
111
- * @category Assertion Steps
112
- */
113
- export async function Then_I_see_stored_element_is_visible(this: CustomWorld) {
114
- if (!this.element) throw new Error("No element stored in context to check visibility.");
115
-
116
- await expect(this.element).toBeVisible({ timeout: 5000 });
117
- this.log?.(`✅ Verified stored element is visible.`);
118
- }
119
- Then("I see element is visible", Then_I_see_stored_element_is_visible);
120
-
121
- /**
122
- * Asserts that the previously stored element is NOT visible in the viewport.
123
- *
124
- * ```gherkin
125
- * Then I see element is not visible
126
- * ```
127
- *
128
- * @example
129
- * When I find element by selector ".loading-spinner"
130
- * Then I see element is not visible
131
- *
132
- * @remarks
133
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
134
- * It uses Playwright's `expect(locator).not.toBeVisible()` which automatically waits
135
- * for the element to become hidden.
136
- * @category Assertion Steps
137
- */
138
- export async function Then_I_see_stored_element_is_not_visible(this: CustomWorld) {
139
- if (!this.element) throw new Error("No element stored in context to check non-visibility.");
140
-
141
- await expect(this.element).not.toBeVisible({ timeout: 5000 });
142
- this.log?.(`✅ Verified stored element is NOT visible.`);
143
- }
144
- Then("I see element is not visible", Then_I_see_stored_element_is_not_visible);
145
-
146
- // ===================================================================================
147
- // ASSERTIONS: ELEMENT EXISTENCE (Absence by Selector)
148
- // ===================================================================================
149
-
150
- /**
151
- * Asserts that no element matching the given selector exists in the DOM.
152
- *
153
- * ```gherkin
154
- * Then I see element {string} does not exist
155
- * ```
156
- *
157
- * @param selector - The CSS selector of the element expected NOT to exist.
158
- *
159
- * @example
160
- * Then I see element ".old-feature-flag" does not exist
161
- *
162
- * @remarks
163
- * This step uses Playwright's `expect(locator).toHaveCount(0)` as a robust way to
164
- * assert that no matching elements are present in the DOM.
165
- * @category Assertion Steps
166
- */
167
- export async function Then_I_see_element_does_not_exist(this: CustomWorld, selector: string) {
168
- const locator = this.page.locator(selector);
169
- await expect(locator).toHaveCount(0, { timeout: 5000 });
170
- this.log?.(`✅ Verified element "${selector}" does NOT exist in the DOM.`);
171
- }
172
- Then(/^I see element "([^"]+)" does not exist$/, Then_I_see_element_does_not_exist);
173
-
174
- // ===================================================================================
175
- // ASSERTIONS: ELEMENT VISIBILITY (by Selector)
176
- // ===================================================================================
177
-
178
- /**
179
- * Asserts that an element matching the given selector is visible in the viewport.
180
- *
181
- * ```gherkin
182
- * Then I see element {string} is visible
183
- * ```
184
- *
185
- * @param selector - The CSS selector of the element expected to be visible.
186
- *
187
- * @example
188
- * Then I see element ".main-content" is visible
189
- *
190
- * @remarks
191
- * This step uses Playwright's `expect(locator).toBeVisible()` which automatically waits
192
- * for the element to become visible.
193
- * @category Assertion Steps
194
- */
195
- export async function Then_I_see_element_is_visible(this: CustomWorld, selector: string) {
196
- const locator = this.page.locator(selector);
197
- await expect(locator).toBeVisible({ timeout: 5000 });
198
- this.log?.(`✅ Verified element "${selector}" is visible.`);
199
- }
200
- Then(/^I see element "([^"]+)" is visible$/, Then_I_see_element_is_visible);
201
-
202
- /**
203
- * Asserts that an element matching the given selector is NOT visible in the viewport.
204
- *
205
- * ```gherkin
206
- * Then I see element {string} is not visible
207
- * ```
208
- *
209
- * @param selector - The CSS selector of the element expected NOT to be visible.
210
- *
211
- * @example
212
- * Then I see element ".modal-overlay" is not visible
213
- *
214
- * @remarks
215
- * This step uses Playwright's `expect(locator).not.toBeVisible()` which automatically waits
216
- * for the element to become hidden.
217
- * @category Assertion Steps
218
- */
219
- export async function Then_I_see_element_is_not_visible(this: CustomWorld, selector: string) {
220
- const locator = this.page.locator(selector);
221
- await expect(locator).not.toBeVisible({ timeout: 5000 });
222
- this.log?.(`✅ Verified element "${selector}" is NOT visible.`);
223
- }
224
- Then(/^I see element "([^"]+)" is not visible$/, Then_I_see_element_is_not_visible);
225
-
226
- // ===================================================================================
227
- // ASSERTIONS: ATTRIBUTE VALUES
228
- // ===================================================================================
229
-
230
- /**
231
- * Asserts that an element matching the given selector has a specific attribute with an exact value.
232
- *
233
- * ```gherkin
234
- * Then I see element {string} attribute {string} equals {string}
235
- * ```
236
- *
237
- * @param selector - The CSS selector of the element to check.
238
- * @param attribute - The name of the attribute (e.g., "id", "class", "data-test").
239
- * @param expectedValue - The exact expected value of the attribute.
240
- *
241
- * @example
242
- * Then I see element ".submit-button" attribute "disabled" equals "true"
243
- *
244
- * @remarks
245
- * This step uses Playwright's `expect(locator).toHaveAttribute()`.
246
- * @category Attribute Assertion Steps
247
- */
248
- export async function Then_I_see_element_attribute_equals(
249
- this: CustomWorld,
250
- selector: string,
251
- attribute: string,
252
- expectedValue: string
253
- ) {
254
- const locator = this.page.locator(selector);
255
- await expect(locator).toHaveAttribute(attribute, expectedValue, { timeout: 5000 });
256
- this.log?.(
257
- `✅ Verified element "${selector}" has attribute "${attribute}" equal to "${expectedValue}".`
258
- );
259
- }
260
- Then(
261
- /^I see element "([^"]+)" attribute "([^"]+)" equals "(.*)"$/,
262
- Then_I_see_element_attribute_equals
263
- );
264
-
265
- /**
266
- * Asserts that the previously stored element has a specific attribute with an exact value.
267
- *
268
- * ```gherkin
269
- * Then I see element attribute {string} equals {string}
270
- * ```
271
- *
272
- * @param attr - The name of the attribute to check.
273
- * @param expectedValue - The exact expected value of the attribute.
274
- *
275
- * @example
276
- * When I find element by selector "input[name='rememberMe']"
277
- * Then I see element attribute "checked" equals "checked"
278
- *
279
- * @remarks
280
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
281
- * It uses Playwright's `expect(locator).toHaveAttribute()`.
282
- * @category Attribute Assertion Steps
283
- */
284
- export async function Then_I_see_stored_element_attribute_equals(
285
- this: CustomWorld,
286
- attr: string,
287
- expectedValue: string
288
- ) {
289
- if (!this.element) {
290
- throw new Error(
291
- "No element is currently selected. Use a 'find' step before asserting its attributes."
292
- );
293
- }
294
- await expect(this.element).toHaveAttribute(attr, expectedValue, { timeout: 5000 });
295
- this.log?.(`✅ Verified stored element has attribute "${attr}" equal to "${expectedValue}".`);
296
- }
297
- Then(
298
- 'I see element attribute "{word}" equals {string}',
299
- Then_I_see_stored_element_attribute_equals
300
- );
301
-
302
- /**
303
- * Asserts that the previously stored element has a specific attribute, regardless of its value.
304
- *
305
- * ```gherkin
306
- * Then I see element has attribute {string}
307
- * ```
308
- *
309
- * @param attr - The name of the attribute expected to exist.
310
- *
311
- * @example
312
- * When I find element by selector "img.user-avatar"
313
- * Then I see element has attribute "alt"
314
- *
315
- * @remarks
316
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
317
- * It retrieves the attribute's value and asserts that it's not `null` (meaning the attribute is present).
318
- * @category Attribute Assertion Steps
319
- */
320
- export async function Then_I_see_stored_element_has_attribute(this: CustomWorld, attr: string) {
321
- if (!this.element) throw new Error("No element stored in context to check for attribute.");
322
-
323
- // Use Playwright's expect.toHaveAttribute for robust checking of existence (value can be empty string, but not null)
324
- // For simply checking existence, we can assert that the attribute is not null or undefined.
325
- const attributeValue = await this.element.getAttribute(attr, { timeout: 5000 });
326
- expect(attributeValue).not.toBeNull();
327
- this.log?.(`✅ Verified stored element has attribute "${attr}".`);
328
- }
329
- Then("I see element has attribute {string}", Then_I_see_stored_element_has_attribute);
330
-
331
- /**
332
- * Asserts that the previously stored element's specific attribute contains a given substring.
333
- *
334
- * ```gherkin
335
- * Then I see element attribute {string} contains {string}
336
- * ```
337
- *
338
- * @param attr - The name of the attribute to check.
339
- * @param part - The substring expected to be contained within the attribute's value.
340
- *
341
- * @example
342
- * When I find element by selector ".product-image"
343
- * Then I see element attribute "src" contains "thumbnail"
344
- *
345
- * @remarks
346
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
347
- * It retrieves the attribute's value and asserts that it includes the `part` substring.
348
- * @category Attribute Assertion Steps
349
- */
350
- export async function Then_I_see_stored_element_attribute_contains(
351
- this: CustomWorld,
352
- attr: string,
353
- part: string
354
- ) {
355
- if (!this.element) throw new Error("No element stored in context to check attribute content.");
356
-
357
- // Use Playwright's expect.toHaveAttribute with a regex for 'contains' check
358
- await expect(this.element).toHaveAttribute(attr, new RegExp(part), { timeout: 5000 });
359
- this.log?.(`✅ Verified stored element attribute "${attr}" contains "${part}".`);
360
- }
361
- Then(
362
- 'I see element attribute "{word}" contains {string}',
363
- Then_I_see_stored_element_attribute_contains
364
- );
365
-
366
- /**
367
- * Asserts that an element matching the given selector has a specific attribute containing a given substring.
368
- *
369
- * ```gherkin
370
- * Then I see element {string} attribute {string} contains {string}
371
- * ```
372
- *
373
- * @param selector - The CSS selector of the element to check.
374
- * @param attribute - The name of the attribute.
375
- * @param substring - The substring expected to be contained within the attribute's value.
376
- *
377
- * @example
378
- * Then I see element "a.download-link" attribute "href" contains ".pdf"
379
- *
380
- * @remarks
381
- * This step retrieves the attribute's value from the element matching the selector
382
- * and asserts that it includes the `substring`.
383
- * @category Attribute Assertion Steps
384
- */
385
- export async function Then_I_see_element_attribute_contains(
386
- this: CustomWorld,
387
- selector: string,
388
- attribute: string,
389
- substring: string
390
- ) {
391
- const locator = this.page.locator(selector);
392
- // Use Playwright's expect.toHaveAttribute with a regex for 'contains' check
393
- await expect(locator).toHaveAttribute(attribute, new RegExp(substring), { timeout: 5000 });
394
- this.log?.(`✅ Verified element "${selector}" attribute "${attribute}" contains "${substring}".`);
395
- }
396
- Then(
397
- /^I see element "([^"]+)" attribute "([^"]+)" contains "(.*)"$/,
398
- Then_I_see_element_attribute_contains
399
- );
400
-
401
- /**
402
- * Asserts that an element matching the given selector has a specific attribute, regardless of its value.
403
- *
404
- * ```gherkin
405
- * Then I see element {string} has attribute {string}
406
- * ```
407
- *
408
- * @param selector - The CSS selector of the element to check.
409
- * @param attribute - The name of the attribute expected to exist.
410
- *
411
- * @example
412
- * Then I see element "img.avatar" has attribute "src"
413
- *
414
- * @remarks
415
- * This step retrieves the attribute's value from the element matching the selector
416
- * and asserts that it's not `null` (meaning the attribute is present).
417
- * @category Attribute Assertion Steps
418
- */
419
- export async function Then_I_see_element_has_attribute(
420
- this: CustomWorld,
421
- selector: string,
422
- attribute: string
423
- ) {
424
- const locator = this.page.locator(selector);
425
- // Playwright's toHaveAttribute with an empty string or regex can assert existence effectively.
426
- // toHaveAttribute(attr, /.+/) ensures it exists and has *some* non-empty value.
427
- // For just existence, checking if getAttribute is not null is explicit.
428
- const attributeValue = await locator.getAttribute(attribute, { timeout: 5000 });
429
- expect(attributeValue).not.toBeNull();
430
- this.log?.(`✅ Verified element "${selector}" has attribute "${attribute}".`);
431
- }
432
- Then(/^I see element "([^"]+)" has attribute "([^"]+)"$/, Then_I_see_element_has_attribute);