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,291 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.When_I_intercept_URL_and_stub_body = When_I_intercept_URL_and_stub_body;
4
- exports.When_I_intercept_URL = When_I_intercept_URL;
5
- exports.When_I_intercept_URL_and_stub_raw_body = When_I_intercept_URL_and_stub_raw_body;
6
- exports.When_I_make_GET_request_to = When_I_make_GET_request_to;
7
- exports.When_I_make_POST_request_with_JSON_body = When_I_make_POST_request_with_JSON_body;
8
- exports.When_I_make_HTTP_request_with_options = When_I_make_HTTP_request_with_options;
9
- // e2e/step_definitions/common/interceptionSteps.ts
10
- const cucumber_1 = require("@cucumber/cucumber");
11
- // =============================
12
- // WHEN I INTERCEPT / STUB
13
- // =============================
14
- /**
15
- * Intercepts a network request to the given URL and stubs its response body with the provided JSON.
16
- * This step should be used *before* the action that triggers the request (e.g., navigating to a page
17
- * or clicking a button that makes an API call).
18
- *
19
- * ```gherkin
20
- * When I intercept URL {string} and stub body:
21
- * """
22
- * { "foo": "bar" }
23
- * """
24
- * ```
25
- *
26
- * @param url - The URL to intercept. This can be a full URL, a URL glob, or a regular expression string.
27
- * @param body - A DocString containing the JSON string to use as the response body.
28
- *
29
- * @example
30
- * Scenario: Stubbing an API response
31
- * When I intercept URL "https://api.example.com/data" and stub body:
32
- * """
33
- * { "status": "success", "items": ["item1", "item2"] }
34
- * """
35
- * And I go to "/dashboard"
36
- * Then I should see text "item1"
37
- *
38
- * @remarks
39
- * The intercepted request will respond with a `200 OK` status and a `Content-Type` of `application/json`.
40
- * The `body` provided must be valid JSON. Playwright's `page.route()` is used internally.
41
- * Make sure this step executes *before* the network request is initiated.
42
- * @category Network Interception Steps
43
- */
44
- async function When_I_intercept_URL_and_stub_body(url, body) {
45
- let parsedBody;
46
- try {
47
- parsedBody = JSON.parse(body);
48
- }
49
- catch (e) {
50
- const message = e instanceof Error ? e.message : String(e);
51
- throw new Error(`Failed to parse JSON body for URL "${url}": ${message}. Please provide valid JSON.`);
52
- }
53
- await this.page.route(url, (route) => {
54
- route.fulfill({
55
- status: 200,
56
- contentType: "application/json",
57
- body: JSON.stringify(parsedBody),
58
- });
59
- });
60
- this.log?.(`📡 Intercepted and stubbed URL "${url}" with JSON body: ${JSON.stringify(parsedBody).slice(0, 100)}...`);
61
- }
62
- (0, cucumber_1.When)("I intercept URL {string} and stub body:", When_I_intercept_URL_and_stub_body);
63
- /**
64
- * Intercepts a network request to the given URL and allows it to continue unmodified.
65
- * This can be useful for ensuring that specific requests are *not* blocked or for logging
66
- * requests without altering their behavior.
67
- *
68
- * ```gherkin
69
- * When I intercept URL {string}
70
- * ```
71
- *
72
- * @param url - The URL to intercept. This can be a full URL, a URL glob, or a regular expression string.
73
- *
74
- * @example
75
- * Scenario: Allowing a specific request to pass through
76
- * When I intercept URL "https://analytics.example.com/*"
77
- * And I go to "/dashboard"
78
- * Then the page title should be "Dashboard"
79
- *
80
- * @remarks
81
- * This step uses Playwright's `page.route()` with `route.continue()`. No changes are made
82
- * to the request or its response. This is essentially a "monitor" step.
83
- * @category Network Interception Steps
84
- */
85
- async function When_I_intercept_URL(url) {
86
- await this.page.route(url, async (route) => {
87
- await route.continue();
88
- });
89
- this.log?.(`📡 Intercepted URL "${url}" and allowed it to continue.`);
90
- }
91
- (0, cucumber_1.When)("I intercept URL {string}", When_I_intercept_URL);
92
- /**
93
- * Intercepts a network request to the given URL and stubs its response body with a raw string.
94
- * This is useful for returning non-JSON content or simple string responses.
95
- *
96
- * ```gherkin
97
- * When I intercept URL {string} and stub body {string}
98
- * ```
99
- *
100
- * @param url - The URL to intercept. This can be a full URL, a URL glob, or a regular expression string.
101
- * @param body - The raw string content to use as the response body.
102
- *
103
- * @example
104
- * Scenario: Stubbing a simple text response
105
- * When I intercept URL "https://api.example.com/status" and stub body "OK"
106
- * And I visit page with JS that fetches "/status"
107
- * Then I should see text "OK"
108
- *
109
- * @remarks
110
- * The intercepted request will respond with a `200 OK` status and a `Content-Type` of `application/json`
111
- * by default (though the `body` is a raw string). If a different `contentType` is needed, consider
112
- * using the `I intercept URL {string} and stub response with:` step if available, or extending this step.
113
- * @category Network Interception Steps
114
- */
115
- async function When_I_intercept_URL_and_stub_raw_body(url, body) {
116
- await this.page.route(url, (route) => {
117
- route.fulfill({
118
- status: 200,
119
- contentType: "application/json", // Defaulting to JSON, can be customized if needed
120
- body,
121
- });
122
- });
123
- this.log?.(`📡 Intercepted and stubbed URL "${url}" with raw body: "${body.slice(0, 100)}..."`);
124
- }
125
- (0, cucumber_1.When)("I intercept URL {string} and stub body {string}", When_I_intercept_URL_and_stub_raw_body);
126
- // =============================
127
- // WHEN I MAKE REQUEST
128
- // =============================
129
- /**
130
- * Makes a GET request to the given URL and stores the response details (status and body)
131
- * in the test context.
132
- *
133
- * ```gherkin
134
- * When I make request to {string}
135
- * ```
136
- *
137
- * @param url - The URL to which the GET request will be made.
138
- *
139
- * @example
140
- * Scenario: Verify API endpoint status
141
- * When I make request to "https://api.example.com/health"
142
- * Then the last response status should be 200
143
- * And the last response body should contain "healthy"
144
- *
145
- * @remarks
146
- * The response object (including status and body) is stored in
147
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}. Subsequent assertion steps
148
- * can then access this data.
149
- * @category API Request Steps
150
- */
151
- async function When_I_make_GET_request_to(url) {
152
- this.log?.(`⚡ Making GET request to "${url}"...`);
153
- const response = await this.page.request.get(url);
154
- const status = response.status();
155
- const body = await response.text();
156
- this.data.lastResponse = { status, body }; // Storing as an object for clarity
157
- this.log?.(`✅ GET request to "${url}" completed. Status: ${status}. Body preview: ${body.slice(0, 100)}...`);
158
- }
159
- // Note: You had two steps "I make request to" and "I make a request to".
160
- // I'm keeping one for clarity and suggesting the other is an alias if needed.
161
- (0, cucumber_1.When)("I make request to {string}", When_I_make_GET_request_to);
162
- (0, cucumber_1.When)("I make a request to {string}", When_I_make_GET_request_to); // Alias for consistency
163
- /**
164
- * Makes a POST request to the given URL with the provided JSON body and stores the response details.
165
- *
166
- * ```gherkin
167
- * When I make a POST request to {string} with JSON body:
168
- * """
169
- * { "username": "user", "password": "pass" }
170
- * """
171
- * ```
172
- *
173
- * @param url - The URL to which the POST request will be made.
174
- * @param docString - A Cucumber DocString containing the JSON payload for the request body.
175
- *
176
- * @example
177
- * Scenario: Login via API
178
- * When I make a POST request to "https://api.example.com/login" with JSON body:
179
- * """
180
- * { "email": "test@example.com", "password": "password123" }
181
- * """
182
- * Then the last response status should be 200
183
- * And the last response body should contain "token"
184
- *
185
- * @remarks
186
- * The `docString` must contain valid JSON. The request will have a `Content-Type` of `application/json`.
187
- * The response object (including status and body) is stored in
188
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
189
- * @category API Request Steps
190
- */
191
- async function When_I_make_POST_request_with_JSON_body(url, docString) {
192
- let payload;
193
- try {
194
- payload = JSON.parse(docString);
195
- }
196
- catch (e) {
197
- const message = e instanceof Error ? e.message : String(e);
198
- throw new Error(`Invalid JSON payload for POST request to "${url}": ${message}.`);
199
- }
200
- this.log?.(`⚡ Making POST request to "${url}" with payload: ${docString.slice(0, 100)}...`);
201
- const response = await this.page.request.post(url, { data: payload });
202
- const status = response.status();
203
- const body = await response.text();
204
- this.data.lastResponse = { status, body };
205
- this.log?.(`✅ POST request to "${url}" completed. Status: ${status}. Body preview: ${body.slice(0, 100)}...`);
206
- }
207
- (0, cucumber_1.When)("I make a POST request to {string} with JSON body:", When_I_make_POST_request_with_JSON_body);
208
- /**
209
- * Makes a generic HTTP request with a specified method and optional headers/body from a data table.
210
- *
211
- * ```gherkin
212
- * When I make a "{word}" request to {string}
213
- * | header | value |
214
- * | Content-Type | application/json |
215
- * | ... | ... |
216
- * ```
217
- *
218
- * @param method - The HTTP method (e.g., "GET", "POST", "PUT", "DELETE").
219
- * @param url - The URL for the request.
220
- * @param table - (Optional) A Cucumber DataTable with `header` and `value` columns for headers,
221
- * and a `body` row for the request body.
222
- *
223
- * @example
224
- * Scenario: Make a PUT request with custom headers
225
- * When I make a "PUT" request to "https://api.example.com/resource/123"
226
- * | Content-Type | application/json |
227
- * | Authorization | Bearer my-token |
228
- * | body | { "status": "updated" } |
229
- * Then the last response status should be 200
230
- *
231
- * @remarks
232
- * This step constructs a `fetch` request using the provided method, URL, and options from the
233
- * data table. The `body` provided in the data table (if any) will be automatically
234
- * JSON.parsed and then JSON.stringified. The entire `Response` object from `fetch` is
235
- * stored in {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
236
- *
237
- * **Note on `fetch`:** This step uses the browser's `fetch` API, which runs in the browser context.
238
- * If you need to make Node.js-based requests (e.g., for backend APIs that are not accessible from the browser),
239
- * you might prefer `page.request` (as used in `When_I_make_GET_request_to` or `When_I_make_POST_request_with_JSON_body`).
240
- * This step stores the raw `Response` object, so you might need to call `.json()` or `.text()`
241
- * on `this.data.lastResponse` in subsequent steps if you need to assert on its content.
242
- * @category API Request Steps
243
- */
244
- async function When_I_make_HTTP_request_with_options(method, url, table) {
245
- const options = {};
246
- if (table) {
247
- const rows = table.rows();
248
- rows.forEach((row) => {
249
- const [key, val] = row;
250
- if (key.toLowerCase() === "body") {
251
- try {
252
- options.body = JSON.stringify(JSON.parse(val)); // Parse then stringify for valid JSON body
253
- }
254
- catch (e) {
255
- throw new Error(`${e}Invalid JSON body provided in data table for request: ${val}`);
256
- }
257
- }
258
- else {
259
- // Treat as headers for now. Can be expanded for other options (e.g., credentials, mode)
260
- if (!options.headers) {
261
- options.headers = {};
262
- }
263
- options.headers[key] = val;
264
- }
265
- });
266
- }
267
- options.method = method.toUpperCase(); // Ensure method is uppercase
268
- this.log?.(`⚡ Making ${method.toUpperCase()} request to "${url}" with options: ${JSON.stringify(options).slice(0, 100)}...`);
269
- const res = await this.page.evaluate(async ([urlArg, optsArg]) => {
270
- const response = await fetch(urlArg, optsArg);
271
- // Return a serializable subset of the response
272
- return {
273
- status: response.status,
274
- statusText: response.statusText,
275
- // Correct way to get headers as a plain object for serialization
276
- headers: (() => {
277
- const result = {};
278
- response.headers.forEach((value, key) => {
279
- result[key] = value;
280
- });
281
- return result;
282
- })(),
283
- body: await response.text(),
284
- };
285
- }, [url, options] // Cast to ensure type compatibility
286
- );
287
- // Store the serializable response object
288
- this.data.lastResponse = res;
289
- this.log?.(`✅ ${method.toUpperCase()} request to "${url}" completed. Status: ${res.status}. Body preview: ${res.body.slice(0, 100)}...`);
290
- }
291
- (0, cucumber_1.When)('I make a "{word}" request to {string}', When_I_make_HTTP_request_with_options);