froth-webdriverio-framework 7.0.13 → 7.0.15

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.
@@ -77,58 +77,69 @@ async function getBSSessionDetails(sessionType, bsUsername, bsPassword) {
77
77
  }
78
78
  }
79
79
 
80
- // async function amend2Browserstack(annotationMessage, level) {
81
- // try {
82
- // console.log(`Annotation message: ${annotationMessage}`);
83
- // if (process.env.PLATFORM === 'browserstack') {
84
- // await driver.execute(`browserstack_executor: {"action": "annotate", "arguments": {"data":"${annotationMessage}","level": "${level}"}}`);
85
- // }
86
- // } catch (error) {
87
- // console.error('Error annotating BrowserStack session:', error);
88
- // throw error;
89
- // }
90
- // }
80
+ async function sendSingleAnnotation(annotationMessage, level) {
81
+ try {
82
+ console.log(`=======> BrowserStack Annotation (single): ${annotationMessage}`);
83
+ if (process.env.PLATFORM === 'browserstack') {
84
+ await driver.execute(`browserstack_executor: {"action": "annotate", "arguments": {"data":"${annotationMessage}","level": "${level}"}}`);
85
+ }
86
+ } catch (error) {
87
+ console.error('Error annotating BrowserStack session:', error);
88
+ throw error;
89
+ }
90
+ }
91
91
 
