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.
@@ -1,41 +1,43 @@
1
1
  const amendToBrowserstack = require("../froth_api_calls/browsersatckSessionInfo").amend2Browserstack;
2
2
 
3
- async function callapi(method, api_url, queryParams, payloaddetails, authentication, headers, attachments) {
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: " + api_url);
10
- let formData = new FormData();
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
- // Prepare fetch options
22
- let options = {
23
- method: method,
24
- headers: await formheaders(authentication, headers)
25
- };
26
- // Only add the body if the method is not GET or HEAD
27
- if (method !== 'GET' && method !== 'HEAD') {
28
- console.log("inside if loop if its POST or PUT");
29
- options.body = formData;
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
- console.log("options:", JSON.stringify(options, null, 2));
31
+
32
+ // console.log("options:", JSON.stringify(options, null, 2));
32
33
  // Send the request
33
- response = await fetch(api_url, options);
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 = 'Error during API call:' + error.response ? error.response.data : error.message;
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
- if (actionname.toLowerCase() == "verify") {
90
- await validateAttributeData(attribute_name, attribute, buffer, buffername_value, datatype);
91
- } else if (actionname.toLowerCase() == "setbuffer") {
92
- BUFFER.setItem(buffername_value, attribute);
93
- let annotationMessage = `The vlaue has been stored in the buffer : ${buffername_value}.`;
94
- await amendToBrowserstack(annotationMessage, "info");
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
- } else if (actionname.toLowerCase() == "getbuffer") {
97
- let annotationMessage = `The vlaue has been retrived from the buffer : ${buffername_value}.`;
98
- await amendToBrowserstack(annotationMessage, "info");
99
- return BUFFER.getItem(buffername_value);
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
- try {
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "3.0.119",
3
+ "version": "3.0.121",
4
4
 
5
5
  "readme": "WebdriverIO Integration",
6
6
  "description": "WebdriverIO and BrowserStack App Automate",