artes 1.7.19 → 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 -1351
  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,582 +1,582 @@
1
- const path = require("path");
2
- const fs = require("fs");
3
- const {
4
- context,
5
- selector,
6
- resolveVariable,
7
- moduleConfig,
8
- normalizeCrossplatformPath
9
- } = require("../imports/commons");
10
-
11
- function getMimeType(filePath) {
12
- const ext = path.extname(filePath).toLowerCase();
13
- const mimeTypes = {
14
- ".jpg": "image/jpeg",
15
- ".jpeg": "image/jpeg",
16
- ".png": "image/png",
17
- ".gif": "image/gif",
18
- ".pdf": "application/pdf",
19
- ".txt": "text/plain",
20
- ".json": "application/json",
21
- ".xml": "application/xml",
22
- ".zip": "application/zip",
23
- ".doc": "application/msword",
24
- ".docx":
25
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
26
- ".csv": "text/csv",
27
- };
28
-
29
- return mimeTypes[ext] || "application/octet-stream";
30
- }
31
-
32
- function curlExtractor(url, method, headers, body, requestDataType) {
33
- let curlCommand = `curl -X ${method} '${url}'`;
34
-
35
- if (headers && Object.keys(headers).length > 0) {
36
- for (const [key, value] of Object.entries(headers)) {
37
- curlCommand += ` \\\n -H '${key}: ${value}'`;
38
- }
39
- }
40
-
41
- if (body && Object.keys(body).length > 0) {
42
- switch (requestDataType) {
43
- case "multipart":
44
- for (const [key, value] of Object.entries(body)) {
45
- if (typeof value === "object" && value.buffer) {
46
- curlCommand += ` \\\n -F '${key}=@${value.name}'`;
47
- } else {
48
- curlCommand += ` \\\n -F '${key}=${value}'`;
49
- }
50
- }
51
- break;
52
- case "xml":
53
- curlCommand += ` \\\n -H 'Content-Type: application/xml'`;
54
- curlCommand += ` \\\n --data-raw '${data}'`;
55
- break;
56
-
57
- case "urlencoded":
58
- case "application/x-www-form-urlencoded":
59
- const urlEncodedData = new URLSearchParams(body).toString();
60
- curlCommand += ` \\\n --data-urlencode '${urlEncodedData}'`;
61
- break;
62
-
63
- case "form":
64
- for (const [key, value] of Object.entries(body)) {
65
- curlCommand += ` \\\n -F '${key}=${value}'`;
66
- }
67
- break;
68
-
69
- default:
70
- const hasContentType =
71
- headers &&
72
- Object.keys(headers).some(
73
- (key) => key.toLowerCase() === "content-type",
74
- );
75
-
76
- if (!hasContentType) {
77
- curlCommand += ` \\\n -H 'Content-Type: application/json'`;
78
- }
79
-
80
- curlCommand += ` \\\n --data-raw '${JSON.stringify(body)}'`;
81
- break;
82
- }
83
- }
84
-
85
- return curlCommand;
86
- }
87
-
88
- function processForm(requestBody) {
89
- let formData = {};
90
- for (const [key, value] of Object.entries(requestBody)) {
91
- if (value === null || value === undefined) {
92
- continue;
93
- }
94
-
95
- if (typeof value === "object") {
96
- if (value.contentType) {
97
- const content =
98
- typeof value.data === "object"
99
- ? JSON.stringify(value.data)
100
- : String(value.data);
101
-
102
- formData[key] = {
103
- name: value.filename || key,
104
- mimeType: value.contentType,
105
- buffer: Buffer.from(content, "utf8"),
106
- };
107
- continue;
108
- } else {
109
- formData[key] = JSON.stringify(value);
110
- continue;
111
- }
112
- }
113
-
114
- if (typeof value === "string") {
115
-
116
- const normalizedValue = normalizeCrossplatformPath(value);
117
-
118
- const looksLikeFilePath =
119
- normalizedValue.endsWith(".pdf") ||
120
- normalizedValue.endsWith(".jpg") ||
121
- normalizedValue.endsWith(".jpeg") ||
122
- normalizedValue.endsWith(".png") ||
123
- normalizedValue.endsWith(".txt") ||
124
- normalizedValue.endsWith(".doc") ||
125
- normalizedValue.endsWith(".docx") ||
126
- normalizedValue.includes("/");
127
-
128
- if (looksLikeFilePath) {
129
- try {
130
- const filePath = path.isAbsolute(normalizedValue)
131
- ? normalizedValue
132
- : path.join(moduleConfig.projectPath, normalizedValue);
133
-
134
- if (fs.existsSync(filePath)) {
135
- formData[key] = {
136
- name: path.basename(filePath),
137
- mimeType: getMimeType(filePath),
138
- buffer: fs.readFileSync(filePath),
139
- };
140
- continue;
141
- }
142
- } catch (error) {
143
- console.log(error);
144
- }
145
- }
146
- }
147
-
148
- formData[key] = value;
149
- }
150
- return formData;
151
- }
152
-
153
- async function requestMaker(headers, data, requestDataType) {
154
- let request = {};
155
-
156
- Object.assign(request, { headers: headers });
157
-
158
- switch (requestDataType) {
159
- case "multipart":
160
- Object.assign(request, { multipart: data });
161
- break;
162
- case "xml":
163
- Object.assign(request, {
164
- headers: { ...headers, "Content-Type": "application/xml" },
165
- data: data,
166
- });
167
- break;
168
- case "urlencoded":
169
- case "application/x-www-form-urlencoded":
170
- const urlEncodedData = new URLSearchParams(data).toString();
171
- Object.assign(request, { data: urlEncodedData });
172
- break;
173
- case "form":
174
- Object.assign(request, { form: data });
175
- break;
176
- default:
177
- Object.assign(request, { data: data });
178
- }
179
-
180
- return request;
181
- }
182
-
183
- async function responseMaker(request, response, duration, curlCommand) {
184
- const responseObject = {};
185
-
186
- response &&
187
- Object.assign(responseObject, {
188
- "Response Params": `URL: ${response.url()}
189
- Response Status: ${await response.status()}
190
- Response Time: ${Math.round(duration)} ms`,
191
- });
192
-
193
- request?.headers &&
194
- Object.assign(responseObject, { "Request Headers": await request.headers });
195
-
196
- request?.body &&
197
- Object.assign(responseObject, { "Request Body": await request.body });
198
-
199
- response && Object.assign(responseObject, { Response: await response });
200
-
201
- response &&
202
- Object.assign(responseObject, {
203
- "Response Headers": await response.headers(),
204
- });
205
-
206
- if (response) {
207
- try {
208
- Object.assign(responseObject, { "Response Body": await response.json() });
209
- } catch (e) {
210
- Object.assign(responseObject, { "Response Body": await response.text() });
211
- }
212
- }
213
-
214
- curlCommand && Object.assign(responseObject, { "cURL Command": curlCommand });
215
-
216
- return responseObject;
217
- }
218
-
219
- const api = {
220
- get: async (url, payload, options) => {
221
- const URL = await selector(url);
222
-
223
- options = options ?? {};
224
-
225
- const resolvedPayload = (await payload) && resolveVariable(payload);
226
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
227
-
228
- const req = await requestMaker(payloadJSON?.headers || {});
229
-
230
- const requestStarts = performance.now();
231
-
232
- const res = await context.request.get(URL, req, options);
233
-
234
- const duration = performance.now() - requestStarts;
235
-
236
- const curlCommand = curlExtractor(
237
- res.url(),
238
- "GET",
239
- payloadJSON?.headers || {},
240
- null,
241
- null,
242
- );
243
-
244
- const response = responseMaker(payloadJSON, res, duration, curlCommand);
245
-
246
- context.response = await response;
247
- },
248
- head: async (url, options) => {
249
- const URL = await selector(url);
250
-
251
- options = options ?? {};
252
-
253
- const requestStarts = performance.now();
254
-
255
- const res = await context.request.head(URL, options);
256
-
257
- const duration = performance.now() - requestStarts;
258
-
259
- const curlCommand = curlExtractor(res.url(), "HEAD", {}, null, null);
260
-
261
- const response = responseMaker(null, res, duration, curlCommand);
262
-
263
- context.response = await response;
264
- },
265
- post: async (url, payload, requestDataType, options) => {
266
- const URL = await selector(url);
267
-
268
- options = options ?? {};
269
-
270
- const resolvedPayload = (await payload) && resolveVariable(payload);
271
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
272
-
273
- let req;
274
- let bodyForCurl = payloadJSON?.body || {};
275
-
276
- switch (requestDataType) {
277
- case "multipart":
278
- const formRequest = processForm(payloadJSON?.body || {});
279
-
280
- req = await requestMaker(
281
- payloadJSON?.headers || {},
282
- formRequest || {},
283
- requestDataType,
284
- );
285
- bodyForCurl = formRequest;
286
- break;
287
- case "xml":
288
- req = await requestMaker(
289
- payloadJSON?.headers || {},
290
- payloadJSON?.body || {},
291
- requestDataType,
292
- );
293
- bodyForCurl = payloadJSON?.body || {};
294
- break;
295
- case "urlencoded":
296
- case "application/x-www-form-urlencoded":
297
- req = await requestMaker(
298
- {
299
- ...payloadJSON?.headers,
300
- "Content-Type": "application/x-www-form-urlencoded",
301
- },
302
- payloadJSON?.body || {},
303
- requestDataType,
304
- );
305
- break;
306
- case "form":
307
- req = await requestMaker(
308
- payloadJSON?.headers || {},
309
- payloadJSON?.body || {},
310
- requestDataType,
311
- );
312
- break;
313
- default:
314
- req = await requestMaker(
315
- payloadJSON?.headers || {},
316
- payloadJSON?.body || {},
317
- );
318
- }
319
-
320
- const requestStarts = performance.now();
321
-
322
- const res = await context.request.post(URL, req, options);
323
-
324
- const duration = performance.now() - requestStarts;
325
-
326
- const curlCommand = curlExtractor(
327
- res.url(),
328
- "POST",
329
- req.headers,
330
- bodyForCurl,
331
- requestDataType,
332
- );
333
-
334
- const response = await responseMaker(
335
- payloadJSON,
336
- res,
337
- duration,
338
- curlCommand,
339
- );
340
-
341
- context.response = response;
342
- },
343
- put: async (url, payload, requestDataType, options) => {
344
- const URL = await selector(url);
345
-
346
- options = options ?? {};
347
-
348
- const resolvedPayload = (await payload) && resolveVariable(payload);
349
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
350
-
351
- let req;
352
- let bodyForCurl = payloadJSON?.body || {};
353
-
354
- switch (requestDataType) {
355
- case "multipart":
356
- const formRequest = processForm(payloadJSON?.body || {});
357
-
358
- req = await requestMaker(
359
- payloadJSON?.headers || {},
360
- formRequest || {},
361
- requestDataType,
362
- );
363
- bodyForCurl = formRequest;
364
- break;
365
- case "xml":
366
- req = await requestMaker(
367
- payloadJSON?.headers || {},
368
- payloadJSON?.body || {},
369
- requestDataType,
370
- );
371
- bodyForCurl = payloadJSON?.body || {};
372
- break;
373
- case "urlencoded":
374
- case "application/x-www-form-urlencoded":
375
- req = await requestMaker(
376
- {
377
- ...payloadJSON?.headers,
378
- "Content-Type": "application/x-www-form-urlencoded",
379
- },
380
- payloadJSON?.body || {},
381
- requestDataType,
382
- );
383
- break;
384
- case "form":
385
- req = await requestMaker(
386
- payloadJSON?.headers || {},
387
- payloadJSON?.body || {},
388
- requestDataType,
389
- );
390
- break;
391
- default:
392
- req = await requestMaker(
393
- payloadJSON?.headers || {},
394
- payloadJSON?.body || {},
395
- );
396
- }
397
-
398
- const requestStarts = performance.now();
399
-
400
- const res = await context.request.put(URL, req, options);
401
-
402
- const duration = performance.now() - requestStarts;
403
-
404
- const curlCommand = curlExtractor(
405
- res.url(),
406
- "PUT",
407
- req.headers,
408
- bodyForCurl,
409
- requestDataType,
410
- );
411
-
412
- const response = await responseMaker(
413
- payloadJSON,
414
- res,
415
- duration,
416
- curlCommand,
417
- );
418
-
419
- context.response = response;
420
- },
421
- patch: async (url, payload, requestDataType, options) => {
422
- const URL = await selector(url);
423
-
424
- options = options ?? {};
425
-
426
- const resolvedPayload = (await payload) && resolveVariable(payload);
427
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
428
-
429
- let req;
430
- let bodyForCurl = payloadJSON?.body || {};
431
-
432
- switch (requestDataType) {
433
- case "multipart":
434
- const formRequest = processForm(payloadJSON?.body || {});
435
-
436
- req = await requestMaker(
437
- payloadJSON?.headers || {},
438
- formRequest || {},
439
- requestDataType,
440
- );
441
- bodyForCurl = formRequest;
442
- break;
443
- case "xml":
444
- req = await requestMaker(
445
- payloadJSON?.headers || {},
446
- payloadJSON?.body || {},
447
- requestDataType,
448
- );
449
- bodyForCurl = payloadJSON?.body || {};
450
- break;
451
- case "urlencoded":
452
- case "application/x-www-form-urlencoded":
453
- req = await requestMaker(
454
- {
455
- ...payloadJSON?.headers,
456
- "Content-Type": "application/x-www-form-urlencoded",
457
- },
458
- payloadJSON?.body || {},
459
- requestDataType,
460
- );
461
- break;
462
- case "form":
463
- req = await requestMaker(
464
- payloadJSON?.headers || {},
465
- payloadJSON?.body || {},
466
- requestDataType,
467
- );
468
- break;
469
- default:
470
- req = await requestMaker(
471
- payloadJSON?.headers || {},
472
- payloadJSON?.body || {},
473
- );
474
- }
475
-
476
- const requestStarts = performance.now();
477
-
478
- const res = await context.request.patch(URL, req, options);
479
-
480
- const duration = performance.now() - requestStarts;
481
-
482
- const curlCommand = curlExtractor(
483
- res.url(),
484
- "PATCH",
485
- req.headers,
486
- bodyForCurl,
487
- requestDataType,
488
- );
489
-
490
- const response = await responseMaker(
491
- payloadJSON,
492
- res,
493
- duration,
494
- curlCommand,
495
- );
496
-
497
- context.response = response;
498
- },
499
- delete: async (url, payload, requestDataType, options) => {
500
- const URL = await selector(url);
501
-
502
- options = options ?? {};
503
-
504
- const resolvedPayload = (await payload) && resolveVariable(payload);
505
- const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
506
-
507
- let req;
508
- let bodyForCurl = payloadJSON?.body || {};
509
-
510
- switch (requestDataType) {
511
- case "multipart":
512
- const formRequest = processForm(payloadJSON?.body || {});
513
- req = await requestMaker(
514
- payloadJSON?.headers || {},
515
- formRequest || {},
516
- requestDataType,
517
- );
518
- bodyForCurl = formRequest;
519
- break;
520
- case "urlencoded":
521
- case "application/x-www-form-urlencoded":
522
- req = await requestMaker(
523
- {
524
- ...payloadJSON?.headers,
525
- "Content-Type": "application/x-www-form-urlencoded",
526
- },
527
- payloadJSON?.body || {},
528
- requestDataType,
529
- );
530
- break;
531
- case "form":
532
- req = await requestMaker(
533
- payloadJSON?.headers || {},
534
- payloadJSON?.body || {},
535
- requestDataType,
536
- );
537
- break;
538
- case "xml":
539
- req = await requestMaker(
540
- {
541
- ...payloadJSON?.headers,
542
- "Content-Type": "application/xml",
543
- },
544
- payloadJSON?.body || {},
545
- requestDataType,
546
- );
547
- break;
548
- default:
549
- req = await requestMaker(
550
- payloadJSON?.headers || {},
551
- payloadJSON?.body || {},
552
- );
553
- }
554
-
555
- const requestStarts = performance.now();
556
-
557
- const res = await context.request.delete(URL, req, options);
558
-
559
- const duration = performance.now() - requestStarts;
560
-
561
- const curlCommand = curlExtractor(
562
- res.url(),
563
- "DELETE",
564
- req.headers,
565
- bodyForCurl,
566
- requestDataType,
567
- );
568
-
569
- const response = responseMaker(payloadJSON, res, duration, curlCommand);
570
-
571
- context.response = await response;
572
- },
573
- vars: (variable) => {
574
- if (!variable) {
575
- return context.vars;
576
- } else {
577
- return { [variable]: context.vars[variable] };
578
- }
579
- },
580
- };
581
-
582
- module.exports = { api };
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const {
4
+ context,
5
+ selector,
6
+ resolveVariable,
7
+ moduleConfig,
8
+ normalizeCrossplatformPath
9
+ } = require("../imports/commons");
10
+
11
+ function getMimeType(filePath) {
12
+ const ext = path.extname(filePath).toLowerCase();
13
+ const mimeTypes = {
14
+ ".jpg": "image/jpeg",
15
+ ".jpeg": "image/jpeg",
16
+ ".png": "image/png",
17
+ ".gif": "image/gif",
18
+ ".pdf": "application/pdf",
19
+ ".txt": "text/plain",
20
+ ".json": "application/json",
21
+ ".xml": "application/xml",
22
+ ".zip": "application/zip",
23
+ ".doc": "application/msword",
24
+ ".docx":
25
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
26
+ ".csv": "text/csv",
27
+ };
28
+
29
+ return mimeTypes[ext] || "application/octet-stream";
30
+ }
31
+
32
+ function curlExtractor(url, method, headers, body, requestDataType) {
33
+ let curlCommand = `curl -X ${method} '${url}'`;
34
+
35
+ if (headers && Object.keys(headers).length > 0) {
36
+ for (const [key, value] of Object.entries(headers)) {
37
+ curlCommand += ` \\\n -H '${key}: ${value}'`;
38
+ }
39
+ }
40
+
41
+ if (body && Object.keys(body).length > 0) {
42
+ switch (requestDataType) {
43
+ case "multipart":
44
+ for (const [key, value] of Object.entries(body)) {
45
+ if (typeof value === "object" && value.buffer) {
46
+ curlCommand += ` \\\n -F '${key}=@${value.name}'`;
47
+ } else {
48
+ curlCommand += ` \\\n -F '${key}=${value}'`;
49
+ }
50
+ }
51
+ break;
52
+ case "xml":
53
+ curlCommand += ` \\\n -H 'Content-Type: application/xml'`;
54
+ curlCommand += ` \\\n --data-raw '${data}'`;
55
+ break;
56
+
57
+ case "urlencoded":
58
+ case "application/x-www-form-urlencoded":
59
+ const urlEncodedData = new URLSearchParams(body).toString();
60
+ curlCommand += ` \\\n --data-urlencode '${urlEncodedData}'`;
61
+ break;
62
+
63
+ case "form":
64
+ for (const [key, value] of Object.entries(body)) {
65
+ curlCommand += ` \\\n -F '${key}=${value}'`;
66
+ }
67
+ break;
68
+
69
+ default:
70
+ const hasContentType =
71
+ headers &&
72
+ Object.keys(headers).some(
73
+ (key) => key.toLowerCase() === "content-type",
74
+ );
75
+
76
+ if (!hasContentType) {
77
+ curlCommand += ` \\\n -H 'Content-Type: application/json'`;
78
+ }
79
+
80
+ curlCommand += ` \\\n --data-raw '${JSON.stringify(body)}'`;
81
+ break;
82
+ }
83
+ }
84
+
85
+ return curlCommand;
86
+ }
87
+
88
+ function processForm(requestBody) {
89
+ let formData = {};
90
+ for (const [key, value] of Object.entries(requestBody)) {
91
+ if (value === null || value === undefined) {
92
+ continue;
93
+ }
94
+
95
+ if (typeof value === "object") {
96
+ if (value.contentType) {
97
+ const content =
98
+ typeof value.data === "object"
99
+ ? JSON.stringify(value.data)
100
+ : String(value.data);
101
+
102
+ formData[key] = {
103
+ name: value.filename || key,
104
+ mimeType: value.contentType,
105
+ buffer: Buffer.from(content, "utf8"),
106
+ };
107
+ continue;
108
+ } else {
109
+ formData[key] = JSON.stringify(value);
110
+ continue;
111
+ }
112
+ }
113
+
114
+ if (typeof value === "string") {
115
+
116
+ const normalizedValue = normalizeCrossplatformPath(value);
117
+
118
+ const looksLikeFilePath =
119
+ normalizedValue.endsWith(".pdf") ||
120
+ normalizedValue.endsWith(".jpg") ||
121
+ normalizedValue.endsWith(".jpeg") ||
122
+ normalizedValue.endsWith(".png") ||
123
+ normalizedValue.endsWith(".txt") ||
124
+ normalizedValue.endsWith(".doc") ||
125
+ normalizedValue.endsWith(".docx") ||
126
+ normalizedValue.includes("/");
127
+
128
+ if (looksLikeFilePath) {
129
+ try {
130
+ const filePath = path.isAbsolute(normalizedValue)
131
+ ? normalizedValue
132
+ : path.join(moduleConfig.projectPath, normalizedValue);
133
+
134
+ if (fs.existsSync(filePath)) {
135
+ formData[key] = {
136
+ name: path.basename(filePath),
137
+ mimeType: getMimeType(filePath),
138
+ buffer: fs.readFileSync(filePath),
139
+ };
140
+ continue;
141
+ }
142
+ } catch (error) {
143
+ console.log(error);
144
+ }
145
+ }
146
+ }
147
+
148
+ formData[key] = value;
149
+ }
150
+ return formData;
151
+ }
152
+
153
+ async function requestMaker(headers, data, requestDataType) {
154
+ let request = {};
155
+
156
+ Object.assign(request, { headers: headers });
157
+
158
+ switch (requestDataType) {
159
+ case "multipart":
160
+ Object.assign(request, { multipart: data });
161
+ break;
162
+ case "xml":
163
+ Object.assign(request, {
164
+ headers: { ...headers, "Content-Type": "application/xml" },
165
+ data: data,
166
+ });
167
+ break;
168
+ case "urlencoded":
169
+ case "application/x-www-form-urlencoded":
170
+ const urlEncodedData = new URLSearchParams(data).toString();
171
+ Object.assign(request, { data: urlEncodedData });
172
+ break;
173
+ case "form":
174
+ Object.assign(request, { form: data });
175
+ break;
176
+ default:
177
+ Object.assign(request, { data: data });
178
+ }
179
+
180
+ return request;
181
+ }
182
+
183
+ async function responseMaker(request, response, duration, curlCommand) {
184
+ const responseObject = {};
185
+
186
+ response &&
187
+ Object.assign(responseObject, {
188
+ "Response Params": `URL: ${response.url()}
189
+ Response Status: ${await response.status()}
190
+ Response Time: ${Math.round(duration)} ms`,
191
+ });
192
+
193
+ request?.headers &&
194
+ Object.assign(responseObject, { "Request Headers": await request.headers });
195
+
196
+ request?.body &&
197
+ Object.assign(responseObject, { "Request Body": await request.body });
198
+
199
+ response && Object.assign(responseObject, { Response: await response });
200
+
201
+ response &&
202
+ Object.assign(responseObject, {
203
+ "Response Headers": await response.headers(),
204
+ });
205
+
206
+ if (response) {
207
+ try {
208
+ Object.assign(responseObject, { "Response Body": await response.json() });
209
+ } catch (e) {
210
+ Object.assign(responseObject, { "Response Body": await response.text() });
211
+ }
212
+ }
213
+
214
+ curlCommand && Object.assign(responseObject, { "cURL Command": curlCommand });
215
+
216
+ return responseObject;
217
+ }
218
+
219
+ const api = {
220
+ get: async (url, payload, options) => {
221
+ const URL = await selector(url);
222
+
223
+ options = options ?? {};
224
+
225
+ const resolvedPayload = (await payload) && resolveVariable(payload);
226
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
227
+
228
+ const req = await requestMaker(payloadJSON?.headers || {});
229
+
230
+ const requestStarts = performance.now();
231
+
232
+ const res = await context.request.get(URL, req, options);
233
+
234
+ const duration = performance.now() - requestStarts;
235
+
236
+ const curlCommand = curlExtractor(
237
+ res.url(),
238
+ "GET",
239
+ payloadJSON?.headers || {},
240
+ null,
241
+ null,
242
+ );
243
+
244
+ const response = responseMaker(payloadJSON, res, duration, curlCommand);
245
+
246
+ context.response = await response;
247
+ },
248
+ head: async (url, options) => {
249
+ const URL = await selector(url);
250
+
251
+ options = options ?? {};
252
+
253
+ const requestStarts = performance.now();
254
+
255
+ const res = await context.request.head(URL, options);
256
+
257
+ const duration = performance.now() - requestStarts;
258
+
259
+ const curlCommand = curlExtractor(res.url(), "HEAD", {}, null, null);
260
+
261
+ const response = responseMaker(null, res, duration, curlCommand);
262
+
263
+ context.response = await response;
264
+ },
265
+ post: async (url, payload, requestDataType, options) => {
266
+ const URL = await selector(url);
267
+
268
+ options = options ?? {};
269
+
270
+ const resolvedPayload = (await payload) && resolveVariable(payload);
271
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
272
+
273
+ let req;
274
+ let bodyForCurl = payloadJSON?.body || {};
275
+
276
+ switch (requestDataType) {
277
+ case "multipart":
278
+ const formRequest = processForm(payloadJSON?.body || {});
279
+
280
+ req = await requestMaker(
281
+ payloadJSON?.headers || {},
282
+ formRequest || {},
283
+ requestDataType,
284
+ );
285
+ bodyForCurl = formRequest;
286
+ break;
287
+ case "xml":
288
+ req = await requestMaker(
289
+ payloadJSON?.headers || {},
290
+ payloadJSON?.body || {},
291
+ requestDataType,
292
+ );
293
+ bodyForCurl = payloadJSON?.body || {};
294
+ break;
295
+ case "urlencoded":
296
+ case "application/x-www-form-urlencoded":
297
+ req = await requestMaker(
298
+ {
299
+ ...payloadJSON?.headers,
300
+ "Content-Type": "application/x-www-form-urlencoded",
301
+ },
302
+ payloadJSON?.body || {},
303
+ requestDataType,
304
+ );
305
+ break;
306
+ case "form":
307
+ req = await requestMaker(
308
+ payloadJSON?.headers || {},
309
+ payloadJSON?.body || {},
310
+ requestDataType,
311
+ );
312
+ break;
313
+ default:
314
+ req = await requestMaker(
315
+ payloadJSON?.headers || {},
316
+ payloadJSON?.body || {},
317
+ );
318
+ }
319
+
320
+ const requestStarts = performance.now();
321
+
322
+ const res = await context.request.post(URL, req, options);
323
+
324
+ const duration = performance.now() - requestStarts;
325
+
326
+ const curlCommand = curlExtractor(
327
+ res.url(),
328
+ "POST",
329
+ req.headers,
330
+ bodyForCurl,
331
+ requestDataType,
332
+ );
333
+
334
+ const response = await responseMaker(
335
+ payloadJSON,
336
+ res,
337
+ duration,
338
+ curlCommand,
339
+ );
340
+
341
+ context.response = response;
342
+ },
343
+ put: async (url, payload, requestDataType, options) => {
344
+ const URL = await selector(url);
345
+
346
+ options = options ?? {};
347
+
348
+ const resolvedPayload = (await payload) && resolveVariable(payload);
349
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
350
+
351
+ let req;
352
+ let bodyForCurl = payloadJSON?.body || {};
353
+
354
+ switch (requestDataType) {
355
+ case "multipart":
356
+ const formRequest = processForm(payloadJSON?.body || {});
357
+
358
+ req = await requestMaker(
359
+ payloadJSON?.headers || {},
360
+ formRequest || {},
361
+ requestDataType,
362
+ );
363
+ bodyForCurl = formRequest;
364
+ break;
365
+ case "xml":
366
+ req = await requestMaker(
367
+ payloadJSON?.headers || {},
368
+ payloadJSON?.body || {},
369
+ requestDataType,
370
+ );
371
+ bodyForCurl = payloadJSON?.body || {};
372
+ break;
373
+ case "urlencoded":
374
+ case "application/x-www-form-urlencoded":
375
+ req = await requestMaker(
376
+ {
377
+ ...payloadJSON?.headers,
378
+ "Content-Type": "application/x-www-form-urlencoded",
379
+ },
380
+ payloadJSON?.body || {},
381
+ requestDataType,
382
+ );
383
+ break;
384
+ case "form":
385
+ req = await requestMaker(
386
+ payloadJSON?.headers || {},
387
+ payloadJSON?.body || {},
388
+ requestDataType,
389
+ );
390
+ break;
391
+ default:
392
+ req = await requestMaker(
393
+ payloadJSON?.headers || {},
394
+ payloadJSON?.body || {},
395
+ );
396
+ }
397
+
398
+ const requestStarts = performance.now();
399
+
400
+ const res = await context.request.put(URL, req, options);
401
+
402
+ const duration = performance.now() - requestStarts;
403
+
404
+ const curlCommand = curlExtractor(
405
+ res.url(),
406
+ "PUT",
407
+ req.headers,
408
+ bodyForCurl,
409
+ requestDataType,
410
+ );
411
+
412
+ const response = await responseMaker(
413
+ payloadJSON,
414
+ res,
415
+ duration,
416
+ curlCommand,
417
+ );
418
+
419
+ context.response = response;
420
+ },
421
+ patch: async (url, payload, requestDataType, options) => {
422
+ const URL = await selector(url);
423
+
424
+ options = options ?? {};
425
+
426
+ const resolvedPayload = (await payload) && resolveVariable(payload);
427
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
428
+
429
+ let req;
430
+ let bodyForCurl = payloadJSON?.body || {};
431
+
432
+ switch (requestDataType) {
433
+ case "multipart":
434
+ const formRequest = processForm(payloadJSON?.body || {});
435
+
436
+ req = await requestMaker(
437
+ payloadJSON?.headers || {},
438
+ formRequest || {},
439
+ requestDataType,
440
+ );
441
+ bodyForCurl = formRequest;
442
+ break;
443
+ case "xml":
444
+ req = await requestMaker(
445
+ payloadJSON?.headers || {},
446
+ payloadJSON?.body || {},
447
+ requestDataType,
448
+ );
449
+ bodyForCurl = payloadJSON?.body || {};
450
+ break;
451
+ case "urlencoded":
452
+ case "application/x-www-form-urlencoded":
453
+ req = await requestMaker(
454
+ {
455
+ ...payloadJSON?.headers,
456
+ "Content-Type": "application/x-www-form-urlencoded",
457
+ },
458
+ payloadJSON?.body || {},
459
+ requestDataType,
460
+ );
461
+ break;
462
+ case "form":
463
+ req = await requestMaker(
464
+ payloadJSON?.headers || {},
465
+ payloadJSON?.body || {},
466
+ requestDataType,
467
+ );
468
+ break;
469
+ default:
470
+ req = await requestMaker(
471
+ payloadJSON?.headers || {},
472
+ payloadJSON?.body || {},
473
+ );
474
+ }
475
+
476
+ const requestStarts = performance.now();
477
+
478
+ const res = await context.request.patch(URL, req, options);
479
+
480
+ const duration = performance.now() - requestStarts;
481
+
482
+ const curlCommand = curlExtractor(
483
+ res.url(),
484
+ "PATCH",
485
+ req.headers,
486
+ bodyForCurl,
487
+ requestDataType,
488
+ );
489
+
490
+ const response = await responseMaker(
491
+ payloadJSON,
492
+ res,
493
+ duration,
494
+ curlCommand,
495
+ );
496
+
497
+ context.response = response;
498
+ },
499
+ delete: async (url, payload, requestDataType, options) => {
500
+ const URL = await selector(url);
501
+
502
+ options = options ?? {};
503
+
504
+ const resolvedPayload = (await payload) && resolveVariable(payload);
505
+ const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
506
+
507
+ let req;
508
+ let bodyForCurl = payloadJSON?.body || {};
509
+
510
+ switch (requestDataType) {
511
+ case "multipart":
512
+ const formRequest = processForm(payloadJSON?.body || {});
513
+ req = await requestMaker(
514
+ payloadJSON?.headers || {},
515
+ formRequest || {},
516
+ requestDataType,
517
+ );
518
+ bodyForCurl = formRequest;
519
+ break;
520
+ case "urlencoded":
521
+ case "application/x-www-form-urlencoded":
522
+ req = await requestMaker(
523
+ {
524
+ ...payloadJSON?.headers,
525
+ "Content-Type": "application/x-www-form-urlencoded",
526
+ },
527
+ payloadJSON?.body || {},
528
+ requestDataType,
529
+ );
530
+ break;
531
+ case "form":
532
+ req = await requestMaker(
533
+ payloadJSON?.headers || {},
534
+ payloadJSON?.body || {},
535
+ requestDataType,
536
+ );
537
+ break;
538
+ case "xml":
539
+ req = await requestMaker(
540
+ {
541
+ ...payloadJSON?.headers,
542
+ "Content-Type": "application/xml",
543
+ },
544
+ payloadJSON?.body || {},
545
+ requestDataType,
546
+ );
547
+ break;
548
+ default:
549
+ req = await requestMaker(
550
+ payloadJSON?.headers || {},
551
+ payloadJSON?.body || {},
552
+ );
553
+ }
554
+
555
+ const requestStarts = performance.now();
556
+
557
+ const res = await context.request.delete(URL, req, options);
558
+
559
+ const duration = performance.now() - requestStarts;
560
+
561
+ const curlCommand = curlExtractor(
562
+ res.url(),
563
+ "DELETE",
564
+ req.headers,
565
+ bodyForCurl,
566
+ requestDataType,
567
+ );
568
+
569
+ const response = responseMaker(payloadJSON, res, duration, curlCommand);
570
+
571
+ context.response = await response;
572
+ },
573
+ vars: (variable) => {
574
+ if (!variable) {
575
+ return context.vars;
576
+ } else {
577
+ return { [variable]: context.vars[variable] };
578
+ }
579
+ },
580
+ };
581
+
582
+ module.exports = { api };