playwright-cucumber-ts-steps 1.0.1 → 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 (132) 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/lib/actions/clickSteps.d.ts +0 -251
  26. package/lib/actions/clickSteps.js +0 -415
  27. package/lib/actions/cookieSteps.d.ts +0 -18
  28. package/lib/actions/cookieSteps.js +0 -93
  29. package/lib/actions/debugSteps.d.ts +0 -14
  30. package/lib/actions/debugSteps.js +0 -23
  31. package/lib/actions/elementFindSteps.d.ts +0 -668
  32. package/lib/actions/elementFindSteps.js +0 -931
  33. package/lib/actions/fillFormSteps.d.ts +0 -69
  34. package/lib/actions/fillFormSteps.js +0 -237
  35. package/lib/actions/index.d.ts +0 -11
  36. package/lib/actions/index.js +0 -28
  37. package/lib/actions/inputSteps.d.ts +0 -218
  38. package/lib/actions/inputSteps.js +0 -343
  39. package/lib/actions/interceptionSteps.d.ts +0 -169
  40. package/lib/actions/interceptionSteps.js +0 -291
  41. package/lib/actions/miscSteps.d.ts +0 -645
  42. package/lib/actions/miscSteps.js +0 -1061
  43. package/lib/actions/mouseSteps.d.ts +0 -143
  44. package/lib/actions/mouseSteps.js +0 -234
  45. package/lib/actions/scrollSteps.d.ts +0 -82
  46. package/lib/actions/scrollSteps.js +0 -123
  47. package/lib/actions/storageSteps.d.ts +0 -174
  48. package/lib/actions/storageSteps.js +0 -292
  49. package/lib/assertions/buttonAndTextVisibilitySteps.d.ts +0 -245
  50. package/lib/assertions/buttonAndTextVisibilitySteps.js +0 -401
  51. package/lib/assertions/cookieSteps.d.ts +0 -75
  52. package/lib/assertions/cookieSteps.js +0 -113
  53. package/lib/assertions/elementSteps.d.ts +0 -264
  54. package/lib/assertions/elementSteps.js +0 -388
  55. package/lib/assertions/formInputSteps.d.ts +0 -248
  56. package/lib/assertions/formInputSteps.js +0 -350
  57. package/lib/assertions/index.d.ts +0 -10
  58. package/lib/assertions/index.js +0 -27
  59. package/lib/assertions/interceptionRequestsSteps.d.ts +0 -353
  60. package/lib/assertions/interceptionRequestsSteps.js +0 -593
  61. package/lib/assertions/locationSteps.d.ts +0 -217
  62. package/lib/assertions/locationSteps.js +0 -310
  63. package/lib/assertions/roleTestIdSteps.d.ts +0 -159
  64. package/lib/assertions/roleTestIdSteps.js +0 -221
  65. package/lib/assertions/semanticSteps.d.ts +0 -176
  66. package/lib/assertions/semanticSteps.js +0 -252
  67. package/lib/assertions/storageSteps.d.ts +0 -149
  68. package/lib/assertions/storageSteps.js +0 -210
  69. package/lib/assertions/visualSteps.d.ts +0 -74
  70. package/lib/assertions/visualSteps.js +0 -209
  71. package/lib/custom_setups/loginHooks.d.ts +0 -1
  72. package/lib/custom_setups/loginHooks.js +0 -130
  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 -34
  90. package/lib/helpers/world.js +0 -110
  91. package/lib/iframes/frames.d.ts +0 -1
  92. package/lib/iframes/frames.js +0 -11
  93. package/lib/index.d.ts +0 -10
  94. package/lib/index.js +0 -28
  95. package/lib/register.d.ts +0 -1
  96. package/lib/register.js +0 -6
  97. package/src/actions/clickSteps.ts +0 -429
  98. package/src/actions/cookieSteps.ts +0 -95
  99. package/src/actions/debugSteps.ts +0 -21
  100. package/src/actions/elementFindSteps.ts +0 -961
  101. package/src/actions/fillFormSteps.ts +0 -270
  102. package/src/actions/index.ts +0 -12
  103. package/src/actions/inputSteps.ts +0 -354
  104. package/src/actions/interceptionSteps.ts +0 -325
  105. package/src/actions/miscSteps.ts +0 -1144
  106. package/src/actions/mouseSteps.ts +0 -256
  107. package/src/actions/scrollSteps.ts +0 -122
  108. package/src/actions/storageSteps.ts +0 -308
  109. package/src/assertions/buttonAndTextVisibilitySteps.ts +0 -436
  110. package/src/assertions/cookieSteps.ts +0 -131
  111. package/src/assertions/elementSteps.ts +0 -432
  112. package/src/assertions/formInputSteps.ts +0 -377
  113. package/src/assertions/index.ts +0 -11
  114. package/src/assertions/interceptionRequestsSteps.ts +0 -640
  115. package/src/assertions/locationSteps.ts +0 -315
  116. package/src/assertions/roleTestIdSteps.ts +0 -254
  117. package/src/assertions/semanticSteps.ts +0 -267
  118. package/src/assertions/storageSteps.ts +0 -250
  119. package/src/assertions/visualSteps.ts +0 -275
  120. package/src/custom_setups/loginHooks.ts +0 -154
  121. package/src/helpers/checkPeerDeps.ts +0 -19
  122. package/src/helpers/compareSnapshots.ts +0 -35
  123. package/src/helpers/hooks.ts +0 -212
  124. package/src/helpers/utils/fakerUtils.ts +0 -64
  125. package/src/helpers/utils/index.ts +0 -4
  126. package/src/helpers/utils/optionsUtils.ts +0 -104
  127. package/src/helpers/utils/resolveUtils.ts +0 -74
  128. package/src/helpers/utils/sessionUtils.ts +0 -36
  129. package/src/helpers/world.ts +0 -119
  130. package/src/iframes/frames.ts +0 -15
  131. package/src/index.ts +0 -18
  132. package/src/register.ts +0 -4
