artes 1.7.20 → 1.7.21

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 (49) hide show
  1. package/README.md +781 -781
  2. package/assets/styles.css +4 -4
  3. package/cucumber.config.js +253 -253
  4. package/docs/ciExecutors.md +198 -198
  5. package/docs/emulationDevicesList.md +152 -152
  6. package/docs/functionDefinitions.md +2401 -2401
  7. package/docs/stepDefinitions.md +435 -435
  8. package/executer.js +266 -266
  9. package/index.js +51 -51
  10. package/package.json +56 -56
  11. package/src/helper/contextManager/browserManager.js +74 -74
  12. package/src/helper/contextManager/requestManager.js +23 -23
  13. package/src/helper/controller/elementController.js +230 -230
  14. package/src/helper/controller/findDuplicateTestNames.js +69 -69
  15. package/src/helper/controller/getEnvInfo.js +97 -97
  16. package/src/helper/controller/getExecutor.js +109 -109
  17. package/src/helper/controller/pomCollector.js +83 -83
  18. package/src/helper/controller/reportCustomizer.js +511 -511
  19. package/src/helper/controller/screenComparer.js +96 -96
  20. package/src/helper/controller/status-formatter.js +137 -137
  21. package/src/helper/controller/testCoverageCalculator.js +111 -111
  22. package/src/helper/executers/cleaner.js +23 -23
  23. package/src/helper/executers/exporter.js +19 -19
  24. package/src/helper/executers/helper.js +193 -193
  25. package/src/helper/executers/projectCreator.js +226 -226
  26. package/src/helper/executers/reportGenerator.js +91 -91
  27. package/src/helper/executers/testRunner.js +28 -28
  28. package/src/helper/executers/versionChecker.js +31 -31
  29. package/src/helper/imports/commons.js +69 -69
  30. package/src/helper/stepFunctions/APIActions.js +582 -582
  31. package/src/helper/stepFunctions/assertions.js +986 -986
  32. package/src/helper/stepFunctions/browserActions.js +87 -87
  33. package/src/helper/stepFunctions/elementInteractions.js +60 -60
  34. package/src/helper/stepFunctions/exporter.js +19 -19
  35. package/src/helper/stepFunctions/frameActions.js +72 -72
  36. package/src/helper/stepFunctions/keyboardActions.js +66 -66
  37. package/src/helper/stepFunctions/mouseActions.js +84 -84
  38. package/src/helper/stepFunctions/pageActions.js +43 -43
  39. package/src/hooks/context.js +18 -18
  40. package/src/hooks/hooks.js +287 -287
  41. package/src/stepDefinitions/API.steps.js +404 -404
  42. package/src/stepDefinitions/assertions.steps.js +1358 -1349
  43. package/src/stepDefinitions/browser.steps.js +74 -74
  44. package/src/stepDefinitions/frameActions.steps.js +76 -76
  45. package/src/stepDefinitions/keyboardActions.steps.js +264 -264
  46. package/src/stepDefinitions/mouseActions.steps.js +374 -374
  47. package/src/stepDefinitions/page.steps.js +71 -71
  48. package/src/stepDefinitions/random.steps.js +199 -199
  49. package/src/stepDefinitions/report.steps.js +5 -5
