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,593 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Then_I_should_see_response_status = Then_I_should_see_response_status;
37
- exports.Then_I_see_response_status_is_not = Then_I_see_response_status_is_not;
38
- exports.Then_I_should_see_response_body_contains = Then_I_should_see_response_body_contains;
39
- exports.Then_I_see_response_body = Then_I_see_response_body;
40
- exports.Then_I_see_response_body_does_not_contain = Then_I_see_response_body_does_not_contain;
41
- exports.Then_I_see_response_body_is_empty = Then_I_see_response_body_is_empty;
42
- exports.Then_I_see_response_body_is_not_empty = Then_I_see_response_body_is_not_empty;
43
- exports.Then_I_see_response_body_is_JSON = Then_I_see_response_body_is_JSON;
44
- exports.Then_I_see_response_body_is_not_JSON = Then_I_see_response_body_is_not_JSON;
45
- exports.Then_I_see_response_body_matches_JSON_schema_path = Then_I_see_response_body_matches_JSON_schema_path;
46
- exports.Then_I_see_response_body_matches_JSON_schema_object = Then_I_see_response_body_matches_JSON_schema_object;
47
- exports.Then_I_see_response_header_equals = Then_I_see_response_header_equals;
48
- exports.Then_I_see_response_header_contains = Then_I_see_response_header_contains;
49
- exports.Then_I_see_response_header_does_not_contain = Then_I_see_response_header_does_not_contain;
50
- exports.Then_I_see_response_header_does_not_equal = Then_I_see_response_header_does_not_equal;
51
- exports.Then_I_see_response_header_exists = Then_I_see_response_header_exists;
52
- exports.Then_I_see_response_header_does_not_exist = Then_I_see_response_header_does_not_exist;
53
- const cucumber_1 = require("@cucumber/cucumber");
54
- const test_1 = require("@playwright/test");
55
- // Helper to ensure lastResponse is available and correctly typed
56
- function getValidatedLastResponse(world) {
57
- const response = world.data.lastResponse;
58
- if (!response) {
59
- throw new Error("No API response available in 'this.data.lastResponse'. Make sure a request step was executed.");
60
- }
61
- // Ensure the structure matches our expected LastResponse interface
62
- if (typeof response.status !== "number" ||
63
- typeof response.body !== "string" ||
64
- typeof response.headers !== "object") {
65
- throw new Error("Invalid 'lastResponse' structure. Expected properties: status (number), body (string), headers (object).");
66
- }
67
- return response;
68
- }
69
- // ===================================================================================
70
- // ASSERTIONS: API RESPONSE STATUS
71
- // ===================================================================================
72
- /**
73
- * Asserts that the status code of the last API response matches the expected number.
74
- *
75
- * ```gherkin
76
- * Then I should see response status {int}
77
- * ```
78
- *
79
- * @param expectedStatus - The expected HTTP status code (e.g., 200, 404).
80
- *
81
- * @example
82
- * When I make request to "https://api.example.com/data"
83
- * Then I should see response status 200
84
- *
85
- * @remarks
86
- * This step requires a preceding step that stores the API response in
87
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
88
- * It uses `expect().toBe()` for robust assertion.
89
- * @category API Response Assertion Steps
90
- */
91
- function Then_I_should_see_response_status(expectedStatus) {
92
- const res = getValidatedLastResponse(this);
93
- (0, test_1.expect)(res.status).toBe(expectedStatus);
94
- this.log?.(`✅ Verified response status is ${expectedStatus}.`);
95
- }
96
- (0, cucumber_1.Then)("I should see response status {int}", Then_I_should_see_response_status);
97
- /**
98
- * Asserts that the status code of the last API response does NOT match the given number.
99
- *
100
- * ```gherkin
101
- * Then I see response status is not {int}
102
- * ```
103
- *
104
- * @param unexpectedStatus - The HTTP status code that is NOT expected.
105
- *
106
- * @example
107
- * When I make request to "https://api.example.com/data"
108
- * Then I see response status is not 404
109
- *
110
- * @remarks
111
- * This step requires a preceding step that stores the API response in
112
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
113
- * It uses `expect().not.toBe()` for robust assertion.
114
- * @category API Response Assertion Steps
115
- */
116
- function Then_I_see_response_status_is_not(unexpectedStatus) {
117
- const res = getValidatedLastResponse(this);
118
- (0, test_1.expect)(res.status).not.toBe(unexpectedStatus);
119
- this.log?.(`✅ Verified response status is NOT ${unexpectedStatus}.`);
120
- }
121
- (0, cucumber_1.Then)("I see response status is not {int}", Then_I_see_response_status_is_not);
122
- // ===================================================================================
123
- // ASSERTIONS: API RESPONSE BODY
124
- // ===================================================================================
125
- /**
126
- * Asserts that the body of the last API response contains the expected text substring.
127
- *
128
- * ```gherkin
129
- * Then I should see response body contains {string}
130
- * ```
131
- *
132
- * @param expectedText - The substring expected to be present in the response body.
133
- *
134
- * @example
135
- * When I make request to "https://api.example.com/users"
136
- * Then I should see response body contains "John Doe"
137
- *
138
- * @remarks
139
- * This step requires a preceding step that stores the API response in
140
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
141
- * It uses `expect().toContain()` for robust assertion.
142
- * @category API Response Assertion Steps
143
- */
144
- function Then_I_should_see_response_body_contains(expectedText) {
145
- const res = getValidatedLastResponse(this);
146
- (0, test_1.expect)(res.body).toContain(expectedText);
147
- this.log?.(`✅ Verified response body contains "${expectedText}".`);
148
- }
149
- // Note: You had two steps "I should see response body contains" and "I see response body contains".
150
- // I've consolidated them to this single export function and will link both When patterns to it.
151
- (0, cucumber_1.Then)("I should see response body contains {string}", Then_I_should_see_response_body_contains);
152
- (0, cucumber_1.Then)("I see response body contains {string}", Then_I_should_see_response_body_contains);
153
- /**
154
- * Asserts that the body of the last API response strictly matches the expected string.
155
- *
156
- * ```gherkin
157
- * Then I see response body {string}
158
- * ```
159
- *
160
- * @param expectedBody - The exact string expected to be the response body.
161
- *
162
- * @example
163
- * When I make request to "https://api.example.com/status"
164
- * Then I see response body "OK"
165
- *
166
- * @remarks
167
- * This step requires a preceding step that stores the API response in
168
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
169
- * It performs a strict equality check on the entire response body string.
170
- * @category API Response Assertion Steps
171
- */
172
- function Then_I_see_response_body(expectedBody) {
173
- const res = getValidatedLastResponse(this);
174
- (0, test_1.expect)(res.body).toBe(expectedBody);
175
- this.log?.(`✅ Verified response body is exactly "${expectedBody}".`);
176
- }
177
- // Note: You had "I see response body {string}" and "I see response body matches {string}".
178
- // I've consolidated them to this single export function and will link both Then patterns to it.
179
- (0, cucumber_1.Then)("I see response body {string}", Then_I_see_response_body);
180
- (0, cucumber_1.Then)("I see response body matches {string}", Then_I_see_response_body);
181
- /**
182
- * Asserts that the body of the last API response does NOT contain the given substring.
183
- *
184
- * ```gherkin
185
- * Then I see response body does not contain {string}
186
- * ```
187
- *
188
- * @param unexpectedPart - The substring expected NOT to be present in the response body.
189
- *
190
- * @example
191
- * When I make request to "https://api.example.com/error"
192
- * Then I see response body does not contain "internal server error"
193
- *
194
- * @remarks
195
- * This step requires a preceding step that stores the API response in
196
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
197
- * It checks for the absence of the substring within the response body.
198
- * @category API Response Assertion Steps
199
- */
200
- function Then_I_see_response_body_does_not_contain(unexpectedPart) {
201
- const res = getValidatedLastResponse(this);
202
- (0, test_1.expect)(res.body).not.toContain(unexpectedPart);
203
- this.log?.(`✅ Verified response body does NOT contain "${unexpectedPart}".`);
204
- }
205
- (0, cucumber_1.Then)("I see response body does not contain {string}", Then_I_see_response_body_does_not_contain);
206
- /**
207
- * Asserts that the body of the last API response is empty (contains only whitespace or is empty).
208
- *
209
- * ```gherkin
210
- * Then I see response body is empty
211
- * ```
212
- *
213
- * @example
214
- * When I make request to "https://api.example.com/no-content"
215
- * Then I see response body is empty
216
- *
217
- * @remarks
218
- * This step requires a preceding step that stores the API response in
219
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
220
- * It trims whitespace and checks if the resulting string is empty.
221
- * @category API Response Assertion Steps
222
- */
223
- function Then_I_see_response_body_is_empty() {
224
- const res = getValidatedLastResponse(this);
225
- (0, test_1.expect)(res.body.trim()).toBe("");
226
- this.log?.(`✅ Verified response body is empty.`);
227
- }
228
- (0, cucumber_1.Then)("I see response body is empty", Then_I_see_response_body_is_empty);
229
- /**
230
- * Asserts that the body of the last API response is NOT empty (contains non-whitespace characters).
231
- *
232
- * ```gherkin
233
- * Then I see response body is not empty
234
- * ```
235
- *
236
- * @example
237
- * When I make request to "https://api.example.com/data"
238
- * Then I see response body is not empty
239
- *
240
- * @remarks
241
- * This step requires a preceding step that stores the API response in
242
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
243
- * It trims whitespace and checks if the resulting string is not empty.
244
- * @category API Response Assertion Steps
245
- */
246
- function Then_I_see_response_body_is_not_empty() {
247
- const res = getValidatedLastResponse(this);
248
- (0, test_1.expect)(res.body.trim()).not.toBe("");
249
- this.log?.(`✅ Verified response body is not empty.`);
250
- }
251
- (0, cucumber_1.Then)("I see response body is not empty", Then_I_see_response_body_is_not_empty);
252
- /**
253
- * Asserts that the body of the last API response is valid JSON.
254
- *
255
- * ```gherkin
256
- * Then I see response body is JSON
257
- * ```
258
- *
259
- * @example
260
- * When I make request to "https://api.example.com/json-data"
261
- * Then I see response body is JSON
262
- *
263
- * @remarks
264
- * This step requires a preceding step that stores the API response in
265
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
266
- * It attempts to parse the response body as JSON. If parsing fails, the step fails.
267
- * @category API Response Assertion Steps
268
- */
269
- function Then_I_see_response_body_is_JSON() {
270
- const res = getValidatedLastResponse(this);
271
- try {
272
- JSON.parse(res.body);
273
- this.log?.(`✅ Verified response body is valid JSON.`);
274
- }
275
- catch (e) {
276
- const message = e instanceof Error ? e.message : String(e);
277
- throw new Error(`Response body is not valid JSON: ${message}`);
278
- }
279
- }
280
- (0, cucumber_1.Then)("I see response body is JSON", Then_I_see_response_body_is_JSON);
281
- /**
282
- * Asserts that the body of the last API response is NOT valid JSON.
283
- *
284
- * ```gherkin
285
- * Then I see response body is not JSON
286
- * ```
287
- *
288
- * @example
289
- * When I make request to "https://api.example.com/plain-text"
290
- * Then I see response body is not JSON
291
- *
292
- * @remarks
293
- * This step requires a preceding step that stores the API response in
294
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
295
- * It attempts to parse the response body as JSON and expects the parsing to fail.
296
- * @category API Response Assertion Steps
297
- */
298
- function Then_I_see_response_body_is_not_JSON() {
299
- const res = getValidatedLastResponse(this);
300
- let isJson = true;
301
- try {
302
- JSON.parse(res.body);
303
- }
304
- catch (e) {
305
- isJson = false;
306
- e instanceof Error ? e.message : String(e);
307
- }
308
- if (isJson) {
309
- throw new Error(`Expected response body to not be JSON, but it is.`);
310
- }
311
- this.log?.(`✅ Verified response body is NOT JSON.`);
312
- }
313
- (0, cucumber_1.Then)("I see response body is not JSON", Then_I_see_response_body_is_not_JSON);
314
- /**
315
- * Asserts that the body of the last API response matches the given JSON schema.
316
- *
317
- * ```gherkin
318
- * Then I see response body matches JSON schema {string}
319
- * ```
320
- *
321
- * @param schemaPath - The path to the JSON schema file (e.g., "schemas/responseSchema.js").
322
- *
323
- * @example
324
- * When I make request to "https://api.example.com/users/1"
325
- * Then I see response body matches JSON schema "schemas/userSchema.js"
326
- *
327
- * @remarks
328
- * This step requires a preceding step that stores the API response in
329
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
330
- * It dynamically imports the schema file and uses `ajv` to validate the JSON response body.
331
- * Ensure `ajv` is installed (`npm install ajv`) and your schema files are accessible.
332
- * @category API Response Assertion Steps
333
- */
334
- async function Then_I_see_response_body_matches_JSON_schema_path(schemaPath) {
335
- const res = getValidatedLastResponse(this);
336
- const body = res.body; // Body is already a string from getValidatedLastResponse
337
- // Dynamically import Ajv and the schema
338
- const AjvModule = await Promise.resolve().then(() => __importStar(require("ajv")));
339
- const Ajv = AjvModule.default || AjvModule; // Handle potential default export differences
340
- const ajv = new Ajv();
341
- // Dynamically import the schema, handling both CommonJS and ES Module exports
342
- let schema;
343
- try {
344
- const schemaModule = await Promise.resolve(`${schemaPath}`).then(s => __importStar(require(s)));
345
- schema = schemaModule.default || schemaModule;
346
- }
347
- catch (error) {
348
- throw new Error(`Failed to load JSON schema from "${schemaPath}": ${error.message}`);
349
- }
350
- const validate = ajv.compile(schema);
351
- let parsedBody;
352
- try {
353
- parsedBody = JSON.parse(body);
354
- }
355
- catch (e) {
356
- throw new Error(`Response body is not valid JSON and cannot be validated against schema: ${e.message}`);
357
- }
358
- const valid = validate(parsedBody);
359
- if (!valid) {
360
- throw new Error(`Response body does not match schema: ${ajv.errorsText(validate.errors)}`);
361
- }
362
- this.log?.(`✅ Verified response body matches JSON schema from "${schemaPath}".`);
363
- }
364
- (0, cucumber_1.Then)("I see response body matches JSON schema {string}", Then_I_see_response_body_matches_JSON_schema_path);
365
- /**
366
- * Asserts that the body of the last API response matches the given JSON schema object directly provided in the step.
367
- *
368
- * ```gherkin
369
- * Then I see response body matches JSON schema:
370
- * """
371
- * { "type": "object", "properties": { "id": { "type": "number" } } }
372
- * """
373
- * ```
374
- *
375
- * @param schema - The JSON schema object (provided as a Cucumber DocString).
376
- *
377
- * @example
378
- * When I make request to "https://api.example.com/users/latest"
379
- * Then I see response body matches JSON schema:
380
- * """
381
- * {
382
- * "type": "object",
383
- * "properties": {
384
- * "id": { "type": "number" },
385
- * "name": { "type": "string" }
386
- * },
387
- * "required": ["id", "name"]
388
- * }
389
- * """
390
- *
391
- * @remarks
392
- * This step requires a preceding step that stores the API response in
393
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
394
- * It expects the schema as a direct JSON string (DocString) in the Gherkin step.
395
- * Uses `ajv` to validate the JSON response body against this inline schema.
396
- * Ensure `ajv` is installed (`npm install ajv`).
397
- * @category API Response Assertion Steps
398
- */
399
- async function Then_I_see_response_body_matches_JSON_schema_object(schemaString) {
400
- const res = getValidatedLastResponse(this);
401
- const body = res.body;
402
- const AjvModule = await Promise.resolve().then(() => __importStar(require("ajv")));
403
- const Ajv = AjvModule.default || AjvModule;
404
- const ajv = new Ajv();
405
- let schema;
406
- try {
407
- schema = JSON.parse(schemaString);
408
- }
409
- catch (e) {
410
- throw new Error(`Failed to parse inline JSON schema: ${e.message}. Ensure it is valid JSON.`);
411
- }
412
- const validate = ajv.compile(schema);
413
- let parsedBody;
414
- try {
415
- parsedBody = JSON.parse(body);
416
- }
417
- catch (e) {
418
- throw new Error(`Response body is not valid JSON and cannot be validated against inline schema: ${e.message}`);
419
- }
420
- const valid = validate(parsedBody);
421
- if (!valid) {
422
- throw new Error(`Response body does not match inline schema: ${ajv.errorsText(validate.errors)}`);
423
- }
424
- this.log?.(`✅ Verified response body matches inline JSON schema.`);
425
- }
426
- (0, cucumber_1.Then)("I see response body matches JSON schema", Then_I_see_response_body_matches_JSON_schema_object);
427
- // ===================================================================================
428
- // ASSERTIONS: API RESPONSE HEADERS
429
- // ===================================================================================
430
- /**
431
- * Asserts that a specific header in the last API response strictly equals an expected value.
432
- *
433
- * ```gherkin
434
- * Then I see response header {string} equals {string}
435
- * ```
436
- *
437
- * @param headerName - The name of the header (case-insensitive, e.g., "Content-Type").
438
- * @param expectedValue - The exact expected value of the header.
439
- *
440
- * @example
441
- * When I make request to "https://api.example.com/data"
442
- * Then I see response header "content-type" equals "application/json"
443
- *
444
- * @remarks
445
- * This step requires a preceding step that stores the API response in
446
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
447
- * It retrieves the header value and performs a strict equality check.
448
- * @category API Response Assertion Steps
449
- */
450
- function Then_I_see_response_header_equals(headerName, expectedValue) {
451
- const res = getValidatedLastResponse(this);
452
- const headerValue = res.headers[headerName.toLowerCase()]; // Access from plain object
453
- (0, test_1.expect)(headerValue, `Expected header "${headerName}" to be "${expectedValue}", but got "${headerValue}".`).toBe(expectedValue);
454
- this.log?.(`✅ Verified response header "${headerName}" equals "${expectedValue}".`);
455
- }
456
- (0, cucumber_1.Then)("I see response header {string} equals {string}", Then_I_see_response_header_equals);
457
- /**
458
- * Asserts that a specific header in the last API response contains a given substring.
459
- *
460
- * ```gherkin
461
- * Then I see response header {string} contains {string}
462
- * ```
463
- *
464
- * @param headerName - The name of the header (case-insensitive, e.g., "Set-Cookie").
465
- * @param expectedPart - The substring expected to be contained within the header's value.
466
- *
467
- * @example
468
- * When I make request to "https://api.example.com/login"
469
- * Then I see response header "set-cookie" contains "session_id"
470
- *
471
- * @remarks
472
- * This step requires a preceding step that stores the API response in
473
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
474
- * It retrieves the header value and checks if it includes the `expectedPart`.
475
- * @category API Response Assertion Steps
476
- */
477
- function Then_I_see_response_header_contains(headerName, expectedPart) {
478
- const res = getValidatedLastResponse(this);
479
- const headerValue = res.headers[headerName.toLowerCase()]; // Access from plain object
480
- (0, test_1.expect)(headerValue, `Header "${headerName}" not found or is empty. Expected to contain "${expectedPart}".`).toBeDefined(); // Ensure header exists before checking content
481
- (0, test_1.expect)(headerValue, `Expected header "${headerName}" to contain "${expectedPart}", but got "${headerValue}".`).toContain(expectedPart);
482
- this.log?.(`✅ Verified response header "${headerName}" contains "${expectedPart}".`);
483
- }
484
- (0, cucumber_1.Then)("I see response header {string} contains {string}", Then_I_see_response_header_contains);
485
- /**
486
- * Asserts that a specific header in the last API response does NOT contain a given substring.
487
- *
488
- * ```gherkin
489
- * Then I see response header {string} does not contain {string}
490
- * ```
491
- *
492
- * @param headerName - The name of the header (case-insensitive).
493
- * @param unexpectedPart - The substring expected NOT to be present within the header's value.
494
- *
495
- * @example
496
- * When I make request to "https://api.example.com/no-cache"
497
- * Then I see response header "cache-control" does not contain "no-store"
498
- *
499
- * @remarks
500
- * This step requires a preceding step that stores the API response in
501
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
502
- * It retrieves the header value and asserts that it does not include the `unexpectedPart`.
503
- * @category API Response Assertion Steps
504
- */
505
- function Then_I_see_response_header_does_not_contain(headerName, unexpectedPart) {
506
- const res = getValidatedLastResponse(this);
507
- const headerValue = res.headers[headerName.toLowerCase()]; // Access from plain object
508
- if (headerValue !== undefined) {
509
- // Only check if header exists
510
- (0, test_1.expect)(headerValue, `Expected header "${headerName}" to NOT contain "${unexpectedPart}", but it does.`).not.toContain(unexpectedPart);
511
- }
512
- this.log?.(`✅ Verified response header "${headerName}" does NOT contain "${unexpectedPart}".`);
513
- }
514
- (0, cucumber_1.Then)("I see response header {string} does not contain {string}", Then_I_see_response_header_does_not_contain);
515
- /**
516
- * Asserts that a specific header in the last API response does NOT strictly equal a given value.
517
- *
518
- * ```gherkin
519
- * Then I see response header {string} does not equal {string}
520
- * ```
521
- *
522
- * @param headerName - The name of the header (case-insensitive).
523
- * @param unexpectedValue - The value that is NOT expected for the header.
524
- *
525
- * @example
526
- * When I make request to "https://api.example.com/html-page"
527
- * Then I see response header "content-type" does not equal "application/json"
528
- *
529
- * @remarks
530
- * This step requires a preceding step that stores the API response in
531
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
532
- * It retrieves the header value and asserts that it does not strictly match `unexpectedValue`.
533
- * @category API Response Assertion Steps
534
- */
535
- function Then_I_see_response_header_does_not_equal(headerName, unexpectedValue) {
536
- const res = getValidatedLastResponse(this);
537
- const headerValue = res.headers[headerName.toLowerCase()]; // Access from plain object
538
- (0, test_1.expect)(headerValue, `Expected header "${headerName}" to NOT be "${unexpectedValue}", but it is.`).not.toBe(unexpectedValue);
539
- this.log?.(`✅ Verified response header "${headerName}" does NOT equal "${unexpectedValue}".`);
540
- }
541
- (0, cucumber_1.Then)("I see response header {string} does not equal {string}", Then_I_see_response_header_does_not_equal);
542
- /**
543
- * Asserts that a specific header in the last API response exists (is present).
544
- *
545
- * ```gherkin
546
- * Then I see response header {string} exists
547
- * ```
548
- *
549
- * @param headerName - The name of the header expected to exist.
550
- *
551
- * @example
552
- * When I make request to "https://api.example.com/data"
553
- * Then I see response header "content-length" exists
554
- *
555
- * @remarks
556
- * This step requires a preceding step that stores the API response in
557
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
558
- * It checks if the header value is defined (not `undefined` or `null`).
559
- * @category API Response Assertion Steps
560
- */
561
- function Then_I_see_response_header_exists(headerName) {
562
- const res = getValidatedLastResponse(this);
563
- const headerValue = res.headers[headerName.toLowerCase()]; // Access from plain object
564
- (0, test_1.expect)(headerValue, `Header "${headerName}" should exist but was not found.`).toBeDefined();
565
- this.log?.(`✅ Verified response header "${headerName}" exists.`);
566
- }
567
- (0, cucumber_1.Then)("I see response header {string} exists", Then_I_see_response_header_exists);
568
- /**
569
- * Asserts that a specific header in the last API response does NOT exist (is not present).
570
- *
571
- * ```gherkin
572
- * Then I see response header {string} does not exist
573
- * ```
574
- *
575
- * @param headerName - The name of the header expected NOT to exist.
576
- *
577
- * @example
578
- * When I make request to "https://api.example.com/simple"
579
- * Then I see response header "x-powered-by" does not exist
580
- *
581
- * @remarks
582
- * This step requires a preceding step that stores the API response in
583
- * {@link CustomWorld.data.lastResponse | this.data.lastResponse}.
584
- * It checks if the header value is `undefined` or `null`.
585
- * @category API Response Assertion Steps
586
- */
587
- function Then_I_see_response_header_does_not_exist(headerName) {
588
- const res = getValidatedLastResponse(this);
589
- const headerValue = res.headers[headerName.toLowerCase()]; // Access from plain object
590
- (0, test_1.expect)(headerValue, `Header "${headerName}" should NOT exist but was found.`).toBeUndefined();
591
- this.log?.(`✅ Verified response header "${headerName}" does NOT exist.`);
592
- }
593
- (0, cucumber_1.Then)("I see response header {string} does not exist", Then_I_see_response_header_does_not_exist);