@@ -1,245 +0,0 @@
1
- import type { CustomWorld } from "../helpers/world";
2
- /**
3
- * Asserts that the previously stored collection of elements has an exact expected count.
4
- *
5
- * ```gherkin
6
- * Then I count {int} elements
7
- * ```
8
- *
9
- * @param expectedCount - The expected number of elements in the collection.
10
- *
11
- * @example
12
- * Given I find elements by selector ".list-item"
13
- * Then I count 5 elements
14
- *
15
- * @remarks
16
- * This step requires a preceding step that populates {@link CustomWorld.elements | this.elements}
17
- * (e.g., "When I find elements by selector"). It then asserts that the number of
18
- * elements in that collection matches `expectedCount`. It also waits for `networkidle`
19
- * to ensure all elements that might affect the count have loaded.
20
- * @category Assertion Steps
21
- */
22
- export declare function Then_I_count_elements(this: CustomWorld, expectedCount: number): Promise<void>;
23
- /**
24
- * Asserts that a button with the given text (or text from an alias) is visible on the page.
25
- * The text matching is case-insensitive and can be partial.
26
- *
27
- * ```gherkin
28
- * Then I see button {string}
29
- * ```
30
- *
31
- * @param rawText - The text of the button, or an alias prefixed with "@" (e.g., "Submit", "@submitButtonLabel").
32
- *
33
- * @example
34
- * Then I see button "Sign In"
35
- * Then I see button "@myLoginButton"
36
- *
37
- * @remarks
38
- * This step uses `page.getByRole("button", { name: ..., exact: false })`.
39
- * It waits for the page to be network idle and then asserts that the button is visible.
40
- * @category Assertion Steps
41
- */
42
- export declare function Then_I_see_button(this: CustomWorld, rawText: string): Promise<void>;
43
- /**
44
- * Asserts that a button with the given text (or text from an alias) is NOT visible on the page.
45
- * The text matching is case-insensitive and can be partial.
46
- *
47
- * ```gherkin
48
- * Then I do not see button {string}
49
- * ```
50
- *
51
- * @param rawText - The text of the button, or an alias prefixed with "@".
52
- *
53
- * @example
54
- * Then I do not see button "Delete Account"
55
- * Then I do not see button "@hiddenAdminButton"
56
- *
57
- * @remarks
58
- * This step checks for the absence of a visible button. It first waits for the page
59
- * to be network idle, then finds potential buttons by role and name. If any matching
60
- * button is found and is visible, the step will fail.
61
- * @category Assertion Steps
62
- */
63
- export declare function Then_I_do_not_see_button(this: CustomWorld, rawText: string): Promise<void>;
64
- /**
65
- * Asserts that specific text is visible on the current page or within the current frame/scope.
66
- *
67
- * ```gherkin
68
- * Then I see text {string}
69
- * ```
70
- *
71
- * @param expectedText - The text string expected to be visible.
72
- *
73
- * @example
74
- * Then I see text "Welcome to your Dashboard"
75
- *
76
- * @remarks
77
- * This step uses `locator.waitFor({ state: "visible" })` to ensure the text is present
78
- * and displayed within the current Playwright scope (main page or active iframe).
79
- * Text matching is a substring match by default.
80
- * @category Assertion Steps
81
- */
82
- export declare function Then_I_see_text(this: CustomWorld, expectedText: string): Promise<void>;
83
- /**
84
- * Asserts that the exact visible text is present on the page.
85
- * This is similar to "I see text", but emphasizes "visible" for clarity.
86
- *
87
- * ```gherkin
88
- * Then I see visible text {string}
89
- * ```
90
- *
91
- * @param text - The exact text string expected to be visible.
92
- *
93
- * @example
94
- * Then I see visible text "Dashboard"
95
- *
96
- * @remarks
97
- * This step uses `:text-is()` pseudo-class for exact text matching and `isVisible()`
98
- * to confirm presence. It also waits for `networkidle` beforehand.
99
- * Consider consolidating with `Then I see text {string}` if you prefer `toBeVisible`
100
- * which handles exact matching via options or `text-is` more flexibly.
101
- * @category Assertion Steps
102
- */
103
- export declare function Then_I_see_visible_text(this: CustomWorld, text: string): Promise<void>;
104
- /**
105
- * Asserts that specific exact visible text is NOT present on the page.
106
- *
107
- * ```gherkin
108
- * Then I do not see visible text {string}
109
- * ```
110
- *
111
- * @param text - The exact text string expected NOT to be visible.
112
- *
113
- * @example
114
- * Then I do not see visible text "Logout"
115
- *
116
- * @remarks
117
- * This step uses `:text-is()` for exact text matching. It asserts that no element
118
- * with this exact text is visible.
119
- * @category Assertion Steps
120
- */
121
- export declare function Then_I_do_not_see_visible_text(this: CustomWorld, text: string): Promise<void>;
122
- /**
123
- * Asserts that the previously selected element has a specific input value.
124
- *
125
- * ```gherkin
126
- * Then I see value {string}
127
- * ```
128
- *
129
- * @param expectedValue - The expected exact value of the input or textarea.
130
- *
131
- * @example
132
- * When I find element by selector "input[name='email']"
133
- * Then I see value "test@example.com"
134
- *
135
- * @remarks
136
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}
137
- * to an input, textarea, or other element that has an input value.
138
- * It uses Playwright's `locator.inputValue()`.
139
- * @category Assertion Steps
140
- */
141
- export declare function Then_I_see_value(this: CustomWorld, expectedValue: string): Promise<void>;
142
- /**
143
- * Asserts that the previously selected element does NOT have a specific input value.
144
- *
145
- * ```gherkin
146
- * Then I do not see value {string}
147
- * ```
148
- *
149
- * @param unwantedValue - The value that is expected NOT to be present in the input or textarea.
150
- *
151
- * @example
152
- * When I find element by selector "input[name='password']"
153
- * Then I do not see value "admin123"
154
- *
155
- * @remarks
156
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
157
- * It asserts that the element's current input value does not match `unwantedValue`.
158
- * @category Assertion Steps
159
- */
160
- export declare function Then_I_do_not_see_value(this: CustomWorld, unwantedValue: string): Promise<void>;
161
- /**
162
- * Asserts that specific text is NOT present on the page. This checks for complete absence,
163
- * not just visibility.
164
- *
165
- * ```gherkin
166
- * Then I do not see text {string}
167
- * ```
168
- *
169
- * @param unexpectedText - The text string that is expected NOT to be found on the page.
170
- *
171
- * @example
172
- * Then I do not see text "Error Message"
173
- *
174
- * @remarks
175
- * This step uses `page.getByText` with `exact: true` and then asserts that the count
176
- * of matching elements is 0. This confirms the text is entirely absent from the DOM.
177
- * @category Assertion Steps
178
- */
179
- export declare function Then_I_do_not_see_text(this: CustomWorld, unexpectedText: string): Promise<void>;
180
- /**
181
- * Asserts that the previously selected element contains the given text,
182
- * which can be a literal string, an alias, or a Faker.js expression.
183
- *
184
- * ```gherkin
185
- * Then I see {string} in the element
186
- * ```
187
- *
188
- * @param expected - The text string, alias (prefixed with "@"), or Faker.js expression expected to be contained within the element's text content.
189
- *
190
- * @example
191
- * When I find element by selector "#welcome-message"
192
- * Then I see "Welcome, John Doe!" in the element
193
- * Given I store "user.name" as "loggedInUserName"
194
- * When I find element by selector "#user-profile-name"
195
- * Then I see "@loggedInUserName" in the element
196
- * Then I see "Hello, {{person.firstName}}!" in the element
197
- *
198
- * @remarks
199
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
200
- * It resolves aliases and Faker expressions before comparing the `textContent` of the element.
201
- * It uses `expect(textContent).toContain(expected)` for partial matching.
202
- * @category Assertion Steps
203
- */
204
- export declare function Then_I_see_text_in_the_element(this: CustomWorld, expected: string): Promise<void>;
205
- /**
206
- * Asserts that the previously selected element contains the value retrieved from a specific alias.
207
- *
208
- * ```gherkin
209
- * Then I see @{word} in the element
210
- * ```
211
- *
212
- * @param alias - The alias name from which to retrieve the expected text value.
213
- *
214
- * @example
215
- * Given I store "Generated Name" as "tempName"
216
- * When I find element by selector "#display-name"
217
- * Then I see @tempName in the element
218
- *
219
- * @remarks
220
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
221
- * It fetches the value from `this.data[alias]` and then asserts that the element's
222
- * `textContent` (trimmed) contains this stored value. This is a specialized version of
223
- * `Then I see {string} in the element` specifically for aliases.
224
- * @category Assertion Steps
225
- */
226
- export declare function Then_I_see_alias_in_the_element(this: CustomWorld, alias: string): Promise<void>;
227
- /**
228
- * Asserts that a button with the given text (or text from an alias) is disabled.
229
- *
230
- * ```gherkin
231
- * Then I see button {string} is disabled
232
- * ```
233
- *
234
- * @param rawText - The text of the button, or an alias prefixed with "@".
235
- *
236
- * @example
237
- * Then I see button "Submit" is disabled
238
- * Then I see button "@checkoutButton" is disabled
239
- *
240
- * @remarks
241
- * This step first locates the button by its role and name, asserts it's visible,
242
- * and then checks its disabled state using Playwright's `isDisabled()` method.
243
- * @category Assertion Steps
244
- */
245
- export declare function Then_I_see_button_is_disabled(this: CustomWorld, rawText: string): Promise<void>;
@@ -1,401 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Then_I_count_elements = Then_I_count_elements;
4
- exports.Then_I_see_button = Then_I_see_button;
5
- exports.Then_I_do_not_see_button = Then_I_do_not_see_button;
6
- exports.Then_I_see_text = Then_I_see_text;
7
- exports.Then_I_see_visible_text = Then_I_see_visible_text;
8
- exports.Then_I_do_not_see_visible_text = Then_I_do_not_see_visible_text;
9
- exports.Then_I_see_value = Then_I_see_value;
10
- exports.Then_I_do_not_see_value = Then_I_do_not_see_value;
11
- exports.Then_I_do_not_see_text = Then_I_do_not_see_text;
12
- exports.Then_I_see_text_in_the_element = Then_I_see_text_in_the_element;
13
- exports.Then_I_see_alias_in_the_element = Then_I_see_alias_in_the_element;
14
- exports.Then_I_see_button_is_disabled = Then_I_see_button_is_disabled;
15
- const cucumber_1 = require("@cucumber/cucumber");
16
- const test_1 = require("@playwright/test");
17
- const fakerUtils_1 = require("../helpers/utils/fakerUtils"); // Assuming this path is correct
18
- // ===================================================================================
19
- // ASSERTIONS: ELEMENT COUNT
20
- // ===================================================================================
21
- /**
22
- * Asserts that the previously stored collection of elements has an exact expected count.
23
- *
24
- * ```gherkin
25
- * Then I count {int} elements
26
- * ```
27
- *
28
- * @param expectedCount - The expected number of elements in the collection.
29
- *
30
- * @example
31
- * Given I find elements by selector ".list-item"
32
- * Then I count 5 elements
33
- *
34
- * @remarks
35
- * This step requires a preceding step that populates {@link CustomWorld.elements | this.elements}
36
- * (e.g., "When I find elements by selector"). It then asserts that the number of
37
- * elements in that collection matches `expectedCount`. It also waits for `networkidle`
38
- * to ensure all elements that might affect the count have loaded.
39
- * @category Assertion Steps
40
- */
41
- async function Then_I_count_elements(expectedCount) {
42
- if (!this.elements)
43
- throw new Error("No element collection found to count. Use a 'find elements' step first.");
44
- const count = await this.elements.count();
45
- await this.page.waitForLoadState("networkidle"); // Wait for network to settle before asserting count
46
- (0, test_1.expect)(count).toBe(expectedCount);
47
- this.log?.(`✅ Verified element count: Expected ${expectedCount}, Found ${count}.`);
48
- }
49
- (0, cucumber_1.Then)("I count {int} elements", Then_I_count_elements);
50
- // ===================================================================================
51
- // ASSERTIONS: BUTTON VISIBILITY
52
- // ===================================================================================
53
- /**
54
- * Asserts that a button with the given text (or text from an alias) is visible on the page.
55
- * The text matching is case-insensitive and can be partial.
56
- *
57
- * ```gherkin
58
- * Then I see button {string}
59
- * ```
60
- *
61
- * @param rawText - The text of the button, or an alias prefixed with "@" (e.g., "Submit", "@submitButtonLabel").
62
- *
63
- * @example
64
- * Then I see button "Sign In"
65
- * Then I see button "@myLoginButton"
66
- *
67
- * @remarks
68
- * This step uses `page.getByRole("button", { name: ..., exact: false })`.
69
- * It waits for the page to be network idle and then asserts that the button is visible.
70
- * @category Assertion Steps
71
- */
72
- async function Then_I_see_button(rawText) {
73
- let buttonText = rawText.startsWith("@") ? this.data[rawText.slice(1)] : rawText;
74
- if (!buttonText) {
75
- throw new Error(`No value found for alias: "${rawText}". Cannot assert button visibility.`);
76
- }
77
- const button = this.page.getByRole("button", {
78
- name: buttonText,
79
- exact: false, // Allows partial match, e.g., "Submit" finds "Submit Form"
80
- });
81
- await this.page.waitForLoadState("networkidle"); // Wait for network to settle
82
- await (0, test_1.expect)(button).toBeVisible({ timeout: 5000 }); // Assert visibility with a timeout
83
- this.log?.(`✅ Verified button "${buttonText}" is visible.`);
84
- }
85
- (0, cucumber_1.Then)(/^I see button "(.*)"$/, Then_I_see_button);
86
- /**
87
- * Asserts that a button with the given text (or text from an alias) is NOT visible on the page.
88
- * The text matching is case-insensitive and can be partial.
89
- *
90
- * ```gherkin
91
- * Then I do not see button {string}
92
- * ```
93
- *
94
- * @param rawText - The text of the button, or an alias prefixed with "@".
95
- *
96
- * @example
97
- * Then I do not see button "Delete Account"
98
- * Then I do not see button "@hiddenAdminButton"
99
- *
100
- * @remarks
101
- * This step checks for the absence of a visible button. It first waits for the page
102
- * to be network idle, then finds potential buttons by role and name. If any matching
103
- * button is found and is visible, the step will fail.
104
- * @category Assertion Steps
105
- */
106
- async function Then_I_do_not_see_button(rawText) {
107
- let buttonText = rawText.startsWith("@") ? this.data[rawText.slice(1)] : rawText;
108
- if (!buttonText) {
109
- throw new Error(`No value found for alias: "${rawText}". Cannot assert button non-visibility.`);
110
- }
111
- const button = this.page.getByRole("button", {
112
- name: buttonText,
113
- exact: false,
114
- });
115
- await this.page.waitForLoadState("networkidle"); // Wait for network to settle
116
- // Check if *any* matching button is visible. If so, throw an error.
117
- await (0, test_1.expect)(button).not.toBeVisible({ timeout: 5000 }); // Playwright's native assertion is more robust here
118
- this.log?.(`✅ Verified button "${buttonText}" is not visible.`);
119
- }
120
- (0, cucumber_1.Then)(/^I do not see button "(.*)"$/, Then_I_do_not_see_button);
121
- // ===================================================================================
122
- // ASSERTIONS: TEXT VISIBILITY
123
- // ===================================================================================
124
- /**
125
- * Asserts that specific text is visible on the current page or within the current frame/scope.
126
- *
127
- * ```gherkin
128
- * Then I see text {string}
129
- * ```
130
- *
131
- * @param expectedText - The text string expected to be visible.
132
- *
133
- * @example
134
- * Then I see text "Welcome to your Dashboard"
135
- *
136
- * @remarks
137
- * This step uses `locator.waitFor({ state: "visible" })` to ensure the text is present
138
- * and displayed within the current Playwright scope (main page or active iframe).
139
- * Text matching is a substring match by default.
140
- * @category Assertion Steps
141
- */
142
- async function Then_I_see_text(expectedText) {
143
- const scope = this.getScope(); // Supports iframe OR main page
144
- const locator = scope.locator(`text=${expectedText}`); // Playwright's text locator is robust
145
- // Use Playwright's expect for robust waiting and assertion
146
- await (0, test_1.expect)(locator).toBeVisible({ timeout: 5000 });
147
- this.log?.(`✅ Verified text visible: "${expectedText}".`);
148
- }
149
- (0, cucumber_1.Then)("I see text {string}", Then_I_see_text);
150
- /**
151
- * Asserts that the exact visible text is present on the page.
152
- * This is similar to "I see text", but emphasizes "visible" for clarity.
153
- *
154
- * ```gherkin
155
- * Then I see visible text {string}
156
- * ```
157
- *
158
- * @param text - The exact text string expected to be visible.
159
- *
160
- * @example
161
- * Then I see visible text "Dashboard"
162
- *
163
- * @remarks
164
- * This step uses `:text-is()` pseudo-class for exact text matching and `isVisible()`
165
- * to confirm presence. It also waits for `networkidle` beforehand.
166
- * Consider consolidating with `Then I see text {string}` if you prefer `toBeVisible`
167
- * which handles exact matching via options or `text-is` more flexibly.
168
- * @category Assertion Steps
169
- */
170
- async function Then_I_see_visible_text(text) {
171
- await this.page.waitForLoadState("networkidle"); // Wait for network to settle
172
- const locator = this.page.locator(`:text-is("${text}")`);
173
- // Use Playwright's expect for robust waiting and assertion
174
- await (0, test_1.expect)(locator).toBeVisible({ timeout: 5000 });
175
- this.log?.(`✅ Verified exact visible text: "${text}".`);
176
- }
177
- (0, cucumber_1.Then)("I see visible text {string}", Then_I_see_visible_text);
178
- /**
179
- * Asserts that specific exact visible text is NOT present on the page.
180
- *
181
- * ```gherkin
182
- * Then I do not see visible text {string}
183
- * ```
184
- *
185
- * @param text - The exact text string expected NOT to be visible.
186
- *
187
- * @example
188
- * Then I do not see visible text "Logout"
189
- *
190
- * @remarks
191
- * This step uses `:text-is()` for exact text matching. It asserts that no element
192
- * with this exact text is visible.
193
- * @category Assertion Steps
194
- */
195
- async function Then_I_do_not_see_visible_text(text) {
196
- const locator = this.page.locator(`:text-is("${text}")`);
197
- // Use Playwright's expect for robust assertion
198
- await (0, test_1.expect)(locator).not.toBeVisible({ timeout: 5000 });
199
- this.log?.(`✅ Verified exact visible text NOT present: "${text}".`);
200
- }
201
- (0, cucumber_1.Then)("I do not see visible text {string}", Then_I_do_not_see_visible_text);
202
- // ===================================================================================
203
- // ASSERTIONS: ELEMENT VALUE
204
- // ===================================================================================
205
- /**
206
- * Asserts that the previously selected element has a specific input value.
207
- *
208
- * ```gherkin
209
- * Then I see value {string}
210
- * ```
211
- *
212
- * @param expectedValue - The expected exact value of the input or textarea.
213
- *
214
- * @example
215
- * When I find element by selector "input[name='email']"
216
- * Then I see value "test@example.com"
217
- *
218
- * @remarks
219
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}
220
- * to an input, textarea, or other element that has an input value.
221
- * It uses Playwright's `locator.inputValue()`.
222
- * @category Assertion Steps
223
- */
224
- async function Then_I_see_value(expectedValue) {
225
- if (!this.element)
226
- throw new Error("No element selected to check its value.");
227
- // Use Playwright's expect.toHaveValue for robust assertion
228
- await (0, test_1.expect)(this.element).toHaveValue(expectedValue, { timeout: 5000 });
229
- this.log?.(`✅ Verified element has value: "${expectedValue}".`);
230
- }
231
- (0, cucumber_1.Then)("I see value {string}", Then_I_see_value);
232
- /**
233
- * Asserts that the previously selected element does NOT have a specific input value.
234
- *
235
- * ```gherkin
236
- * Then I do not see value {string}
237
- * ```
238
- *
239
- * @param unwantedValue - The value that is expected NOT to be present in the input or textarea.
240
- *
241
- * @example
242
- * When I find element by selector "input[name='password']"
243
- * Then I do not see value "admin123"
244
- *
245
- * @remarks
246
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
247
- * It asserts that the element's current input value does not match `unwantedValue`.
248
- * @category Assertion Steps
249
- */
250
- async function Then_I_do_not_see_value(unwantedValue) {
251
- if (!this.element)
252
- throw new Error("No element selected to check its value.");
253
- // Use Playwright's expect.not.toHaveValue for robust assertion
254
- await (0, test_1.expect)(this.element).not.toHaveValue(unwantedValue, { timeout: 5000 });
255
- this.log?.(`✅ Verified element does NOT have value: "${unwantedValue}".`);
256
- }
257
- (0, cucumber_1.Then)("I do not see value {string}", Then_I_do_not_see_value);
258
- // ===================================================================================
259
- // ASSERTIONS: TEXT PRESENCE (Absence)
260
- // ===================================================================================
261
- /**
262
- * Asserts that specific text is NOT present on the page. This checks for complete absence,
263
- * not just visibility.
264
- *
265
- * ```gherkin
266
- * Then I do not see text {string}
267
- * ```
268
- *
269
- * @param unexpectedText - The text string that is expected NOT to be found on the page.
270
- *
271
- * @example
272
- * Then I do not see text "Error Message"
273
- *
274
- * @remarks
275
- * This step uses `page.getByText` with `exact: true` and then asserts that the count
276
- * of matching elements is 0. This confirms the text is entirely absent from the DOM.
277
- * @category Assertion Steps
278
- */
279
- async function Then_I_do_not_see_text(unexpectedText) {
280
- const el = this.page.getByText(unexpectedText, { exact: true });
281
- await (0, test_1.expect)(el).toHaveCount(0); // This directly asserts that no such element exists
282
- this.log?.(`✅ Verified text NOT present in DOM: "${unexpectedText}".`);
283
- }
284
- (0, cucumber_1.Then)(/^I do not see text "(.*)"$/, Then_I_do_not_see_text);
285
- // ===================================================================================
286
- // ASSERTIONS: TEXT IN ELEMENT (with Alias/Faker)
287
- // ===================================================================================
288
- /**
289
- * Asserts that the previously selected element contains the given text,
290
- * which can be a literal string, an alias, or a Faker.js expression.
291
- *
292
- * ```gherkin
293
- * Then I see {string} in the element
294
- * ```
295
- *
296
- * @param expected - The text string, alias (prefixed with "@"), or Faker.js expression expected to be contained within the element's text content.
297
- *
298
- * @example
299
- * When I find element by selector "#welcome-message"
300
- * Then I see "Welcome, John Doe!" in the element
301
- * Given I store "user.name" as "loggedInUserName"
302
- * When I find element by selector "#user-profile-name"
303
- * Then I see "@loggedInUserName" in the element
304
- * Then I see "Hello, {{person.firstName}}!" in the element
305
- *
306
- * @remarks
307
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
308
- * It resolves aliases and Faker expressions before comparing the `textContent` of the element.
309
- * It uses `expect(textContent).toContain(expected)` for partial matching.
310
- * @category Assertion Steps
311
- */
312
- async function Then_I_see_text_in_the_element(expected) {
313
- const element = this.element;
314
- if (!element)
315
- throw new Error("No element selected to check its text content.");
316
- // ✅ Resolve alias
317
- if (expected.startsWith("@")) {
318
- const alias = expected.substring(1);
319
- expected = this.data[alias];
320
- if (!expected)
321
- throw new Error(`No data stored for alias "@${alias}".`);
322
- }
323
- // ✅ Resolve faker syntax
324
- expected = (0, fakerUtils_1.evaluateFaker)(expected);
325
- // Use Playwright's expect.toContainText for robust assertion on visible text
326
- await (0, test_1.expect)(element).toContainText(expected, { timeout: 5000 });
327
- this.log?.(`✅ Verified "${expected}" is contained in element text.`);
328
- }
329
- (0, cucumber_1.Then)("I see {string} in the element", Then_I_see_text_in_the_element);
330
- /**
331
- * Asserts that the previously selected element contains the value retrieved from a specific alias.
332
- *
333
- * ```gherkin
334
- * Then I see @{word} in the element
335
- * ```
336
- *
337
- * @param alias - The alias name from which to retrieve the expected text value.
338
- *
339
- * @example
340
- * Given I store "Generated Name" as "tempName"
341
- * When I find element by selector "#display-name"
342
- * Then I see @tempName in the element
343
- *
344
- * @remarks
345
- * This step requires a preceding step that sets the {@link CustomWorld.element | current element}.
346
- * It fetches the value from `this.data[alias]` and then asserts that the element's
347
- * `textContent` (trimmed) contains this stored value. This is a specialized version of
348
- * `Then I see {string} in the element` specifically for aliases.
349
- * @category Assertion Steps
350
- */
351
- async function Then_I_see_alias_in_the_element(alias) {
352
- const storedValue = this.data[alias];
353
- if (storedValue === undefined || storedValue === null) {
354
- throw new Error(`No value found in data storage under alias "@${alias}". Alias might be undefined or null.`);
355
- }
356
- if (!this.element) {
357
- throw new Error("No element selected to check its text content. You must get an element before asserting its contents.");
358
- }
359
- // Use Playwright's expect.toContainText for robust assertion
360
- // Convert storedValue to string for reliable comparison
361
- await (0, test_1.expect)(this.element).toContainText(String(storedValue), { timeout: 5000 });
362
- this.log?.(`✅ Verified element contains value from "@${alias}" ("${storedValue}").`);
363
- }
364
- (0, cucumber_1.Then)("I see @{word} in the element", Then_I_see_alias_in_the_element);
365
- // ===================================================================================
366
- // ASSERTIONS: BUTTON STATE
367
- // ===================================================================================
368
- /**
369
- * Asserts that a button with the given text (or text from an alias) is disabled.
370
- *
371
- * ```gherkin
372
- * Then I see button {string} is disabled
373
- * ```
374
- *
375
- * @param rawText - The text of the button, or an alias prefixed with "@".
376
- *
377
- * @example
378
- * Then I see button "Submit" is disabled
379
- * Then I see button "@checkoutButton" is disabled
380
- *
381
- * @remarks
382
- * This step first locates the button by its role and name, asserts it's visible,
383
- * and then checks its disabled state using Playwright's `isDisabled()` method.
384
- * @category Assertion Steps
385
- */
386
- async function Then_I_see_button_is_disabled(rawText) {
387
- // Resolve alias
388
- let buttonText = rawText.startsWith("@") ? this.data[rawText.slice(1)] : rawText;
389
- if (!buttonText) {
390
- throw new Error(`No value found for alias: "${rawText}". Cannot check button disabled state.`);
391
- }
392
- const button = this.page.getByRole("button", {
393
- name: buttonText,
394
- exact: false,
395
- });
396
- // Assert visibility first, then disabled state
397
- await (0, test_1.expect)(button).toBeVisible({ timeout: 5000 });
398
- await (0, test_1.expect)(button).toBeDisabled({ timeout: 5000 }); // Playwright's direct assertion is best
399
- this.log?.(`✅ Verified button "${buttonText}" is disabled.`);
400
- }
401
- (0, cucumber_1.Then)("I see button {string} is disabled", Then_I_see_button_is_disabled);