froth-webdriverio-framework 4.0.1 → 4.0.2
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.
|
@@ -51,12 +51,16 @@ const commonconfig = {
|
|
|
51
51
|
if (capabilities.platformName === 'android' || capabilities.platformName === 'ios')
|
|
52
52
|
capabilities.app = process.env.BROWSERSTACK_APP_PATH;
|
|
53
53
|
|
|
54
|
+
try {
|
|
55
|
+
let mediaFiles = process.env.MEDIA_FILES ? JSON.parse(process.env.MEDIA_FILES) : [];
|
|
56
|
+
console.log("Size of Media Files:", Array.isArray(mediaFiles) ? mediaFiles.length : "Invalid data");
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.log("Size of Media Files:", process.env.MEDIA_FILES.length);
|
|
58
|
-
if (process.env.MEDIA_FILES.length > 0)
|
|
58
|
+
if (Array.isArray(mediaFiles) && mediaFiles.length > 0) {
|
|
59
|
+
console.log("Media Files:", JSON.parse(process.env.MEDIA_FILES));
|
|
59
60
|
capabilities['browserstack.uploadMedia'] = JSON.parse(process.env.MEDIA_FILES);
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Error parsing MEDIA_FILES:", error);
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
console.log(`Running tests on after app,bslocal,mediafiles: ${JSON.stringify(capabilities)}`);
|
package/package.json
CHANGED
|
@@ -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 };
|