froth-webdriverio-framework 3.0.159 → 4.0.0

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.
@@ -34,9 +34,7 @@ async function callapi(methodtype, api_url, queryParams, payloaddetails, body_ty
34
34
  console.log("No body sent (body_type not provided or empty payload).");
35
35
  }
36
36
 
37
- // console.log("options:", JSON.stringify(options, null, 2));
38
- // Send the request
39
- // if (method === 'GET' && body) {
37
+
40
38
  console.warn("Warning: GET request with a body is non-standard and may not work with all APIs.");
41
39
  response = await axios({
42
40
  method: method,
@@ -44,14 +42,7 @@ async function callapi(methodtype, api_url, queryParams, payloaddetails, body_ty
44
42
  headers: headers,
45
43
  data: body === null ? undefined : body // Axios allows body with GET in some cases
46
44
  });
47
- // } else {
48
- // // ✅ Use Fetch for other request types
49
- // response = await fetch(api_url, {
50
- // method,
51
- // headers,
52
- // body: method !== 'GET' ? body : null, // Fetch does NOT allow body in GET
53
- // });
54
- // }
45
+
55
46
 
56
47
  console.log("Response Data:", response.data);
57
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "3.0.159",
3
+ "version": "4.0.0",
4
4
 
5
5
  "readme": "WebdriverIO Integration",
6
6
  "description": "WebdriverIO and BrowserStack App Automate",
File without changes
@@ -1,165 +0,0 @@
1
- const amendToBrowserstack = require("../froth_api_calls/browsersatckSessionInfo").amend2Browserstack;
2
-
3
- async function callapi(methodtype, api_url, queryParams, payloaddetails, body_type, authentication, headersdetails, attachments) {
4
- let response;
5
- if (queryParams && Object.keys(queryParams).length > 0) {
6
- const queryString = new URLSearchParams(queryParams).toString();
7
- api_url += `?${queryString}`;
8
- }
9
- console.log("Final API URL:", api_url);
10
-
11
-
12
- try {
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
- console.log("method:",method);
19
- console.log("headers:",headers);
20
- if (body_type === "raw" && payloaddetails && Object.keys(payloaddetails).length > 0) {
21
- console.log("Payload (JSON):", JSON.stringify(payloaddetails));
22
- body = JSON.stringify(payloaddetails);
23
- console.log("Payload (raw):", body);
24
- } else if (body_type === "formdata" && payloaddetails) {
25
- body = await jsonToFormData(payloaddetails);
26
- console.log("Payload (FormData):", body);
27
- for (let [key, value] of body.entries()) {
28
- console.log(`FormData Key: ${key}, Value: ${value}`);
29
- }
30
- } else {
31
- console.log("No body sent (body_type not provided or empty payload).");
32
- }
33
-
34
- // console.log("options:", JSON.stringify(options, null, 2));
35
- // Send the request
36
- if (method === 'GET' && body) {
37
- console.warn("Using X-HTTP-Method-Override for GET with body.");
38
- response = await fetch(api_url, {
39
- method: 'POST', // Override to POST
40
- headers: {
41
- ...headers,
42
- 'X-HTTP-Method-Override': 'GET' // Trick the API into treating it as GET
43
- },
44
- body: body
45
- });
46
- } else
47
- response = await fetch(api_url, {method,headers, body});
48
-
49
- console.log("Response Data:", response);
50
-
51
- } catch (error) {
52
- console.error('Error during API call in call api menthod:', error);
53
- let annotationMessage = 'Error during API call:' + error.response ? error.response.data : error.message;
54
- await amendToBrowserstack(annotationMessage, "error");
55
- throw error;
56
- }
57
- return response;
58
- }
59
- async function jsonToFormData(json) {
60
- const formData = new FormData();
61
-
62
- function appendFormData(data, parentKey = '') {
63
- if (data && typeof data === 'object' && !Array.isArray(data)) {
64
- for (const key in data) {
65
- if (data.hasOwnProperty(key)) {
66
- appendFormData(data[key], parentKey ? `${parentKey}[${key}]` : key);
67
- }
68
- }
69
- } else {
70
- formData.append(parentKey, data);
71
- }
72
- }
73
-
74
- appendFormData(json);
75
- console.log("FormData in json to formdata:", formData);
76
- return formData;
77
- }
78
-
79
- // Function to form headers
80
- async function formheaders(authentication, headers, body_type) {
81
- try {
82
- if (!headers || typeof headers !== "object") {
83
- headers = {};
84
- }
85
- if(body_type === "raw"){
86
- headers['Content-Type'] = 'application/json';
87
- }
88
- // Add authentication headers based on the type
89
- if (authentication && authentication.auth_type) {
90
- if (authentication.auth_type?.toLowerCase() === 'bearer') {
91
- console.log('Bearer token:', authentication.token);
92
- headers.Authorization = `Bearer ` + authentication.token;
93
- } else if (authentication.auth_type?.toLowerCase() === 'basic') {
94
- headers.Authorization = `Basic ` + btoa(authentication.username + `:` + authentication.password);
95
- }
96
- }
97
- console.log('Headers:', headers);
98
- } catch (e) {
99
-
100
- console.error('Error in formheaders:', e);
101
- let annotationMessage = `Error during API call: ${error.response?.data || error.message}`;
102
- await amendToBrowserstack(annotationMessage, "error");
103
- }
104
- return headers;
105
-
106
- }
107
- async function validate(attribute_name, attribute, actionname, buffer, buffername_value, datatype) {
108
-
109
- if (actionname.toLowerCase() == "verify") {
110
- await validateAttributeData(attribute_name, attribute, buffer, buffername_value, datatype);
111
- } else if (actionname.toLowerCase() == "setbuffer") {
112
- BUFFER.setItem(buffername_value, attribute);
113
- let annotationMessage = `The vlaue has been stored in the buffer : ${buffername_value}.`;
114
- await amendToBrowserstack(annotationMessage, "info");
115
-
116
- } else if (actionname.toLowerCase() == "getbuffer") {
117
- let annotationMessage = `The vlaue has been retrived from the buffer : ${buffername_value}.`;
118
- await amendToBrowserstack(annotationMessage, "info");
119
- return BUFFER.getItem(buffername_value);
120
-
121
- }
122
- // } catch (e) {
123
- // console.error('Error in validate method:', e);
124
- // throw e;
125
- // }
126
- }
127
-
128
- async function validateAttributeData(attribute_name, attribute, buffer, buffername_value, datatype) {
129
- let assertionStatus = false; // Initialize status
130
- let valueToVerify;
131
-
132
- try {
133
- //if buffer is true, get the value from buffer
134
- buffer ? valueToVerify = BUFFER.getItem(buffername_value) : valueToVerify = buffername_value;
135
-
136
- if (datatype.toLowerCase() == "integer") {
137
- valueToVerify = Number(valueToVerify);
138
- } else if (datatype.toLowerCase() == "boolean") {
139
- valueToVerify = Boolean(valueToVerify);
140
- } else if (datatype.toLowerCase() == "float") {
141
- valueToVerify = parseFloat(valueToVerify);
142
- } else if (datatype.toLowerCase() == "double") {
143
- valueToVerify = parseFloat(valueToVerify);
144
- } else if (datatype.toLowerCase() == "string") {
145
- valueToVerify = valueToVerify.toString();
146
- }
147
-
148
- expect(attribute).toBe(valueToVerify, `${attribute_name} --> Expected value: ${valueToVerify}, but got: ${attribute}`);
149
- assertionStatus = true; // If assertion passes, set status to true
150
-
151
- console.log(`Attribute name : ${attribute_name} verification passed. Actual text: ${attribute}, Expected text: ${valueToVerify}.`);
152
- let annotationMessage = `Attribute name : ${attribute_name} - verification passed. Actual text: ${attribute}, Expected text: ${valueToVerify}.`;
153
- await amendToBrowserstack(annotationMessage, "info");
154
-
155
- } catch (e) {
156
- console.error('Error in validateAttributeData:', e);
157
- console.log(`Attribute name : ${attribute_name} verification failed. Expected text: ${valueToVerify}. error: ${e.toString()}`);
158
- let annotationMessage = `Attribute name : ${attribute_name} - verification failed. Expected text: ${valueToVerify}. error: ${e.toString()}`;
159
- await amendToBrowserstack(annotationMessage, "error");
160
-
161
- throw e;
162
- }
163
- }
164
-
165
- module.exports = { callapi, validate };