92
92
  async function amend2Browserstack(annotationMessage, level) {
93
93
  try {
94
- const MAX_CHUNK_BYTES = 800 * 1024; // 800 KB (BYTE-based)
94
+ const MAX_CHUNK_BYTES = 800 * 1024; // 800 KB
95
95
 
96
- // 1️⃣ Convert message to string
97
- let messageStr =
96
+ // Convert to string
97
+ const messageStr =
98
98
  typeof annotationMessage === "string"
99
99
  ? annotationMessage
100
100
  : JSON.stringify(annotationMessage, null, 2);
101
101
 
102
- // 2️⃣ Escape for BrowserStack executor
103
- let escapedMessage = messageStr
104
- .replace(/\\/g, "\\\\")
105
- .replace(/"/g, '\\"')
106
- .replace(/\n/g, "\\n")
107
- .replace(/\r/g, "\\r");
102
+ // Escape once
103
+ const escapedMessage = await escapeForBrowserStack(messageStr);
104
+
105
+ // Byte size check
106
+ const messageBytes = Buffer.byteLength(escapedMessage, "utf8");
107
+
108
+ console.log(`BrowserStack annotation size: ${messageBytes} bytes`);
109
+
110
+ // ✅ Small payload → single annotation
111
+ if (messageBytes <= MAX_CHUNK_BYTES) {
112
+ await sendSingleAnnotation(escapedMessage, level);
113
+ return;
114
+ }
108
115
 
109
- // 3️⃣ Convert to Buffer (UTF-8)
110
- const buffer = Buffer.from(escapedMessage, "utf8");
116
+ // 🔁 Large payload chunking
117
+ await sendChunkedAnnotations(escapedMessage, level, MAX_CHUNK_BYTES);
111
118
 
112
- // 4️⃣ Split into BYTE chunks
119
+ } catch (error) {
120
+ console.error("BrowserStack annotation failed:", error);
121
+ throw error;
122
+ }
123
+ }
124
+
125
+ async function sendChunkedAnnotations(message, level, maxBytes) {
126
+ try {
127
+ const buffer = Buffer.from(message, "utf8");
113
128
  const chunks = [];
114
- for (let i = 0; i < buffer.length; i += MAX_CHUNK_BYTES) {
115
- chunks.push(buffer.subarray(i, i + MAX_CHUNK_BYTES).toString("utf8"));
129
+
130
+ for (let i = 0; i < buffer.length; i += maxBytes) {
131
+ chunks.push(buffer.subarray(i, i + maxBytes).toString("utf8"));
116
132
  }
133
+
117
134
  console.log(
118
- `BrowserStack Annotation → total bytes: ${buffer.length}, chunks: ${chunks.length}`
135
+ `BrowserStack chunking enabled → total bytes: ${buffer.length}, chunks: ${chunks.length}`
119
136
  );
120
137
 
121
- // 5️⃣ Print + send each chunk
122
138
  for (let i = 0; i < chunks.length; i++) {
123
- const chunkMessage =
124
- chunks.length > 1
125
- ? `PART ${i + 1}/${chunks.length}\n${chunks[i]}`
126
- : chunks[i];
139
+ const chunkMessage = `PART ${i + 1}/${chunks.length}\n${chunks[i]}`;
127
140
 
128
- // 🔍 LOCAL LOG
129
- console.log(`=======> BrowserStack Chunk ${i + 1}/${chunks.length}`, JSON.stringify(chunkMessage, null, 2));
141
+ console.log(`=======> BrowserStack Chunk ${i + 1}/${chunks.length}`,chunkMessage);
130
142
 
131
- // 🚀 SEND TO BROWSERSTACK (WDIO-safe)
132
143
  if (process.env.PLATFORM === "browserstack") {
133
144
  await driver.execute(
134
145
  `browserstack_executor: {"action":"annotate","arguments":{"data":"${chunkMessage}","level":"${level}"}}`
@@ -140,6 +151,13 @@ async function amend2Browserstack(annotationMessage, level) {
140
151
  throw error;
141
152
  }
142
153
  }
154
+ async function escapeForBrowserStack(message) {
155
+ return message
156
+ .replace(/\\/g, "\\\\")
157
+ .replace(/"/g, '\\"')
158
+ .replace(/\n/g, "\\n")
159
+ .replace(/\r/g, "\\r");
160
+ }
143
161
 
144
162
 
145
163
 
@@ -263,23 +263,23 @@ module.exports = {
263
263
  update_CICDRUNID_ReportUrl
264
264
  };
265
265
 
266
- async function main() {
267
- try {
268
- const frothUrl = "devapi.frothtestops.com";
269
- // const username = "subhra.subudhi@roboticodigital.com";
270
- // const password = "V2VsY29tZUAxMjM=";
271
-
272
- // const token = await getLoginToken(frothUrl, username, password);
273
- // if (!token) {
274
- // throw new Error('Login failed, no token obtained');
275
- // }
276
- const token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcyNTgyMzk5LCJpYXQiOjE3NjQ3NjU3OTQsImp0aSI6IjRhOWUyNjlkNWZhMzRlYzQ4NjZhZjk5MTc3Y2MwNzZiIiwidXNlcl9pZCI6NH0.1a_KwJvW3LOoBgzWMZBCoyGnA3eNm_XYeiah6Ql_EoA'
277
- const id = 147;
278
- const data = await getExecuitonDetails(frothUrl, token, id);
279
- console.log("Retrieved JSON Data:", data);
280
- } catch (error) {
281
- console.error('Error in main function:', error);
282
- }
283
- }
284
-
285
- main();
266
+ // async function main() {
267
+ // try {
268
+ // const frothUrl = "devapi.frothtestops.com";
269
+ // // const username = "subhra.subudhi@roboticodigital.com";
270
+ // // const password = "V2VsY29tZUAxMjM=";
271
+
272
+ // // const token = await getLoginToken(frothUrl, username, password);
273
+ // // if (!token) {
274
+ // // throw new Error('Login failed, no token obtained');
275
+ // // }
276
+ // const token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzcyNTgyMzk5LCJpYXQiOjE3NjQ3NjU3OTQsImp0aSI6IjRhOWUyNjlkNWZhMzRlYzQ4NjZhZjk5MTc3Y2MwNzZiIiwidXNlcl9pZCI6NH0.1a_KwJvW3LOoBgzWMZBCoyGnA3eNm_XYeiah6Ql_EoA'
277
+ // const id = 147;
278
+ // const data = await getExecuitonDetails(frothUrl, token, id);
279
+ // console.log("Retrieved JSON Data:", data);
280
+ // } catch (error) {
281
+ // console.error('Error in main function:', error);
282
+ // }
283
+ // }
284
+
285
+ // main();
@@ -32,14 +32,14 @@ async function callapi(
32
32
  ) {
33
33
  let response;
34
34
  const startTime = Date.now();
35
- console.log("Final API URL:", api_url);
35
+ console.log("Final API URL:", apiUrl);
36
36
 
37
37
  try {
38
38
  const method = methodType.toUpperCase();
39
39
  const headers = await formHeaders(authentication, headersDetails, bodyType);
40
40
 
41
41
  let body;
42
- if (bodyType === "raw" && payloadDetails) {
42
+ if (bodyType === "raw" && payloadDetails && Object.keys(payloaddetails).length > 0) {
43
43
  console.log("Payload (JSON):", JSON.stringify(payloaddetails));
44
44
  body = payloadDetails;
45
45
  console.log("Payload (raw):", body);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "7.0.13",
3
+ "version": "7.0.15",
4
4
  "readme": "WendriverIO Integration with [BrowserStack](https://www.browserstack.com)",
5
5
  "description": "Selenium examples for WebdriverIO and BrowserStack App Automate",
6
6
  "scripts": {