froth-webdriverio-framework 3.0.49 → 3.0.50
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/commonMethods/apicall.js +55 -42
- package/package.json +1 -1
package/commonMethods/apicall.js
CHANGED
|
@@ -11,9 +11,9 @@ async function callapi(method, api_url, queryParams, payloaddetails, authenticat
|
|
|
11
11
|
|
|
12
12
|
if (payloaddetails && Object.keys(payloaddetails).length > 0) {
|
|
13
13
|
console.log("Payload Details:", JSON.stringify(payloaddetails));
|
|
14
|
-
formData= await jsonToFormData(payloaddetails);
|
|
14
|
+
formData = await jsonToFormData(payloaddetails);
|
|
15
15
|
console.log("FormData:", JSON.stringify(formData));
|
|
16
|
-
|
|
16
|
+
// Object.entries(payloaddetails).forEach(([key, value]) => formData.append(key, value));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
try {
|
|
@@ -39,22 +39,22 @@ async function callapi(method, api_url, queryParams, payloaddetails, authenticat
|
|
|
39
39
|
}
|
|
40
40
|
async function jsonToFormData(json) {
|
|
41
41
|
const formData = new FormData();
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
function appendFormData(data, parentKey = '') {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (data && typeof data === 'object' && !Array.isArray(data)) {
|
|
45
|
+
for (const key in data) {
|
|
46
|
+
if (data.hasOwnProperty(key)) {
|
|
47
|
+
appendFormData(data[key], parentKey ? `${parentKey}[${key}]` : key);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
formData.append(parentKey, data);
|
|
49
52
|
}
|
|
50
|
-
} else {
|
|
51
|
-
formData.append(parentKey, data);
|
|
52
|
-
}
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
appendFormData(json);
|
|
56
56
|
return formData;
|
|
57
|
-
|
|
57
|
+
}
|
|
58
58
|
|
|
59
59
|
// Function to form headers
|
|
60
60
|
async function formheaders(authentication, headers) {
|
|
@@ -76,48 +76,61 @@ async function formheaders(authentication, headers) {
|
|
|
76
76
|
return headers;
|
|
77
77
|
|
|
78
78
|
}
|
|
79
|
-
async function validate(attribute, actionname, buffer,
|
|
80
|
-
let valueToVerify;
|
|
79
|
+
async function validate(attribute_name, attribute, actionname, buffer, buffername_value, datatype) {
|
|
81
80
|
|
|
82
81
|
try {
|
|
83
|
-
let assertionStatus = false; // Initialize status
|
|
84
82
|
|
|
85
83
|
if (actionname.toLowerCase() == "verify") {
|
|
86
|
-
|
|
87
|
-
//if buffer is true, get the value from buffer
|
|
88
|
-
buffer ? valueToVerify = BUFFER.getItem(value) : valueToVerify = value;
|
|
89
|
-
|
|
90
|
-
if (datatype.toLowerCase() == "integer") {
|
|
91
|
-
valueToVerify = Number(valueToVerify);
|
|
92
|
-
} else if (datatype.toLowerCase() == "boolean") {
|
|
93
|
-
valueToVerify = Boolean(valueToVerify);
|
|
94
|
-
}
|
|
95
|
-
expect(attribute).toBe(valueToVerify, `Expected value: ${valueToVerify}, but got: ${attribute}`);
|
|
96
|
-
assertionStatus = true; // If assertion passes, set status to true
|
|
97
|
-
console.log("Verification succeeded.");
|
|
98
|
-
let annotationMessage = `Verification passed. Actual text: ${attribute}, Expected text: ${valueToVerify}.`;
|
|
99
|
-
await amendToBrowserstack(annotationMessage, "info");
|
|
100
|
-
|
|
84
|
+
await validateAttributeData(attribute_name,attribute,buffer, buffername_value, datatype);
|
|
101
85
|
} else if (actionname.toLowerCase() == "setbuffer") {
|
|
102
|
-
BUFFER.setItem(
|
|
86
|
+
BUFFER.setItem(buffername_value, attribute);
|
|
103
87
|
} else if (actionname.toLowerCase() == "getbuffer") {
|
|
104
|
-
return BUFFER.getItem(
|
|
88
|
+
return BUFFER.getItem(buffername_value);
|
|
105
89
|
}
|
|
106
90
|
} catch (e) {
|
|
107
|
-
console.error('Error in validate:', e);
|
|
108
|
-
console.log(`Validation failed. Expected text: ${valueToVerify}.`);
|
|
109
|
-
let annotationMessage = `Verification failed. Expected text: ${valueToVerify}.`;
|
|
110
|
-
await amendToBrowserstack(annotationMessage, "error");
|
|
91
|
+
console.error('Error in validate method:', e);
|
|
111
92
|
}
|
|
112
93
|
}
|
|
113
94
|
|
|
95
|
+
async function validateAttributeData(attribute_name,attribute,buffer, buffername_value, datatype) {
|
|
96
|
+
let assertionStatus = false; // Initialize status
|
|
97
|
+
let valueToVerify;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
//if buffer is true, get the value from buffer
|
|
101
|
+
buffer ? valueToVerify = BUFFER.getItem(buffername_value) : valueToVerify = buffername_value;
|
|
102
|
+
|
|
103
|
+
if (datatype.toLowerCase() == "integer") {
|
|
104
|
+
valueToVerify = Number(valueToVerify);
|
|
105
|
+
} else if (datatype.toLowerCase() == "boolean") {
|
|
106
|
+
valueToVerify = Boolean(valueToVerify);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
expect(attribute).toBe(valueToVerify, `${attribute_name} --> Expected value: ${valueToVerify}, but got: ${attribute}`);
|
|
110
|
+
assertionStatus = true; // If assertion passes, set status to true
|
|
111
|
+
|
|
112
|
+
console.log("Verification succeeded.");
|
|
113
|
+
let annotationMessage = `${attribute_name} Verification passed. Actual text: ${attribute}, Expected text: ${valueToVerify}.`;
|
|
114
|
+
|
|
115
|
+
if (process.env.BROWSERSTACK)
|
|
116
|
+
await amendToBrowserstack(annotationMessage, "info");
|
|
117
|
+
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error('Error in validateAttributeData:', e);
|
|
120
|
+
console.log(`${attribute_name} Validation failed. Expected text: ${valueToVerify}.`);
|
|
121
|
+
let annotationMessage = `${attribute_name} Verification failed. Expected text: ${valueToVerify}.`;
|
|
122
|
+
|
|
123
|
+
if (process.env.BROWSERSTACK)
|
|
124
|
+
await amendToBrowserstack(annotationMessage, "error");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
114
127
|
async function amendToBrowserstack(annotationMessage, level) {
|
|
115
128
|
try {
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
await driver.execute('browserstack_executor: {"action": "annotate", "arguments": {"data":"' + annotationMessage + '","level": "' + level + '"}}');
|
|
130
|
+
|
|
118
131
|
} catch (error) {
|
|
119
|
-
|
|
120
|
-
|
|
132
|
+
console.error('Error occurred while annoting to BS :', error);
|
|
133
|
+
throw error;
|
|
121
134
|
}
|
|
122
|
-
|
|
135
|
+
}
|
|
123
136
|
module.exports = { callapi, validate };
|