@@ -1,405 +1,405 @@
1
- const {
2
- When,
3
- context,
4
- extractVarsFromResponse,
5
- saveVar,
6
- time,
7
- random,
8
- moduleConfig,
9
- resolveVariable,
10
- normalizeCrossplatformPath
11
- } = require("../helper/imports/commons");
12
- const { api } = require("../helper/stepFunctions/exporter");
13
- const path = require("path");
14
- const fs = require("fs");
15
- require("allure-cucumberjs");
16
- const allure = require("allure-js-commons");
17
-
18
-
19
- When("User sends GET request to {string}", async function (url) {
20
- await api.get(url);
21
- });
22
-
23
- When(
24
- "User sends GET request to {string} with payload:",
25
- async function (url, payload) {
26
- await api.get(url, payload);
27
- },
28
- );
29
-
30
- When(
31
- "User sends GET request to {string} and saves {string} variables",
32
- async function (url, vars) {
33
- await api.get(url);
34
- await extractVarsFromResponse(context.response["Response Body"], vars);
35
- },
36
- );
37
-
38
- When(
39
- "User sends GET request to {string} with payload and saves {string} variables",
40
- async function (url, vars, payload) {
41
- await api.get(url, payload);
42
- await extractVarsFromResponse(context.response["Response Body"], vars);
43
- },
44
- );
45
-
46
- When("User sends HEAD request to {string}", async function (url) {
47
- await api.head(url);
48
- });
49
-
50
- When(
51
- "User sends POST request to {string} with payload:",
52
- async function (url, payload) {
53
- await api.post(url, payload);
54
- },
55
- );
56
-
57
- When(
58
- "User sends POST request to {string} with payload and saves {string} variables",
59
- async function (url, vars, payload) {
60
- await api.post(url, payload);
61
- await extractVarsFromResponse(context.response["Response Body"], vars);
62
- },
63
- );
64
-
65
- When(
66
- "User sends multipart POST request to {string} with payload:",
67
- async (url, payload) => {
68
- await api.post(url, payload, "multipart");
69
- },
70
- );
71
-
72
- When(
73
- "User sends multipart POST request to {string} with payload and saves {string} variables",
74
- async (url, vars, payload) => {
75
- await api.post(url, payload, "multipart");
76
- await extractVarsFromResponse(context.response["Response Body"], vars);
77
- },
78
- );
79
-
80
- When(
81
- "User sends x-www-form-urlencoded POST request to {string} with payload:",
82
- async (url, payload) => {
83
- await api.post(url, payload, "application/x-www-form-urlencoded");
84
- },
85
- );
86
-
87
- When(
88
- "User sends x-www-form-urlencoded POST request to {string} with payload and saves {string} variables",
89
- async (url, vars, payload) => {
90
- await api.post(url, payload, "application/x-www-form-urlencoded");
91
- await extractVarsFromResponse(context.response["Response Body"], vars);
92
- },
93
- );
94
-
95
- When(
96
- "User sends xml POST request to {string} with payload:",
97
- async (url, payload) => {
98
- await api.post(url, payload, "xml");
99
- },
100
- );
101
-
102
- When(
103
- "User sends xml POST request to {string} with payload and saves {string} variables",
104
- async (url, vars, payload) => {
105
- await api.post(url, payload, "xml");
106
- await extractVarsFromResponse(context.response["Response Body"], vars);
107
- },
108
- );
109
-
110
- When(
111
- "User sends PUT request to {string} with payload:",
112
- async function (url, payload) {
113
- await api.put(url, payload);
114
- },
115
- );
116
-
117
- When(
118
- "User sends PUT request to {string} with payload and saves {string} variables",
119
- async function (url, vars, payload) {
120
- await api.put(url, payload);
121
- await extractVarsFromResponse(context.response["Response Body"], vars);
122
- },
123
- );
124
-
125
- When(
126
- "User sends multipart PUT request to {string} with payload:",
127
- async function (url, payload) {
128
- await api.put(url, payload, "multipart");
129
- },
130
- );
131
-
132
- When(
133
- "User sends multipart PUT request to {string} with payload and saves {string} variables",
134
- async function (url, vars, payload) {
135
- await api.put(url, payload, "multipart");
136
- await extractVarsFromResponse(context.response["Response Body"], vars);
137
- },
138
- );
139
-
140
- When(
141
- "User sends x-www-form-urlencoded PUT request to {string} with payload:",
142
- async (url, payload) => {
143
- await api.put(url, payload, "application/x-www-form-urlencoded");
144
- },
145
- );
146
-
147
- When(
148
- "User sends x-www-form-urlencoded PUT request to {string} with payload and saves {string} variables",
149
- async (url, vars, payload) => {
150
- await api.put(url, payload, "application/x-www-form-urlencoded");
151
- await extractVarsFromResponse(context.response["Response Body"], vars);
152
- },
153
- );
154
-
155
- When(
156
- "User sends xml PUT request to {string} with payload:",
157
- async (url, payload) => {
158
- await api.put(url, payload, "xml");
159
- },
160
- );
161
-
162
- When(
163
- "User sends xml PUT request to {string} with payload and saves {string} variables",
164
- async (url, vars, payload) => {
165
- await api.put(url, payload, "xml");
166
- await extractVarsFromResponse(context.response["Response Body"], vars);
167
- },
168
- );
169
-
170
- When(
171
- "User sends PATCH request to {string} with payload:",
172
- async function (url, payload) {
173
- await api.patch(url, payload);
174
- },
175
- );
176
-
177
- When(
178
- "User sends PATCH request to {string} with payload and saves {string} variables",
179
- async function (url, vars, payload) {
180
- await api.patch(url, payload);
181
- await extractVarsFromResponse(context.response["Response Body"], vars);
182
- },
183
- );
184
-
185
- When(
186
- "User sends multipart PATCH request to {string} with payload:",
187
- async function (url, payload) {
188
- await api.patch(url, payload, "multipart");
189
- },
190
- );
191
-
192
- When(
193
- "User sends multipart PATCH request to {string} with payload and saves {string} variables",
194
- async function (url, vars, payload) {
195
- await api.patch(url, payload, "multipart");
196
- await extractVarsFromResponse(context.response["Response Body"], vars);
197
- },
198
- );
199
-
200
- When(
201
- "User sends x-www-form-urlencoded PATCH request to {string} with payload:",
202
- async (url, payload) => {
203
- await api.patch(url, payload, "application/x-www-form-urlencoded");
204
- },
205
- );
206
-
207
- When(
208
- "User sends x-www-form-urlencoded PATCH request to {string} with payload and saves {string} variables",
209
- async (url, vars, payload) => {
210
- await api.patch(url, payload, "application/x-www-form-urlencoded");
211
- await extractVarsFromResponse(context.response["Response Body"], vars);
212
- },
213
- );
214
-
215
- When(
216
- "User sends xml PATCH request to {string} with payload:",
217
- async (url, payload) => {
218
- await api.patch(url, payload, "xml");
219
- },
220
- );
221
-
222
- When(
223
- "User sends xml PATCH request to {string} with payload and saves {string} variables",
224
- async (url, vars, payload) => {
225
- await api.patch(url, payload, "xml");
226
- await extractVarsFromResponse(context.response["Response Body"], vars);
227
- },
228
- );
229
-
230
- When("User sends DELETE request to {string}", async function (url) {
231
- await api.delete(url);
232
- });
233
-
234
- When(
235
- "User sends DELETE request to {string} and saves {string} variables",
236
- async function (url, vars) {
237
- await api.delete(url);
238
- await extractVarsFromResponse(context.response["Response Body"], vars);
239
- },
240
- );
241
-
242
- When(
243
- "User sends DELETE request to {string} with payload:",
244
- async function (url, payload) {
245
- await api.delete(url, payload);
246
- },
247
- );
248
-
249
- When(
250
- "User sends DELETE request to {string} with payload and saves {string}",
251
- async function (url, vars, payload) {
252
- await api.delete(url, payload);
253
- await extractVarsFromResponse(context.response["Response Body"], vars);
254
- },
255
- );
256
-
257
- When(
258
- "User sends xml DELETE request to {string} with payload:",
259
- async (url, payload) => {
260
- await api.delete(url, payload, "xml");
261
- },
262
- );
263
-
264
- When(
265
- "User sends xml DELETE request to {string} with payload and saves {string} variables",
266
- async (url, vars, payload) => {
267
- await api.delete(url, payload, "xml");
268
- await extractVarsFromResponse(context.response["Response Body"], vars);
269
- },
270
- );
271
-
272
- When(
273
- "User saves {string} variable from response as {string}",
274
- async function (vars, customVarName) {
275
- await extractVarsFromResponse(
276
- context.response["Response Body"],
277
- vars,
278
- customVarName,
279
- );
280
- },
281
- );
282
-
283
- When(
284
- "User saves {string} variable as {string}",
285
- async function (value, customVarName) {
286
- saveVar(value, customVarName);
287
- },
288
- );
289
-
290
- When(
291
- 'User sets {int} year from current year as {string}',
292
- async function (year, yearName) {
293
- const targetYear = time().add(year, 'year').year();
294
- context.vars[yearName] = targetYear.toString();
295
- }
296
- );
297
-
298
- When(
299
- 'User sets {int} month from current month as {string}',
300
- async function (month, monthName) {
301
- const targetMonth = time().add(month, 'month').month() + 1;
302
-
303
- context.vars[monthName] = targetMonth.toString().padStart(2, '0');
304
- }
305
- );
306
-
307
- When(
308
- "User saves request time in ISO format as {string}",
309
- async (request_time) => {
310
- context.vars[request_time] = new Date(
311
- context.response["Response Headers"].date,
312
- ).toISOString();
313
- allure.attachment("Request Time", context.vars[request_time], "text/plain");
314
- },
315
- );
316
-
317
- When("User wants to see saved variables", async function () {
318
- console.log("\nVariables:", api.vars(null), "\n");
319
- });
320
-
321
- When("User wants to see {string} variable", async function (variable) {
322
- console.log(api.vars(variable), "\n");
323
- });
324
-
325
- When("User wants to see request body", async function () {
326
- console.log("Request Body: ", context.response["Request Body"]);
327
- });
328
-
329
- When("User wants to see response body", async function () {
330
- console.log("Response Body: ", context.response["Response Body"]);
331
- });
332
-
333
- When(
334
- "User sends {string} request to {string} with payload:",
335
- async function (method, url, payload) {
336
- const httpMethod = method.toUpperCase();
337
-
338
- switch (httpMethod) {
339
- case "GET":
340
- await api.get(url, payload);
341
- break;
342
- case "HEAD":
343
- await api.head(url, payload);
344
- break;
345
- case "POST":
346
- await api.post(url, payload);
347
- break;
348
- case "PUT":
349
- await api.put(url, payload);
350
- break;
351
- case "PATCH":
352
- await api.patch(url, payload);
353
- break;
354
- case "DELETE":
355
- await api.delete(url, payload);
356
- break;
357
- default:
358
- throw new Error(`Unsupported HTTP method: ${httpMethod}`);
359
- }
360
- },
361
- );
362
-
363
- When(
364
- "User sends GET request to {string} and save {string} variable from {string} array as {string} randomly with payload:",
365
- async (endPoint, varName, fromArray, variableKey, payload) => {
366
- await api.get(endPoint, payload);
367
- let responseBody;
368
- if (fromArray == "[]") {
369
- responseBody = await context.response["Response Body"];
370
- } else {
371
- responseBody = await context.response["Response Body"][fromArray];
372
- }
373
- const randomContent =
374
- responseBody[random.number.int({ min: 0, max: responseBody.length - 1 })];
375
- context.vars[variableKey] = randomContent[varName];
376
- },
377
- );
378
-
379
- When(
380
- "User sets {string} date {int} days from today",
381
- async function (dateName, days) {
382
- const expiresAt =
383
- days < 0
384
- ? time().subtract(Math.abs(days), "day").toISOString()
385
- : time().add(days, "day").toISOString();
386
-
387
- context.vars[dateName] = expiresAt;
388
- },
389
- );
390
-
391
- When(
392
- "User convert {string} into base64 as {string}",
393
- async (file, variable) => {
394
- file = await resolveVariable(file);
395
-
396
- const normalizedFile = normalizeCrossplatformPath(file);
397
-
398
- const filePath = path.isAbsolute(normalizedFile)
399
- ? normalizedFile
400
- : path.join(moduleConfig.projectPath, normalizedFile);
401
-
402
- const fileData = fs.readFileSync(filePath);
403
- context.vars[variable] = fileData.toString("base64");
404
- },
1
+ const {
2
+ When,
3
+ context,
4
+ extractVarsFromResponse,
5
+ saveVar,
6
+ time,
7
+ random,
8
+ moduleConfig,
9
+ resolveVariable,
10
+ normalizeCrossplatformPath
11
+ } = require("../helper/imports/commons");
12
+ const { api } = require("../helper/stepFunctions/exporter");
13
+ const path = require("path");
14
+ const fs = require("fs");
15
+ require("allure-cucumberjs");
16
+ const allure = require("allure-js-commons");
17
+
18
+
19
+ When("User sends GET request to {string}", async function (url) {
20
+ await api.get(url);
21
+ });
22
+
23
+ When(
24
+ "User sends GET request to {string} with payload:",
25
+ async function (url, payload) {
26
+ await api.get(url, payload);
27
+ },
28
+ );
29
+
30
+ When(
31
+ "User sends GET request to {string} and saves {string} variables",
32
+ async function (url, vars) {
33
+ await api.get(url);
34
+ await extractVarsFromResponse(context.response["Response Body"], vars);
35
+ },
36
+ );
37
+
38
+ When(
39
+ "User sends GET request to {string} with payload and saves {string} variables",
40
+ async function (url, vars, payload) {
41
+ await api.get(url, payload);
42
+ await extractVarsFromResponse(context.response["Response Body"], vars);
43
+ },
44
+ );
45
+
46
+ When("User sends HEAD request to {string}", async function (url) {
47
+ await api.head(url);
48
+ });
49
+
50
+ When(
51
+ "User sends POST request to {string} with payload:",
52
+ async function (url, payload) {
53
+ await api.post(url, payload);
54
+ },
55
+ );
56
+
57
+ When(
58
+ "User sends POST request to {string} with payload and saves {string} variables",
59
+ async function (url, vars, payload) {
60
+ await api.post(url, payload);
61
+ await extractVarsFromResponse(context.response["Response Body"], vars);
62
+ },
63
+ );
64
+
65
+ When(
66
+ "User sends multipart POST request to {string} with payload:",
67
+ async (url, payload) => {
68
+ await api.post(url, payload, "multipart");
69
+ },
70
+ );
71
+
72
+ When(
73
+ "User sends multipart POST request to {string} with payload and saves {string} variables",
74
+ async (url, vars, payload) => {
75
+ await api.post(url, payload, "multipart");
76
+ await extractVarsFromResponse(context.response["Response Body"], vars);
77
+ },
78
+ );
79
+
80
+ When(
81
+ "User sends x-www-form-urlencoded POST request to {string} with payload:",
82
+ async (url, payload) => {
83
+ await api.post(url, payload, "application/x-www-form-urlencoded");
84
+ },
85
+ );
86
+
87
+ When(
88
+ "User sends x-www-form-urlencoded POST request to {string} with payload and saves {string} variables",
89
+ async (url, vars, payload) => {
90
+ await api.post(url, payload, "application/x-www-form-urlencoded");
91
+ await extractVarsFromResponse(context.response["Response Body"], vars);
92
+ },
93
+ );
94
+
95
+ When(
96
+ "User sends xml POST request to {string} with payload:",
97
+ async (url, payload) => {
98
+ await api.post(url, payload, "xml");
99
+ },
100
+ );
101
+
102
+ When(
103
+ "User sends xml POST request to {string} with payload and saves {string} variables",
104
+ async (url, vars, payload) => {
105
+ await api.post(url, payload, "xml");
106
+ await extractVarsFromResponse(context.response["Response Body"], vars);
107
+ },
108
+ );
109
+
110
+ When(
111
+ "User sends PUT request to {string} with payload:",
112
+ async function (url, payload) {
113
+ await api.put(url, payload);
114
+ },
115
+ );
116
+
117
+ When(
118
+ "User sends PUT request to {string} with payload and saves {string} variables",
119
+ async function (url, vars, payload) {
120
+ await api.put(url, payload);
121
+ await extractVarsFromResponse(context.response["Response Body"], vars);
122
+ },
123
+ );
124
+
125
+ When(
126
+ "User sends multipart PUT request to {string} with payload:",
127
+ async function (url, payload) {
128
+ await api.put(url, payload, "multipart");
129
+ },
130
+ );
131
+
132
+ When(
133
+ "User sends multipart PUT request to {string} with payload and saves {string} variables",
134
+ async function (url, vars, payload) {
135
+ await api.put(url, payload, "multipart");
136
+ await extractVarsFromResponse(context.response["Response Body"], vars);
137
+ },
138
+ );
139
+
140
+ When(
141
+ "User sends x-www-form-urlencoded PUT request to {string} with payload:",
142
+ async (url, payload) => {
143
+ await api.put(url, payload, "application/x-www-form-urlencoded");
144
+ },
145
+ );
146
+
147
+ When(
148
+ "User sends x-www-form-urlencoded PUT request to {string} with payload and saves {string} variables",
149
+ async (url, vars, payload) => {
150
+ await api.put(url, payload, "application/x-www-form-urlencoded");
151
+ await extractVarsFromResponse(context.response["Response Body"], vars);
152
+ },
153
+ );
154
+
155
+ When(
156
+ "User sends xml PUT request to {string} with payload:",
157
+ async (url, payload) => {
158
+ await api.put(url, payload, "xml");
159
+ },
160
+ );
161
+
162
+ When(
163
+ "User sends xml PUT request to {string} with payload and saves {string} variables",
164
+ async (url, vars, payload) => {
165
+ await api.put(url, payload, "xml");
166
+ await extractVarsFromResponse(context.response["Response Body"], vars);
167
+ },
168
+ );
169
+
170
+ When(
171
+ "User sends PATCH request to {string} with payload:",
172
+ async function (url, payload) {
173
+ await api.patch(url, payload);
174
+ },
175
+ );
176
+
177
+ When(
178
+ "User sends PATCH request to {string} with payload and saves {string} variables",
179
+ async function (url, vars, payload) {
180
+ await api.patch(url, payload);
181
+ await extractVarsFromResponse(context.response["Response Body"], vars);
182
+ },
183
+ );
184
+
185
+ When(
186
+ "User sends multipart PATCH request to {string} with payload:",
187
+ async function (url, payload) {
188
+ await api.patch(url, payload, "multipart");
189
+ },
190
+ );
191
+
192
+ When(
193
+ "User sends multipart PATCH request to {string} with payload and saves {string} variables",
194
+ async function (url, vars, payload) {
195
+ await api.patch(url, payload, "multipart");
196
+ await extractVarsFromResponse(context.response["Response Body"], vars);
197
+ },
198
+ );
199
+
200
+ When(
201
+ "User sends x-www-form-urlencoded PATCH request to {string} with payload:",
202
+ async (url, payload) => {
203
+ await api.patch(url, payload, "application/x-www-form-urlencoded");
204
+ },
205
+ );
206
+
207
+ When(
208
+ "User sends x-www-form-urlencoded PATCH request to {string} with payload and saves {string} variables",
209
+ async (url, vars, payload) => {
210
+ await api.patch(url, payload, "application/x-www-form-urlencoded");
211
+ await extractVarsFromResponse(context.response["Response Body"], vars);
212
+ },
213
+ );
214
+
215
+ When(
216
+ "User sends xml PATCH request to {string} with payload:",
217
+ async (url, payload) => {
218
+ await api.patch(url, payload, "xml");
219
+ },
220
+ );
221
+
222
+ When(
223
+ "User sends xml PATCH request to {string} with payload and saves {string} variables",
224
+ async (url, vars, payload) => {
225
+ await api.patch(url, payload, "xml");
226
+ await extractVarsFromResponse(context.response["Response Body"], vars);
227
+ },
228
+ );
229
+
230
+ When("User sends DELETE request to {string}", async function (url) {
231
+ await api.delete(url);
232
+ });
233
+
234
+ When(
235
+ "User sends DELETE request to {string} and saves {string} variables",
236
+ async function (url, vars) {
237
+ await api.delete(url);
238
+ await extractVarsFromResponse(context.response["Response Body"], vars);
239
+ },
240
+ );
241
+
242
+ When(
243
+ "User sends DELETE request to {string} with payload:",
244
+ async function (url, payload) {
245
+ await api.delete(url, payload);
246
+ },
247
+ );
248
+
249
+ When(
250
+ "User sends DELETE request to {string} with payload and saves {string}",
251
+ async function (url, vars, payload) {
252
+ await api.delete(url, payload);
253
+ await extractVarsFromResponse(context.response["Response Body"], vars);
254
+ },
255
+ );
256
+
257
+ When(
258
+ "User sends xml DELETE request to {string} with payload:",
259
+ async (url, payload) => {
260
+ await api.delete(url, payload, "xml");
261
+ },
262
+ );
263
+
264
+ When(
265
+ "User sends xml DELETE request to {string} with payload and saves {string} variables",
266
+ async (url, vars, payload) => {
267
+ await api.delete(url, payload, "xml");
268
+ await extractVarsFromResponse(context.response["Response Body"], vars);
269
+ },
270
+ );
271
+
272
+ When(
273
+ "User saves {string} variable from response as {string}",
274
+ async function (vars, customVarName) {
275
+ await extractVarsFromResponse(
276
+ context.response["Response Body"],
277
+ vars,
278
+ customVarName,
279
+ );
280
+ },
281
+ );
282
+
283
+ When(
284
+ "User saves {string} variable as {string}",
285
+ async function (value, customVarName) {
286
+ saveVar(value, customVarName);
287
+ },
288
+ );
289
+
290
+ When(
291
+ 'User sets {int} year from current year as {string}',
292
+ async function (year, yearName) {
293
+ const targetYear = time().add(year, 'year').year();
294
+ context.vars[yearName] = targetYear.toString();
295
+ }
296
+ );
297
+
298
+ When(
299
+ 'User sets {int} month from current month as {string}',
300
+ async function (month, monthName) {
301
+ const targetMonth = time().add(month, 'month').month() + 1;
302
+
303
+ context.vars[monthName] = targetMonth.toString().padStart(2, '0');
304
+ }
305
+ );
306
+
307
+ When(
308
+ "User saves request time in ISO format as {string}",
309
+ async (request_time) => {
310
+ context.vars[request_time] = new Date(
311
+ context.response["Response Headers"].date,
312
+ ).toISOString();
313
+ allure.attachment("Request Time", context.vars[request_time], "text/plain");
314
+ },
315
+ );
316
+
317
+ When("User wants to see saved variables", async function () {
318
+ console.log("\nVariables:", api.vars(null), "\n");
319
+ });
320
+
321
+ When("User wants to see {string} variable", async function (variable) {
322
+ console.log(api.vars(variable), "\n");
323
+ });
324
+
325
+ When("User wants to see request body", async function () {
326
+ console.log("Request Body: ", context.response["Request Body"]);
327
+ });
328
+
329
+ When("User wants to see response body", async function () {
330
+ console.log("Response Body: ", context.response["Response Body"]);
331
+ });
332
+
333
+ When(
334
+ "User sends {string} request to {string} with payload:",
335
+ async function (method, url, payload) {
336
+ const httpMethod = method.toUpperCase();
337
+
338
+ switch (httpMethod) {
339
+ case "GET":
340
+ await api.get(url, payload);
341
+ break;
342
+ case "HEAD":
343
+ await api.head(url, payload);
344
+ break;
345
+ case "POST":
346
+ await api.post(url, payload);
347
+ break;
348
+ case "PUT":
349
+ await api.put(url, payload);
350
+ break;
351
+ case "PATCH":
352
+ await api.patch(url, payload);
353
+ break;
354
+ case "DELETE":
355
+ await api.delete(url, payload);
356
+ break;
357
+ default:
358
+ throw new Error(`Unsupported HTTP method: ${httpMethod}`);
359
+ }
360
+ },
361
+ );
362
+
363
+ When(
364
+ "User sends GET request to {string} and save {string} variable from {string} array as {string} randomly with payload:",
365
+ async (endPoint, varName, fromArray, variableKey, payload) => {
366
+ await api.get(endPoint, payload);
367
+ let responseBody;
368
+ if (fromArray == "[]") {
369
+ responseBody = await context.response["Response Body"];
370
+ } else {
371
+ responseBody = await context.response["Response Body"][fromArray];
372
+ }
373
+ const randomContent =
374
+ responseBody[random.number.int({ min: 0, max: responseBody.length - 1 })];
375
+ context.vars[variableKey] = randomContent[varName];
376
+ },
377
+ );
378
+
379
+ When(
380
+ "User sets {string} date {int} days from today",
381
+ async function (dateName, days) {
382
+ const expiresAt =
383
+ days < 0
384
+ ? time().subtract(Math.abs(days), "day").toISOString()
385
+ : time().add(days, "day").toISOString();
386
+
387
+ context.vars[dateName] = expiresAt;
388
+ },
389
+ );
390
+
391
+ When(
392
+ "User convert {string} into base64 as {string}",
393
+ async (file, variable) => {
394
+ file = await resolveVariable(file);
395
+
396
+ const normalizedFile = normalizeCrossplatformPath(file);
397
+
398
+ const filePath = path.isAbsolute(normalizedFile)
399
+ ? normalizedFile
400
+ : path.join(moduleConfig.projectPath, normalizedFile);
401
+
402
+ const fileData = fs.readFileSync(filePath);
403
+ context.vars[variable] = fileData.toString("base64");
404
+ },
405
405
  );