froth-webdriverio-framework 6.0.35 → 6.0.36

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,73 +0,0 @@
1
- const amendToBrowserstack = require("../froth_api_calls/browsersatckSessionInfo").amend2Browserstack;
2
-
3
- async function logJsonData2Table(jsonData) {
4
- try {
5
- console.log("Logging JSON data to table format in BrowserStack:");
6
- console.log(JSON.stringify(jsonData, null, 2));
7
-
8
- if (!Array.isArray(jsonData) || jsonData.length === 0) {
9
- await amendToBrowserstack("No data to log", "info");
10
- return;
11
- }
12
-
13
- // --- Extract keys dynamically (columns) ---
14
- const keys = Object.keys(jsonData[0]);
15
-
16
- // --- Calculate max width for each column ---
17
- const colWidths = {};
18
- keys.forEach(key => {
19
- colWidths[key] = Math.max(
20
- key.length,
21
- ...jsonData.map(row => String(row[key] ?? "").length)
22
- ) + 2;
23
- });
24
-
25
- // --- Build line separator ---
26
- const line = "-".repeat(
27
- keys.reduce((sum, key) => sum + colWidths[key], 0) + keys.length + 1
28
- );
29
-
30
- // --- Build header ---
31
- let table = line + "\n";
32
- table += "|" + keys.map(key => ` ${key.padEnd(colWidths[key])}`).join("|") + "|\n";
33
- table += line + "\n";
34
-
35
- // --- Build rows ---
36
- jsonData.forEach(row => {
37
- table += "|" + keys.map(key => ` ${String(row[key] ?? "").padEnd(colWidths[key])}`).join("|") + "|\n";
38
- });
39
-
40
- table += line;
41
- console.log(table);
42
- // --- Send to BrowserStack ---
43
- await amendToBrowserstack(table, "info");
44
-
45
- } catch (error) {
46
- console.error('Error occurred while logging JSON data to table:', error);
47
- // let annotationMessage = `Error occurred while logging JSON data to table: ${error.message}.`;
48
- // await amendToBrowserstack(annotationMessage, "error");
49
- }
50
- }
51
- module.exports = {
52
- logJsonData2Table
53
- };
54
-
55
- // // Main function to execute the API call
56
- // async function main() {
57
- // try {
58
- // /// BUFFER.setItem("EXECUTION_SESSIONID","297666e2fd4195de98d7da3b359669072ff41a2a");
59
- // const pageTimes = "[{ name: 'Homepage', time: 120 },{ name: 'Service Account Page', time: 250 },{ name: 'Search Results', time: 180 }]";
60
-
61
- // await logJsonData2Table(pageTimes, "info");
62
- // // const data = [
63
- // // { id: 1, score: 95.5, passed: true },
64
- // // { id: 2, score: 67.2, passed: false },
65
- // // { id: 3, score: null, passed: "N/A" }
66
- // // ];
67
- // // await logJsonData2Table(data, "info");
68
- // } catch (error) {
69
- // console.error('Error in main function:', error);
70
- // }
71
- // }
72
-
73
- // main();
@@ -1,230 +0,0 @@
1
- const RandExp = require('randexp');
2
-
3
- // Random number generator that can handle both range and length
4
- async function RNDNUMBER(minOrLength, max) {
5
- if (max !== undefined) {
6
- // If max is provided, generate a number within the specified range
7
- return Math.floor(Math.random() * (max - minOrLength + 1)) + minOrLength;
8
- } else {
9
- // Otherwise, generate a random number of the specified length
10
- const length = minOrLength || 18; // Default to 18 digits if no length is provided
11
- // if (length <= 0) length = 18; // Default to 18 digits if length is invalid
12
-
13
- const min = Math.pow(10, length - 1); // Minimum value for the given length
14
- const max = Math.pow(10, length) - 1; // Maximum value for the given length
15
-
16
- return Math.floor(Math.random() * (max - min + 1)) + min;
17
- }
18
- }
19
-
20
- // Random floating-point number between 0 and 1
21
- async function RNDFLOAT() {
22
- return Math.random();
23
- }
24
-
25
- // Random integer between 0 and 100000 (large multiplier range)
26
- async function RNDINT() {
27
- return Math.floor(Math.random() * 100000);
28
- }
29
-
30
- // Random text string of specified length
31
- async function RANDOMTEXT(length) {
32
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
33
- let result = '';
34
- for (let i = 0; i < length; i++) {
35
- result += characters.charAt(Math.floor(Math.random() * characters.length));
36
- }
37
- return result;
38
- }
39
-
40
- // Random alphanumeric string of specified length
41
- async function RNDALPHANUM(length) {
42
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
43
- let result = '';
44
- for (let i = 0; i < length; i++) {
45
- result += chars.charAt(Math.floor(Math.random() * chars.length));
46
- }
47
- return result;
48
- }
49
-
50
- async function RNDDECIMAL(minOrLength, max, decimalPlaces) {
51
- if (max !== undefined) {
52
- // If max is provided, generate a decimal number within the specified range
53
- let randomNum = Math.random() * (max - minOrLength) + minOrLength;
54
- console.log(randomNum);
55
- return parseFloat(randomNum.toFixed(decimalPlaces));
56
- } else {
57
- // Otherwise, generate a random decimal number between 0 and 1, rounded to the specified decimal places
58
- let length = minOrLength;
59
- const integerLength = length - decimalPlaces - 1; // Subtract 1 for the decimal point
60
- let integerPart = 0;
61
-
62
- if (integerLength > 0) {
63
- const minInt = Math.pow(10, integerLength - 1);
64
- const maxInt = Math.pow(10, integerLength) - 1;
65
-
66
- // Generate the integer part
67
- integerPart = Math.floor(Math.random() * (maxInt - minInt + 1)) + minInt;
68
- }
69
- // Generate the decimal part
70
- const decimalFactor = Math.pow(10, decimalPlaces);
71
- const decimalPart = Math.floor(Math.random() * decimalFactor);
72
- // Combine integer and decimal parts
73
- const result = `${integerPart}.${decimalPart.toString().padStart(decimalPlaces, '0')}`;
74
- return result;
75
- }
76
- }
77
-
78
-
79
- // Random string based on regex pattern
80
- async function RNDREGEX(regex) {
81
- console.log("inside random regex", regex);
82
- return new RandExp(regex).gen();
83
- }
84
-
85
- async function RNDDATE(startYear = 1950, endYear = 2005, format = 'YYMMDD') {
86
- // Generate a random year between startYear and endYear
87
- const start = new Date(`${startYear}-01-01`).getTime();
88
- const end = new Date(`${endYear}-12-31`).getTime();
89
-
90
- const randomTimestamp = start + Math.random() * (end - start);
91
- const randomDate = new Date(randomTimestamp);
92
- console.log(randomDate);
93
- return FORMATDATE(randomDate, format);
94
- }
95
-
96
- async function FORMATDATE(date, format) {
97
- const yy = String(date.getFullYear()).slice(2);
98
- const yyyy = String(date.getFullYear());
99
- const mm = String(date.getMonth() + 1).padStart(2, '0');
100
- const dd = String(date.getDate()).padStart(2, '0');
101
-
102
- switch (format.toUpperCase()) {
103
- case 'YYMMDD': return `${yy}${mm}${dd}`;
104
- case 'DDMMYY': return `${dd}${mm}${yy}`;
105
- case 'YYYYMMDD': return `${yyyy}${mm}${dd}`;
106
- case 'DDMMYYYY': return `${dd}${mm}${yyyy}`;
107
- case 'MMDDYY': return `${mm}${dd}${yy}`;
108
- case 'MMDDYYYY': return `${mm}${dd}${yyyy}`;
109
- case 'YYDDMM': return `${yy}${dd}${mm}`;
110
- case 'YYYYDDMM': return `${yyyy}${dd}${mm}`;
111
- default: return `${yy}${mm}${dd}`; // Fallback to YYMMDD
112
- }
113
- }
114
- // Main function to process templates and replace placeholders with random values
115
- async function RANDOM(template, datatype) {
116
- const regex = /\{(.*?)\}/g;
117
- let matches = [...template.matchAll(regex)];
118
-
119
- // Iterate over all matches and replace them with the resolved values
120
- let replacements = await Promise.all(matches.map(async (match) => {
121
- const content = match[1]; // Get the content inside { ... }
122
-
123
- const parts = content.split(/[\[\]]/).filter(Boolean); // Split by square brackets
124
- const type = parts[0];
125
- console.log("type is :" + type);
126
- console.log("parts are :" + parts);
127
- switch (type) {
128
- case 'RND':
129
- if (parts.length === 1) {
130
- return await RNDNUMBER(); // {RND} - Default to 5-digit number
131
- }
132
- else if (parts.length === 2) {
133
- return await RNDNUMBER(parseInt(parts[1])); // {RND[length]}
134
- } else if (parts.length === 3) {
135
- return await RNDNUMBER(parseInt(parts[1]), parseInt(parts[2])); // {RND[min][max]}
136
- } else {
137
- return await RNDNUMBER(); // {RND} - Default to 5-digit number
138
- }
139
- break;
140
-
141
- case 'RNDDECIMAL':
142
- console.log(parts);
143
- if (parts.length === 3) {
144
- return await RNDDECIMAL(parseInt(parts[1]), undefined, parseInt(parts[2])); // {RNDDECIMAL[length][decimalPlaces]}
145
- } else if (parts.length === 4) {
146
- return await RNDDECIMAL(parseInt(parts[1]), parseInt(parts[2]), parseInt(parts[3])); // {RNDDECIMAL[length][decimalPlaces]}
147
- } else {
148
- return await RNDDECIMAL(6, undefined, 2); // {RNDDECIMAL[length][decimalPlaces]}
149
- }
150
- break;
151
-
152
- case 'RANDOMTEXT':
153
- return await RANDOMTEXT(parseInt(parts[1])); // {RANDOMTEXT[length]}
154
- break;
155
- case 'CTMSTMP':
156
- console.log("inside CTMSTMP",Date.now());
157
- return Date.now(); // Current timestamp
158
- break;
159
-
160
- case 'RANDOMREGEX':
161
- let regexPattern;
162
- if (parts.length === 3) {
163
- regexPattern = `[${parts[1]}]{${parts[2]}}`; // {RANDOMREGEX[pattern][length]}
164
- console.log("regex pattern is :" + regexPattern);
165
- } else if (parts.length === 2) {
166
- regexPattern = `[${parts[1]}]{10}`; // {RANDOMREGEX[pattern][length]}
167
- console.log("regex pattern is :" + regexPattern);
168
- }
169
- let regex = new RegExp(regexPattern);
170
- return await RNDREGEX(regex); // Generate random string based on regex
171
- break;
172
-
173
- case 'RNDDATE':
174
- return await RNDDATE(parseInt(parts[1]), parseInt(parts[2])); // Generate random date of birth
175
- break;
176
-
177
- default:
178
- return match[0]; // If no match found, return original template string
179
- break;
180
-
181
- }
182
- }));
183
-
184
- // Replace all matches with their resolved values
185
- let result = template;
186
- matches.forEach((match, index) => {
187
- result = result.replace(match[0], replacements[index]);
188
- });
189
- datatype = datatype.toLowerCase();
190
-
191
- if (datatype == 'integer') {
192
- result = parseInt(result);
193
- }
194
- else if (datatype == 'decimal') {
195
- console.log("insude decimal");
196
- result = parseFloat(result);
197
- }
198
- else if (datatype == 'string') {
199
- result = result.toString();
200
- }
201
-
202
- return result;
203
- }
204
-
205
- // Example function to test the template replacement
206
- // async function main() {
207
-
208
- // let template = "SUBHRASUBUDHI {CTMSTMP} @GMAQIL.COM";
209
- // let result = await RANDOM(template, 'STRING');
210
- // console.log(result);
211
- // console.log(typeof result);
212
- // // template = "{RANDOMREGEX[\\\\d{5}(-\\\\\d{4})?][10]}";
213
- // // result = await RANDOM(template, 'STRING');
214
- // // console.log(result);
215
- // // console.log(typeof result);
216
-
217
- // }
218
-
219
- //main();
220
- module.exports = {
221
- RNDNUMBER,
222
- RNDFLOAT,
223
- RNDINT,
224
- RANDOMTEXT,
225
- RNDALPHANUM,
226
- RNDDECIMAL,
227
- RNDREGEX,
228
- RANDOM,
229
- RNDDATE
230
- };
@@ -1,104 +0,0 @@
1
- async function scrollToEnd(maxSwipes, steps) {
2
-
3
- try {
4
- console.log('Scrolling to end');
5
- await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToEnd(' + maxSwipes + ',' + steps + ')');
6
- await driver.pause(3000);
7
- console.log('Scrolled to end');
8
- } catch (error) {
9
- console.error(error.message);
10
- }
11
- }
12
-
13
- async function scrollToLeft(steps) {
14
-
15
- try {
16
- console.log('Scrolling to left');
17
- await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollable.setAsHorizontalList().scrollBackward(' + steps + ')');
18
- await driver.pause(3000);
19
- console.log('Scrolled to left');
20
- } catch (error) {
21
- console.error(error.message);
22
- }
23
- }
24
-
25
- async function scrollToBeginning(maxSwipes, steps) {
26
-
27
- try {
28
- console.log('Scrolling to beginning');
29
- await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollToBeginning(' + maxSwipes + ',' + steps + ')');
30
- await driver.pause(3000);
31
- console.log('Scrolled to beginning');
32
- } catch (error) {
33
- console.error(error.message);
34
- }
35
- }
36
- async function scrollRightToView(text) {
37
-
38
- try {
39
- console.log('Scrolling to right until text is found');
40
- await $('android=new UiScrollable(new UiSelector().scrollable(true)).setAsHorizontalList().scrollTextIntoView("' + text + '")');
41
- await driver.pause(3000);
42
- console.log('Scrolled to right completed');
43
- } catch (error) {
44
- console.error(error.message);
45
- }
46
- }
47
- async function scrollDownToView(text) {
48
-
49
- try {
50
- console.log('Scrolling down until text is found');
51
- await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollTextIntoView("' + text + '")');
52
- await driver.pause(3000);
53
- console.log('Scrolled down completed');
54
- } catch (error) {
55
- console.error(error.message);
56
- }
57
- }
58
- async function scrollToRight(steps) {
59
-
60
- try {
61
- console.log('Scrolling to right');
62
- await $('android=new UiScrollable(new UiSelector().scrollable(true)).scrollable.setAsHorizontalList().scrollForward(' + steps + ')');
63
- await driver.pause(3000);
64
- console.log('Scrolled to right');
65
- } catch (error) {
66
- console.error(error.message);
67
- }
68
- }
69
-
70
- async function scrollIntoView(element){
71
- try{
72
- const elem = await $(element);
73
- // scroll to specific element
74
- await elem.scrollIntoView();
75
- // center element within the viewport
76
- // await elem.scrollIntoView({ block: 'center', inline: 'center' });
77
-
78
- }catch(error){
79
- console.error(error.message);
80
- }
81
- }
82
-
83
- async function scrollupUntilVisible(selector) {
84
- const element = await $(selector);
85
-
86
- while (!(await element.isDisplayed())) {
87
- await driver.performActions([
88
- {
89
- type: 'pointer',
90
- id: 'finger1',
91
- parameters: { pointerType: 'touch' },
92
- actions: [
93
- { type: 'pointerMove', duration: 0, x: 200, y: 800 },
94
- { type: 'pointerDown', button: 0 },
95
- { type: 'pause', duration: 100 },
96
- { type: 'pointerMove', duration: 500, x: 200, y: 200 },
97
- { type: 'pointerUp', button: 0 }
98
- ]
99
- }
100
- ]);
101
- await browser.pause(500);
102
- }
103
- }
104
- module.exports = { scrollToEnd, scrollToLeft, scrollToBeginning, scrollRightToView, scrollDownToView, scrollToRight ,scrollIntoView,scrollupUntilVisible};
@@ -1,45 +0,0 @@
1
- async function STORETEXT(element, buffername) {
2
-
3
- try {
4
- let ele = await $(element);
5
- // Get the actual text from the specified attribute
6
- const actualText = await ele.getText();
7
- console.log('Text stored in buffer:', actualText);
8
- BUFFER.setItem(buffername, actualText);
9
-
10
- } catch (error) {
11
- console.log('Excption occured during storing the text into buffer', `${error.message}`);
12
- console.error(error.message);
13
- }
14
- }
15
-
16
- async function STOREVALUE(element, buffername) {
17
-
18
- try {
19
- let ele = await $(element);
20
- // Get the actual text from the specified attribute
21
- const actualText = await ele.getValue();
22
- console.log('Value stored in buffer:', actualText);
23
- BUFFER.setItem(buffername, actualText);
24
-
25
- } catch (error) {
26
- console.log('Excption occured during storing the value into buffer', `${error.message}`);
27
- console.error(error.message);
28
- }
29
- }
30
-
31
- async function STOREATTRIBUTEVALUE(element, attribute, buffername) {
32
-
33
- try {
34
- let ele = await $(element);
35
- // Get the actual text from the specified attribute
36
- const actualText = await ele.getAttribute(attribute);
37
- console.log('Attr value stored in buffer:', actualText);
38
- BUFFER.setItem(buffername, actualText);
39
-
40
- } catch (error) {
41
- console.log('Excption occured during storing the attribute value into buffer', `${error.message}`);
42
- console.error(error.message);
43
- }
44
- }
45
- module.exports = { STORETEXT, STOREVALUE, STOREATTRIBUTEVALUE };
@@ -1,36 +0,0 @@
1
- /**
2
- * Switches to a browser window/tab by its title using WebdriverIO.
3
- * @param {string} title - The title of the window/tab to switch to.
4
- */
5
- async function switch2WindowByTitle(title) {
6
- const handles = await browser.getWindowHandles();
7
- for (const handle of handles) {
8
- await browser.switchToWindow(handle);
9
- const currentTitle = await browser.getTitle();
10
- if (currentTitle === title) {
11
- return true; // Switched successfully
12
- }
13
- }
14
- throw new Error(`No window with title "${title}" found.`);
15
- }
16
-
17
- /**
18
- * Switches to a browser window/tab by its index using WebdriverIO.
19
- * @param {number} index - The index of the window/tab to switch to (0-based).
20
- */
21
- async function switch2WindowByIndex(index) {
22
- const handles = await browser.getWindowHandles();
23
- console.log(`Total open windows: ${handles.length}`);
24
- console.log(`Switching to window at index: ${index}`);
25
- console.log(`Available handles: ${handles.join(', ')}`);
26
- if (index < 0 || index >= handles.length) {
27
- throw new Error(`Invalid window index: ${index}. There are only ${handles.length} windows open.`);
28
- }
29
- await browser.switchToWindow(handles[index]);
30
- return true; // Switched successfully
31
- }
32
-
33
-
34
- // Example usage in a test
35
- // await switchToWindowByTitle('Your Window Title');
36
- module.exports = {switch2WindowByTitle,switch2WindowByIndex};