froth-webdriverio-framework 3.0.119 → 3.0.121
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/froth_common_actions/apicall.js +50 -43
- package/package.json +1 -1
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
const amendToBrowserstack = require("../froth_api_calls/browsersatckSessionInfo").amend2Browserstack;
|
|
2
2
|
|
|
3
|
-
async function callapi(
|
|
3
|
+
async function callapi(methodtype, api_url, queryParams, payloaddetails, body_type, authentication, headersdetails, attachments) {
|
|
4
4
|
let response;
|
|
5
5
|
if (queryParams && Object.keys(queryParams).length > 0) {
|
|
6
6
|
const queryString = new URLSearchParams(queryParams).toString();
|
|
7
7
|
api_url += `?${queryString}`;
|
|
8
8
|
}
|
|
9
|
-
console.log("URL:
|
|
10
|
-
|
|
11
|
-
// console.log("Payload Details: before if loop", JSON.stringify(payloaddetails));
|
|
12
|
-
|
|
13
|
-
if (payloaddetails && Object.keys(payloaddetails).length > 0) {
|
|
14
|
-
console.log("Payload Details:", JSON.stringify(payloaddetails));
|
|
15
|
-
formData = await jsonToFormData(payloaddetails);
|
|
16
|
-
console.log("FormData:", JSON.stringify(formData));
|
|
17
|
-
// Object.entries(payloaddetails).forEach(([key, value]) => formData.append(key, value));
|
|
18
|
-
}
|
|
9
|
+
console.log("Final API URL:", api_url);
|
|
10
|
+
|
|
19
11
|
|
|
20
12
|
try {
|
|
21
|
-
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
|
|
14
|
+
let method = methodtype;
|
|
15
|
+
let headers = await formheaders(authentication, headersdetails, body_type);
|
|
16
|
+
let body = null;
|
|
17
|
+
console.log("Body Type:", body_type);
|
|
18
|
+
if (body_type === "raw" && payloaddetails && Object.keys(payloaddetails).length > 0) {
|
|
19
|
+
console.log("Payload (JSON):", JSON.stringify(payloaddetails));
|
|
20
|
+
body = JSON.stringify(payloaddetails);
|
|
21
|
+
console.log("Payload (raw):", body);
|
|
22
|
+
} else if (body_type === "formdata" && payloaddetails) {
|
|
23
|
+
body = await jsonToFormData(payloaddetails);
|
|
24
|
+
console.log("Payload (FormData):", body);
|
|
25
|
+
for (let [key, value] of body.entries()) {
|
|
26
|
+
console.log(`FormData Key: ${key}, Value: ${value}`);
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
console.log("No body sent (body_type not provided or empty payload).");
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
// console.log("options:", JSON.stringify(options, null, 2));
|
|
32
33
|
// Send the request
|
|
33
|
-
response = await fetch(api_url,
|
|
34
|
+
const response = await fetch(api_url, {method,headers, body});
|
|
35
|
+
|
|
36
|
+
console.log("Response Data:", response);
|
|
34
37
|
|
|
35
38
|
} catch (error) {
|
|
36
39
|
console.error('Error during API call in call api menthod:', error);
|
|
37
40
|
let annotationMessage = 'Error during API call:' + error.response ? error.response.data : error.message;
|
|
38
|
-
// if (process.env.BROWSERSTACK)
|
|
39
41
|
await amendToBrowserstack(annotationMessage, "error");
|
|
40
42
|
throw error;
|
|
41
43
|
}
|
|
@@ -57,14 +59,19 @@ async function jsonToFormData(json) {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
appendFormData(json);
|
|
60
|
-
console.log("FormData in json to formdata:",formData);
|
|
61
|
-
console.log("FormData in json to formdata:", JSON.stringify(formData));
|
|
62
|
+
console.log("FormData in json to formdata:", formData);
|
|
62
63
|
return formData;
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
// Function to form headers
|
|
66
|
-
async function formheaders(authentication, headers) {
|
|
67
|
+
async function formheaders(authentication, headers, body_type) {
|
|
67
68
|
try {
|
|
69
|
+
if (!headers || typeof headers !== "object") {
|
|
70
|
+
headers = {};
|
|
71
|
+
}
|
|
72
|
+
if (body_type === "formdata") {
|
|
73
|
+
headers['Content-Type'] = 'multipart/form-data';
|
|
74
|
+
}
|
|
68
75
|
// Add authentication headers based on the type
|
|
69
76
|
if (authentication && authentication.auth_type) {
|
|
70
77
|
if (authentication.auth_type?.toLowerCase() === 'bearer') {
|
|
@@ -78,27 +85,27 @@ async function formheaders(authentication, headers) {
|
|
|
78
85
|
} catch (e) {
|
|
79
86
|
|
|
80
87
|
console.error('Error in formheaders:', e);
|
|
81
|
-
let annotationMessage =
|
|
82
|
-
|
|
88
|
+
let annotationMessage = `Error during API call: ${error.response?.data || error.message}`;
|
|
89
|
+
await amendToBrowserstack(annotationMessage, "error");
|
|
83
90
|
}
|
|
84
91
|
return headers;
|
|
85
92
|
|
|
86
93
|
}
|
|
87
94
|
async function validate(attribute_name, attribute, actionname, buffer, buffername_value, datatype) {
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
if (actionname.toLowerCase() == "verify") {
|
|
97
|
+
await validateAttributeData(attribute_name, attribute, buffer, buffername_value, datatype);
|
|
98
|
+
} else if (actionname.toLowerCase() == "setbuffer") {
|
|
99
|
+
BUFFER.setItem(buffername_value, attribute);
|
|
100
|
+
let annotationMessage = `The vlaue has been stored in the buffer : ${buffername_value}.`;
|
|
101
|
+
await amendToBrowserstack(annotationMessage, "info");
|
|
95
102
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
103
|
+
} else if (actionname.toLowerCase() == "getbuffer") {
|
|
104
|
+
let annotationMessage = `The vlaue has been retrived from the buffer : ${buffername_value}.`;
|
|
105
|
+
await amendToBrowserstack(annotationMessage, "info");
|
|
106
|
+
return BUFFER.getItem(buffername_value);
|
|
100
107
|
|
|
101
|
-
|
|
108
|
+
}
|
|
102
109
|
// } catch (e) {
|
|
103
110
|
// console.error('Error in validate method:', e);
|
|
104
111
|
// throw e;
|
|
@@ -109,7 +116,7 @@ async function validateAttributeData(attribute_name, attribute, buffer, bufferna
|
|
|
109
116
|
let assertionStatus = false; // Initialize status
|
|
110
117
|
let valueToVerify;
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
try {
|
|
113
120
|
//if buffer is true, get the value from buffer
|
|
114
121
|
buffer ? valueToVerify = BUFFER.getItem(buffername_value) : valueToVerify = buffername_value;
|
|
115
122
|
|
|
@@ -117,11 +124,11 @@ async function validateAttributeData(attribute_name, attribute, buffer, bufferna
|
|
|
117
124
|
valueToVerify = Number(valueToVerify);
|
|
118
125
|
} else if (datatype.toLowerCase() == "boolean") {
|
|
119
126
|
valueToVerify = Boolean(valueToVerify);
|
|
120
|
-
}else if (datatype.toLowerCase() == "float") {
|
|
127
|
+
} else if (datatype.toLowerCase() == "float") {
|
|
121
128
|
valueToVerify = parseFloat(valueToVerify);
|
|
122
|
-
}else if (datatype.toLowerCase() == "double") {
|
|
129
|
+
} else if (datatype.toLowerCase() == "double") {
|
|
123
130
|
valueToVerify = parseFloat(valueToVerify);
|
|
124
|
-
}else if (datatype.toLowerCase() == "string") {
|
|
131
|
+
} else if (datatype.toLowerCase() == "string") {
|
|
125
132
|
valueToVerify = valueToVerify.toString();
|
|
126
133
|
}
|
|
127
134
|
|