artes 1.2.17 → 1.2.18
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.
- package/README.md +629 -629
- package/cucumber.config.js +171 -171
- package/docs/functionDefinitions.md +2401 -2401
- package/docs/stepDefinitions.md +391 -391
- package/executer.js +161 -161
- package/index.js +48 -48
- package/package.json +52 -51
- package/src/helper/contextManager/browserManager.js +63 -63
- package/src/helper/contextManager/requestManager.js +23 -23
- package/src/helper/controller/elementController.js +182 -182
- package/src/helper/controller/pomCollector.js +25 -25
- package/src/helper/executers/cleaner.js +19 -19
- package/src/helper/executers/exporter.js +15 -15
- package/src/helper/executers/helper.js +95 -95
- package/src/helper/executers/projectCreator.js +198 -198
- package/src/helper/executers/reportGenerator.js +58 -58
- package/src/helper/executers/testRunner.js +30 -30
- package/src/helper/executers/versionChecker.js +31 -31
- package/src/helper/imports/commons.js +56 -56
- package/src/helper/stepFunctions/APIActions.js +362 -362
- package/src/helper/stepFunctions/assertions.js +523 -523
- package/src/helper/stepFunctions/browserActions.js +22 -22
- package/src/helper/stepFunctions/elementInteractions.js +38 -38
- package/src/helper/stepFunctions/exporter.js +19 -19
- package/src/helper/stepFunctions/frameActions.js +50 -50
- package/src/helper/stepFunctions/keyboardActions.js +41 -41
- package/src/helper/stepFunctions/mouseActions.js +145 -145
- package/src/helper/stepFunctions/pageActions.js +27 -27
- package/src/hooks/context.js +15 -15
- package/src/hooks/hooks.js +257 -257
- package/src/stepDefinitions/API.steps.js +299 -299
- package/src/stepDefinitions/assertions.steps.js +861 -861
- package/src/stepDefinitions/browser.steps.js +7 -7
- package/src/stepDefinitions/frameActions.steps.js +76 -76
- package/src/stepDefinitions/keyboardActions.steps.js +226 -226
- package/src/stepDefinitions/mouseActions.steps.js +275 -275
- package/src/stepDefinitions/page.steps.js +71 -71
- package/src/stepDefinitions/random.steps.js +158 -158
|
@@ -1,363 +1,363 @@
|
|
|
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 processForm(requestBody) {
|
|
32
|
-
let formData = {};
|
|
33
|
-
for (const [key, value] of Object.entries(requestBody)) {
|
|
34
|
-
|
|
35
|
-
if (value === null || value === undefined) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (typeof value === "object") {
|
|
40
|
-
if (value.contentType) {
|
|
41
|
-
const content =
|
|
42
|
-
typeof value.data === "object"
|
|
43
|
-
? JSON.stringify(value.data)
|
|
44
|
-
: String(value.data);
|
|
45
|
-
|
|
46
|
-
formData[key] = {
|
|
47
|
-
name: value.filename || key,
|
|
48
|
-
mimeType: value.contentType,
|
|
49
|
-
buffer: Buffer.from(content, "utf8"),
|
|
50
|
-
};
|
|
51
|
-
continue;
|
|
52
|
-
} else {
|
|
53
|
-
formData[key] = JSON.stringify(value);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
typeof value === "string" &&
|
|
60
|
-
(value.endsWith(".pdf") ||
|
|
61
|
-
value.endsWith(".jpg") ||
|
|
62
|
-
value.endsWith(".png") ||
|
|
63
|
-
value.endsWith(".txt") ||
|
|
64
|
-
value.endsWith(".doc") ||
|
|
65
|
-
value.endsWith(".docx") ||
|
|
66
|
-
value.includes("/"))
|
|
67
|
-
) {
|
|
68
|
-
try {
|
|
69
|
-
const filePath = path.join(moduleConfig.projectPath, value);
|
|
70
|
-
if (fs.existsSync(filePath)) {
|
|
71
|
-
formData[key] = {
|
|
72
|
-
name: path.basename(filePath),
|
|
73
|
-
mimeType: getMimeType(filePath),
|
|
74
|
-
buffer: fs.readFileSync(filePath),
|
|
75
|
-
};
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.log(error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
formData[key] = value;
|
|
84
|
-
}
|
|
85
|
-
return formData;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function requestMaker(headers, data, requestDataType) {
|
|
89
|
-
let request = {};
|
|
90
|
-
|
|
91
|
-
Object.assign(request, { headers: headers });
|
|
92
|
-
|
|
93
|
-
switch (requestDataType) {
|
|
94
|
-
case "multipart":
|
|
95
|
-
Object.assign(request, { multipart: data });
|
|
96
|
-
break;
|
|
97
|
-
case "urlencoded":
|
|
98
|
-
case "application/x-www-form-urlencoded":
|
|
99
|
-
const urlEncodedData = new URLSearchParams(data).toString();
|
|
100
|
-
Object.assign(request, { data: urlEncodedData });
|
|
101
|
-
break;
|
|
102
|
-
case "form":
|
|
103
|
-
Object.assign(request, { form: data });
|
|
104
|
-
break;
|
|
105
|
-
default:
|
|
106
|
-
Object.assign(request, { data: data });
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return request;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async function responseMaker(request, response, duration) {
|
|
113
|
-
const responseObject = {};
|
|
114
|
-
|
|
115
|
-
response &&
|
|
116
|
-
Object.assign(responseObject, {
|
|
117
|
-
"Response Params": `URL: ${response.url()}
|
|
118
|
-
Response Status: ${await response.status()}
|
|
119
|
-
Response Time: ${Math.round(duration)} ms`,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
request?.headers &&
|
|
123
|
-
Object.assign(responseObject, { "Request Headers": await request.headers });
|
|
124
|
-
|
|
125
|
-
request?.body &&
|
|
126
|
-
Object.assign(responseObject, { "Request Body": await request.body });
|
|
127
|
-
|
|
128
|
-
response && Object.assign(responseObject, { Response: await response });
|
|
129
|
-
|
|
130
|
-
response &&
|
|
131
|
-
Object.assign(responseObject, {
|
|
132
|
-
"Response Headers": await response.headers(),
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
if (response) {
|
|
136
|
-
try {
|
|
137
|
-
Object.assign(responseObject, { "Response Body": await response.json() });
|
|
138
|
-
} catch (e) {
|
|
139
|
-
Object.assign(responseObject, { "Response Body": await response.text() });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return responseObject;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const api = {
|
|
147
|
-
get: async (url, payload) => {
|
|
148
|
-
const URL = await selector(url);
|
|
149
|
-
|
|
150
|
-
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
151
|
-
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
152
|
-
|
|
153
|
-
const req = await requestMaker(payloadJSON?.headers || {});
|
|
154
|
-
|
|
155
|
-
const requestStarts = performance.now();
|
|
156
|
-
|
|
157
|
-
const res = await context.request.get(URL, req);
|
|
158
|
-
|
|
159
|
-
const duration = performance.now() - requestStarts;
|
|
160
|
-
|
|
161
|
-
const response = responseMaker(payloadJSON, res, duration);
|
|
162
|
-
|
|
163
|
-
context.response = await response;
|
|
164
|
-
},
|
|
165
|
-
head: async (url) => {
|
|
166
|
-
const URL = await selector(url);
|
|
167
|
-
|
|
168
|
-
const requestStarts = performance.now();
|
|
169
|
-
|
|
170
|
-
const res = await context.request.head(URL);
|
|
171
|
-
|
|
172
|
-
const duration = performance.now() - requestStarts;
|
|
173
|
-
|
|
174
|
-
const response = responseMaker(payloadJSON, res, duration);
|
|
175
|
-
|
|
176
|
-
context.response = await response;
|
|
177
|
-
},
|
|
178
|
-
post: async (url, payload, requestDataType) => {
|
|
179
|
-
const URL = await selector(url);
|
|
180
|
-
|
|
181
|
-
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
182
|
-
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
183
|
-
|
|
184
|
-
let req;
|
|
185
|
-
|
|
186
|
-
switch (requestDataType) {
|
|
187
|
-
case "multipart":
|
|
188
|
-
const formRequest = processForm(payloadJSON?.body || {});
|
|
189
|
-
|
|
190
|
-
req = await requestMaker(
|
|
191
|
-
payloadJSON?.headers || {},
|
|
192
|
-
formRequest || {},
|
|
193
|
-
requestDataType,
|
|
194
|
-
);
|
|
195
|
-
break;
|
|
196
|
-
case "urlencoded":
|
|
197
|
-
case "application/x-www-form-urlencoded":
|
|
198
|
-
req = await requestMaker(
|
|
199
|
-
{
|
|
200
|
-
...payloadJSON?.headers,
|
|
201
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
202
|
-
},
|
|
203
|
-
payloadJSON?.body || {},
|
|
204
|
-
requestDataType,
|
|
205
|
-
);
|
|
206
|
-
break;
|
|
207
|
-
case "form":
|
|
208
|
-
req = await requestMaker(
|
|
209
|
-
payloadJSON?.headers || {},
|
|
210
|
-
payloadJSON?.body || {},
|
|
211
|
-
requestDataType,
|
|
212
|
-
);
|
|
213
|
-
break;
|
|
214
|
-
default:
|
|
215
|
-
req = await requestMaker(
|
|
216
|
-
payloadJSON?.headers || {},
|
|
217
|
-
payloadJSON?.body || {},
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const requestStarts = performance.now();
|
|
222
|
-
|
|
223
|
-
const res = await context.request.post(URL, req);
|
|
224
|
-
|
|
225
|
-
const duration = performance.now() - requestStarts;
|
|
226
|
-
|
|
227
|
-
const response = await responseMaker(payloadJSON, res, duration);
|
|
228
|
-
|
|
229
|
-
context.response = response;
|
|
230
|
-
},
|
|
231
|
-
put: async (url, payload, requestDataType) => {
|
|
232
|
-
const URL = await selector(url);
|
|
233
|
-
|
|
234
|
-
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
235
|
-
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
236
|
-
|
|
237
|
-
let req;
|
|
238
|
-
|
|
239
|
-
switch (requestDataType) {
|
|
240
|
-
case "multipart":
|
|
241
|
-
const formRequest = processForm(payloadJSON?.body || {});
|
|
242
|
-
|
|
243
|
-
req = await requestMaker(
|
|
244
|
-
payloadJSON?.headers || {},
|
|
245
|
-
formRequest || {},
|
|
246
|
-
requestDataType,
|
|
247
|
-
);
|
|
248
|
-
break;
|
|
249
|
-
case "urlencoded":
|
|
250
|
-
case "application/x-www-form-urlencoded":
|
|
251
|
-
req = await requestMaker(
|
|
252
|
-
{
|
|
253
|
-
...payloadJSON?.headers,
|
|
254
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
255
|
-
},
|
|
256
|
-
payloadJSON?.body || {},
|
|
257
|
-
requestDataType,
|
|
258
|
-
);
|
|
259
|
-
break;
|
|
260
|
-
case "form":
|
|
261
|
-
req = await requestMaker(
|
|
262
|
-
payloadJSON?.headers || {},
|
|
263
|
-
payloadJSON?.body || {},
|
|
264
|
-
requestDataType,
|
|
265
|
-
);
|
|
266
|
-
break;
|
|
267
|
-
default:
|
|
268
|
-
req = await requestMaker(
|
|
269
|
-
payloadJSON?.headers || {},
|
|
270
|
-
payloadJSON?.body || {},
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const requestStarts = performance.now();
|
|
275
|
-
|
|
276
|
-
const res = await context.request.put(URL, req);
|
|
277
|
-
|
|
278
|
-
const duration = performance.now() - requestStarts;
|
|
279
|
-
|
|
280
|
-
const response = await responseMaker(payloadJSON, res, duration);
|
|
281
|
-
|
|
282
|
-
context.response = response;
|
|
283
|
-
},
|
|
284
|
-
patch: async (url, payload, requestDataType) => {
|
|
285
|
-
const URL = await selector(url);
|
|
286
|
-
|
|
287
|
-
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
288
|
-
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
289
|
-
|
|
290
|
-
let req;
|
|
291
|
-
|
|
292
|
-
switch (requestDataType) {
|
|
293
|
-
case "multipart":
|
|
294
|
-
const formRequest = processForm(payloadJSON?.body || {});
|
|
295
|
-
|
|
296
|
-
req = await requestMaker(
|
|
297
|
-
payloadJSON?.headers || {},
|
|
298
|
-
formRequest || {},
|
|
299
|
-
requestDataType,
|
|
300
|
-
);
|
|
301
|
-
break;
|
|
302
|
-
case "urlencoded":
|
|
303
|
-
case "application/x-www-form-urlencoded":
|
|
304
|
-
req = await requestMaker(
|
|
305
|
-
{
|
|
306
|
-
...payloadJSON?.headers,
|
|
307
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
308
|
-
},
|
|
309
|
-
payloadJSON?.body || {},
|
|
310
|
-
requestDataType,
|
|
311
|
-
);
|
|
312
|
-
break;
|
|
313
|
-
case "form":
|
|
314
|
-
req = await requestMaker(
|
|
315
|
-
payloadJSON?.headers || {},
|
|
316
|
-
payloadJSON?.body || {},
|
|
317
|
-
requestDataType,
|
|
318
|
-
);
|
|
319
|
-
break;
|
|
320
|
-
default:
|
|
321
|
-
req = await requestMaker(
|
|
322
|
-
payloadJSON?.headers || {},
|
|
323
|
-
payloadJSON?.body || {},
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const requestStarts = performance.now();
|
|
328
|
-
|
|
329
|
-
const res = await context.request.patch(URL, req);
|
|
330
|
-
|
|
331
|
-
const duration = performance.now() - requestStarts;
|
|
332
|
-
|
|
333
|
-
const response = await responseMaker(payloadJSON, res, duration);
|
|
334
|
-
|
|
335
|
-
context.response = response;
|
|
336
|
-
},
|
|
337
|
-
delete: async (url, payload) => {
|
|
338
|
-
const URL = await selector(url);
|
|
339
|
-
|
|
340
|
-
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
341
|
-
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
342
|
-
|
|
343
|
-
const req = await requestMaker(
|
|
344
|
-
payloadJSON?.headers || {},
|
|
345
|
-
payloadJSON?.body || {},
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
const requestStarts = performance.now();
|
|
349
|
-
|
|
350
|
-
const res = await context.request.delete(URL, req);
|
|
351
|
-
|
|
352
|
-
const duration = performance.now() - requestStarts;
|
|
353
|
-
|
|
354
|
-
const response = responseMaker(payloadJSON, res, duration);
|
|
355
|
-
|
|
356
|
-
context.response = await response;
|
|
357
|
-
},
|
|
358
|
-
vars: () => {
|
|
359
|
-
return context.vars;
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
|
|
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 processForm(requestBody) {
|
|
32
|
+
let formData = {};
|
|
33
|
+
for (const [key, value] of Object.entries(requestBody)) {
|
|
34
|
+
|
|
35
|
+
if (value === null || value === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof value === "object") {
|
|
40
|
+
if (value.contentType) {
|
|
41
|
+
const content =
|
|
42
|
+
typeof value.data === "object"
|
|
43
|
+
? JSON.stringify(value.data)
|
|
44
|
+
: String(value.data);
|
|
45
|
+
|
|
46
|
+
formData[key] = {
|
|
47
|
+
name: value.filename || key,
|
|
48
|
+
mimeType: value.contentType,
|
|
49
|
+
buffer: Buffer.from(content, "utf8"),
|
|
50
|
+
};
|
|
51
|
+
continue;
|
|
52
|
+
} else {
|
|
53
|
+
formData[key] = JSON.stringify(value);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
typeof value === "string" &&
|
|
60
|
+
(value.endsWith(".pdf") ||
|
|
61
|
+
value.endsWith(".jpg") ||
|
|
62
|
+
value.endsWith(".png") ||
|
|
63
|
+
value.endsWith(".txt") ||
|
|
64
|
+
value.endsWith(".doc") ||
|
|
65
|
+
value.endsWith(".docx") ||
|
|
66
|
+
value.includes("/"))
|
|
67
|
+
) {
|
|
68
|
+
try {
|
|
69
|
+
const filePath = path.join(moduleConfig.projectPath, value);
|
|
70
|
+
if (fs.existsSync(filePath)) {
|
|
71
|
+
formData[key] = {
|
|
72
|
+
name: path.basename(filePath),
|
|
73
|
+
mimeType: getMimeType(filePath),
|
|
74
|
+
buffer: fs.readFileSync(filePath),
|
|
75
|
+
};
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.log(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
formData[key] = value;
|
|
84
|
+
}
|
|
85
|
+
return formData;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function requestMaker(headers, data, requestDataType) {
|
|
89
|
+
let request = {};
|
|
90
|
+
|
|
91
|
+
Object.assign(request, { headers: headers });
|
|
92
|
+
|
|
93
|
+
switch (requestDataType) {
|
|
94
|
+
case "multipart":
|
|
95
|
+
Object.assign(request, { multipart: data });
|
|
96
|
+
break;
|
|
97
|
+
case "urlencoded":
|
|
98
|
+
case "application/x-www-form-urlencoded":
|
|
99
|
+
const urlEncodedData = new URLSearchParams(data).toString();
|
|
100
|
+
Object.assign(request, { data: urlEncodedData });
|
|
101
|
+
break;
|
|
102
|
+
case "form":
|
|
103
|
+
Object.assign(request, { form: data });
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
Object.assign(request, { data: data });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return request;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function responseMaker(request, response, duration) {
|
|
113
|
+
const responseObject = {};
|
|
114
|
+
|
|
115
|
+
response &&
|
|
116
|
+
Object.assign(responseObject, {
|
|
117
|
+
"Response Params": `URL: ${response.url()}
|
|
118
|
+
Response Status: ${await response.status()}
|
|
119
|
+
Response Time: ${Math.round(duration)} ms`,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
request?.headers &&
|
|
123
|
+
Object.assign(responseObject, { "Request Headers": await request.headers });
|
|
124
|
+
|
|
125
|
+
request?.body &&
|
|
126
|
+
Object.assign(responseObject, { "Request Body": await request.body });
|
|
127
|
+
|
|
128
|
+
response && Object.assign(responseObject, { Response: await response });
|
|
129
|
+
|
|
130
|
+
response &&
|
|
131
|
+
Object.assign(responseObject, {
|
|
132
|
+
"Response Headers": await response.headers(),
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (response) {
|
|
136
|
+
try {
|
|
137
|
+
Object.assign(responseObject, { "Response Body": await response.json() });
|
|
138
|
+
} catch (e) {
|
|
139
|
+
Object.assign(responseObject, { "Response Body": await response.text() });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return responseObject;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const api = {
|
|
147
|
+
get: async (url, payload) => {
|
|
148
|
+
const URL = await selector(url);
|
|
149
|
+
|
|
150
|
+
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
151
|
+
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
152
|
+
|
|
153
|
+
const req = await requestMaker(payloadJSON?.headers || {});
|
|
154
|
+
|
|
155
|
+
const requestStarts = performance.now();
|
|
156
|
+
|
|
157
|
+
const res = await context.request.get(URL, req);
|
|
158
|
+
|
|
159
|
+
const duration = performance.now() - requestStarts;
|
|
160
|
+
|
|
161
|
+
const response = responseMaker(payloadJSON, res, duration);
|
|
162
|
+
|
|
163
|
+
context.response = await response;
|
|
164
|
+
},
|
|
165
|
+
head: async (url) => {
|
|
166
|
+
const URL = await selector(url);
|
|
167
|
+
|
|
168
|
+
const requestStarts = performance.now();
|
|
169
|
+
|
|
170
|
+
const res = await context.request.head(URL);
|
|
171
|
+
|
|
172
|
+
const duration = performance.now() - requestStarts;
|
|
173
|
+
|
|
174
|
+
const response = responseMaker(payloadJSON, res, duration);
|
|
175
|
+
|
|
176
|
+
context.response = await response;
|
|
177
|
+
},
|
|
178
|
+
post: async (url, payload, requestDataType) => {
|
|
179
|
+
const URL = await selector(url);
|
|
180
|
+
|
|
181
|
+
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
182
|
+
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
183
|
+
|
|
184
|
+
let req;
|
|
185
|
+
|
|
186
|
+
switch (requestDataType) {
|
|
187
|
+
case "multipart":
|
|
188
|
+
const formRequest = processForm(payloadJSON?.body || {});
|
|
189
|
+
|
|
190
|
+
req = await requestMaker(
|
|
191
|
+
payloadJSON?.headers || {},
|
|
192
|
+
formRequest || {},
|
|
193
|
+
requestDataType,
|
|
194
|
+
);
|
|
195
|
+
break;
|
|
196
|
+
case "urlencoded":
|
|
197
|
+
case "application/x-www-form-urlencoded":
|
|
198
|
+
req = await requestMaker(
|
|
199
|
+
{
|
|
200
|
+
...payloadJSON?.headers,
|
|
201
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
202
|
+
},
|
|
203
|
+
payloadJSON?.body || {},
|
|
204
|
+
requestDataType,
|
|
205
|
+
);
|
|
206
|
+
break;
|
|
207
|
+
case "form":
|
|
208
|
+
req = await requestMaker(
|
|
209
|
+
payloadJSON?.headers || {},
|
|
210
|
+
payloadJSON?.body || {},
|
|
211
|
+
requestDataType,
|
|
212
|
+
);
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
req = await requestMaker(
|
|
216
|
+
payloadJSON?.headers || {},
|
|
217
|
+
payloadJSON?.body || {},
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const requestStarts = performance.now();
|
|
222
|
+
|
|
223
|
+
const res = await context.request.post(URL, req);
|
|
224
|
+
|
|
225
|
+
const duration = performance.now() - requestStarts;
|
|
226
|
+
|
|
227
|
+
const response = await responseMaker(payloadJSON, res, duration);
|
|
228
|
+
|
|
229
|
+
context.response = response;
|
|
230
|
+
},
|
|
231
|
+
put: async (url, payload, requestDataType) => {
|
|
232
|
+
const URL = await selector(url);
|
|
233
|
+
|
|
234
|
+
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
235
|
+
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
236
|
+
|
|
237
|
+
let req;
|
|
238
|
+
|
|
239
|
+
switch (requestDataType) {
|
|
240
|
+
case "multipart":
|
|
241
|
+
const formRequest = processForm(payloadJSON?.body || {});
|
|
242
|
+
|
|
243
|
+
req = await requestMaker(
|
|
244
|
+
payloadJSON?.headers || {},
|
|
245
|
+
formRequest || {},
|
|
246
|
+
requestDataType,
|
|
247
|
+
);
|
|
248
|
+
break;
|
|
249
|
+
case "urlencoded":
|
|
250
|
+
case "application/x-www-form-urlencoded":
|
|
251
|
+
req = await requestMaker(
|
|
252
|
+
{
|
|
253
|
+
...payloadJSON?.headers,
|
|
254
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
255
|
+
},
|
|
256
|
+
payloadJSON?.body || {},
|
|
257
|
+
requestDataType,
|
|
258
|
+
);
|
|
259
|
+
break;
|
|
260
|
+
case "form":
|
|
261
|
+
req = await requestMaker(
|
|
262
|
+
payloadJSON?.headers || {},
|
|
263
|
+
payloadJSON?.body || {},
|
|
264
|
+
requestDataType,
|
|
265
|
+
);
|
|
266
|
+
break;
|
|
267
|
+
default:
|
|
268
|
+
req = await requestMaker(
|
|
269
|
+
payloadJSON?.headers || {},
|
|
270
|
+
payloadJSON?.body || {},
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const requestStarts = performance.now();
|
|
275
|
+
|
|
276
|
+
const res = await context.request.put(URL, req);
|
|
277
|
+
|
|
278
|
+
const duration = performance.now() - requestStarts;
|
|
279
|
+
|
|
280
|
+
const response = await responseMaker(payloadJSON, res, duration);
|
|
281
|
+
|
|
282
|
+
context.response = response;
|
|
283
|
+
},
|
|
284
|
+
patch: async (url, payload, requestDataType) => {
|
|
285
|
+
const URL = await selector(url);
|
|
286
|
+
|
|
287
|
+
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
288
|
+
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
289
|
+
|
|
290
|
+
let req;
|
|
291
|
+
|
|
292
|
+
switch (requestDataType) {
|
|
293
|
+
case "multipart":
|
|
294
|
+
const formRequest = processForm(payloadJSON?.body || {});
|
|
295
|
+
|
|
296
|
+
req = await requestMaker(
|
|
297
|
+
payloadJSON?.headers || {},
|
|
298
|
+
formRequest || {},
|
|
299
|
+
requestDataType,
|
|
300
|
+
);
|
|
301
|
+
break;
|
|
302
|
+
case "urlencoded":
|
|
303
|
+
case "application/x-www-form-urlencoded":
|
|
304
|
+
req = await requestMaker(
|
|
305
|
+
{
|
|
306
|
+
...payloadJSON?.headers,
|
|
307
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
308
|
+
},
|
|
309
|
+
payloadJSON?.body || {},
|
|
310
|
+
requestDataType,
|
|
311
|
+
);
|
|
312
|
+
break;
|
|
313
|
+
case "form":
|
|
314
|
+
req = await requestMaker(
|
|
315
|
+
payloadJSON?.headers || {},
|
|
316
|
+
payloadJSON?.body || {},
|
|
317
|
+
requestDataType,
|
|
318
|
+
);
|
|
319
|
+
break;
|
|
320
|
+
default:
|
|
321
|
+
req = await requestMaker(
|
|
322
|
+
payloadJSON?.headers || {},
|
|
323
|
+
payloadJSON?.body || {},
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const requestStarts = performance.now();
|
|
328
|
+
|
|
329
|
+
const res = await context.request.patch(URL, req);
|
|
330
|
+
|
|
331
|
+
const duration = performance.now() - requestStarts;
|
|
332
|
+
|
|
333
|
+
const response = await responseMaker(payloadJSON, res, duration);
|
|
334
|
+
|
|
335
|
+
context.response = response;
|
|
336
|
+
},
|
|
337
|
+
delete: async (url, payload) => {
|
|
338
|
+
const URL = await selector(url);
|
|
339
|
+
|
|
340
|
+
const resolvedPayload = (await payload) && resolveVariable(payload);
|
|
341
|
+
const payloadJSON = (await resolvedPayload) && JSON.parse(resolvedPayload);
|
|
342
|
+
|
|
343
|
+
const req = await requestMaker(
|
|
344
|
+
payloadJSON?.headers || {},
|
|
345
|
+
payloadJSON?.body || {},
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
const requestStarts = performance.now();
|
|
349
|
+
|
|
350
|
+
const res = await context.request.delete(URL, req);
|
|
351
|
+
|
|
352
|
+
const duration = performance.now() - requestStarts;
|
|
353
|
+
|
|
354
|
+
const response = responseMaker(payloadJSON, res, duration);
|
|
355
|
+
|
|
356
|
+
context.response = await response;
|
|
357
|
+
},
|
|
358
|
+
vars: () => {
|
|
359
|
+
return context.vars;
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
|
|
363
363
|
module.exports = { api };
|