artes 1.7.4 → 1.7.6

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