froth-webdriverio-framework 4.0.6 → 4.0.8

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.
File without changes
@@ -20,6 +20,8 @@ let clickIfVisible = null;
20
20
  let doubleClick = null;
21
21
 
22
22
  let assertText = null;
23
+
24
+ let random = null;
23
25
  let randomtext = null;
24
26
  let randomnumber = null;
25
27
  let randomfloat = null;
@@ -27,6 +29,8 @@ let randomint = null;
27
29
  let randomalphanum = null;
28
30
  let randomdecimal = null;
29
31
  let randomregex = null;
32
+ let randomdate = null;
33
+
30
34
  let storetext = null;
31
35
  let storevalue = null;
32
36
  let storeattributevalue = null;
@@ -80,6 +84,8 @@ randomint = require(basepath + '/random').RNDINT;
80
84
  randomalphanum = require(basepath + '/random').RNDALPHANUM;
81
85
  randomdecimal = require(basepath + '/random').RNDDECIMAL;
82
86
  randomregex = require(basepath + '/random').RNDREGEX;
87
+ random= require(basepath + '/random').RANDOM;
88
+ randomdate= require(basepath + '/random').RNDDATE;
83
89
 
84
90
  storetext = require(basepath + '/storeToBuffer').STORETEXT;
85
91
  storevalue = require(basepath + '/storeToBuffer').STOREVALUE;
@@ -108,6 +114,7 @@ module.exports = {
108
114
  doubleClick,
109
115
  assertText,
110
116
  assertAttributeValue,
117
+ random,
111
118
  randomtext,
112
119
  randomnumber,
113
120
  randomfloat,
@@ -115,6 +122,7 @@ module.exports = {
115
122
  randomalphanum,
116
123
  randomdecimal,
117
124
  randomregex,
125
+ randomdate,
118
126
  storetext,
119
127
  storevalue,
120
128
  storeattributevalue,
@@ -135,11 +135,9 @@ async function validateAttributeData(attribute_name, attribute, buffer, bufferna
135
135
  valueToVerify = Number(valueToVerify);
136
136
  } else if (datatype.toLowerCase() == "boolean") {
137
137
  valueToVerify = Boolean(valueToVerify);
138
- } else if (datatype.toLowerCase() == "float") {
138
+ } else if (datatype.toLowerCase() == "decimal") {
139
139
  valueToVerify = parseFloat(valueToVerify);
140
- } else if (datatype.toLowerCase() == "double") {
141
- valueToVerify = parseFloat(valueToVerify);
142
- } else if (datatype.toLowerCase() == "string") {
140
+ }else if (datatype.toLowerCase() == "string") {
143
141
  valueToVerify = valueToVerify.toString();
144
142
  }
145
143
 
@@ -0,0 +1,72 @@
1
+ const RandExp = require('randexp');
2
+
3
+ async function RNDNUMBER(min, max) {
4
+ return Math.floor(Math.random() * (max - min + 1)) + min;
5
+ }
6
+
7
+ async function RNDFLOAT() {
8
+ return Math.random();
9
+ }
10
+
11
+ async function RNDINT() {
12
+ return Math.floor(Math.random() * 100000); // You can choose any large multiplier for bigger ranges
13
+ }
14
+
15
+ async function RNDNUMBER(length) {
16
+ if (length <= 0) return null; // Handle invalid length
17
+
18
+ const min = Math.pow(10, length - 1); // Minimum value for the given length
19
+ const max = Math.pow(10, length) - 1; // Maximum value for the given length
20
+
21
+ return Math.floor(Math.random() * (max - min + 1)) + min; // Generate the random number
22
+ }
23
+ async function RANDOMTEXT(length) {
24
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
25
+ let result = '';
26
+ for (let i = 0; i < length; i++) {
27
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
28
+ }
29
+ return result;
30
+ }
31
+
32
+ async function RNDALPHANUM(length) {
33
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
34
+ let result = '';
35
+ for (let i = 0; i < length; i++) {
36
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
37
+ }
38
+ return result;
39
+ }
40
+
41
+ async function RNDDECIMAL(min, max, decimalPlaces) {
42
+ let randomNum = Math.random() * (max - min) + min; // Generates a number between min and max
43
+ return parseFloat(randomNum.toFixed(decimalPlaces));
44
+ }
45
+
46
+ async function RNDDECIMAL(decimalPlaces) {
47
+ let randomNum = Math.random(); // Generates a number between 0 and 1
48
+ return parseFloat(randomNum.toFixed(decimalPlaces));
49
+ }
50
+
51
+ async function RNDREGEX(regex) {
52
+ return new RandExp(regex).gen();
53
+ }
54
+
55
+ module.exports = {
56
+ RNDNUMBER,
57
+ RNDFLOAT,
58
+ RNDINT,
59
+ RANDOMTEXT,
60
+ RNDALPHANUM,
61
+ RNDDECIMAL,
62
+ RNDREGEX
63
+ };
64
+
65
+ // console.log(RNDNUMBER(1, 100));
66
+ // console.log(RNDFLOAT());
67
+ // console.log(RNDINT());
68
+ // console.log(RANDOMTEXT(10));
69
+ // console.log(RNDALPHANUM(10));
70
+ // console.log(RNDDECIMAL(100, 10000, 4));
71
+ // console.log(RNDDECIMAL(2));
72
+ // console.log(RNDREGEX(/[a-z]{4}\d{4}/));
@@ -1,25 +1,33 @@
1
1
  const RandExp = require('randexp');
2
2
 
3
- async function RNDNUMBER(min, max) {
4
- return Math.floor(Math.random() * (max - min + 1)) + min;
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
+ }
5
18
  }
6
19
 
20
+ // Random floating-point number between 0 and 1
7
21
  async function RNDFLOAT() {
8
22
  return Math.random();
9
23
  }
10
24
 
25
+ // Random integer between 0 and 100000 (large multiplier range)
11
26
  async function RNDINT() {
12
- return Math.floor(Math.random() * 100000); // You can choose any large multiplier for bigger ranges
27
+ return Math.floor(Math.random() * 100000);
13
28
  }
14
29
 
15
- async function RNDNUMBER(length) {
16
- if (length <= 0) return null; // Handle invalid length
17
-
18
- const min = Math.pow(10, length - 1); // Minimum value for the given length
19
- const max = Math.pow(10, length) - 1; // Maximum value for the given length
20
-
21
- return Math.floor(Math.random() * (max - min + 1)) + min; // Generate the random number
22
- }
30
+ // Random text string of specified length
23
31
  async function RANDOMTEXT(length) {
24
32
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
25
33
  let result = '';
@@ -29,6 +37,7 @@ async function RANDOMTEXT(length) {
29
37
  return result;
30
38
  }
31
39
 
40
+ // Random alphanumeric string of specified length
32
41
  async function RNDALPHANUM(length) {
33
42
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
34
43
  let result = '';
@@ -38,20 +47,153 @@ async function RNDALPHANUM(length) {
38
47
  return result;
39
48
  }
40
49
 
41
- async function RNDDECIMAL(min, max, decimalPlaces) {
42
- let randomNum = Math.random() * (max - min) + min; // Generates a number between min and max
43
- return parseFloat(randomNum.toFixed(decimalPlaces));
44
- }
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;
45
61
 
46
- async function RNDDECIMAL(decimalPlaces) {
47
- let randomNum = Math.random(); // Generates a number between 0 and 1
48
- return parseFloat(randomNum.toFixed(decimalPlaces));
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
+ }
49
76
  }
50
77
 
78
+
79
+ // Random string based on regex pattern
51
80
  async function RNDREGEX(regex) {
52
81
  return new RandExp(regex).gen();
53
82
  }
54
83
 
84
+ async function RNDDATE(startYear = 1950, endYear = 2005, format = 'YYMMDD') {
85
+ // Generate a random year between startYear and endYear
86
+ const start = new Date(`${startYear}-01-01`).getTime();
87
+ const end = new Date(`${endYear}-12-31`).getTime();
88
+
89
+ const randomTimestamp = start + Math.random() * (end - start);
90
+ const randomDate = new Date(randomTimestamp);
91
+
92
+ return FORMATDATE(randomDate, format);
93
+ }
94
+
95
+ async function FORMATDATE(date, format) {
96
+ const yy = String(date.getFullYear()).slice(2);
97
+ const yyyy = String(date.getFullYear());
98
+ const mm = String(date.getMonth() + 1).padStart(2, '0');
99
+ const dd = String(date.getDate()).padStart(2, '0');
100
+
101
+ switch (format.toUpperCase()) {
102
+ case 'YYMMDD': return `${yy}${mm}${dd}`;
103
+ case 'DDMMYY': return `${dd}${mm}${yy}`;
104
+ case 'YYYYMMDD': return `${yyyy}${mm}${dd}`;
105
+ case 'DDMMYYYY': return `${dd}${mm}${yyyy}`;
106
+ case 'MMDDYY': return `${mm}${dd}${yy}`;
107
+ case 'MMDDYYYY': return `${mm}${dd}${yyyy}`;
108
+ case 'YYDDMM': return `${yy}${dd}${mm}`;
109
+ case 'YYYYDDMM': return `${yyyy}${dd}${mm}`;
110
+ default: return `${yy}${mm}${dd}`; // Fallback to YYMMDD
111
+ }
112
+ }
113
+ // Main function to process templates and replace placeholders with random values
114
+ async function RANDOM(template, datatype) {
115
+ const regex = /\{(.*?)\}/g;
116
+ let matches = [...template.matchAll(regex)];
117
+
118
+ // Iterate over all matches and replace them with the resolved values
119
+ let replacements = await Promise.all(matches.map(async (match) => {
120
+ const content = match[1]; // Get the content inside { ... }
121
+
122
+ const parts = content.split(/[\[\]]/).filter(Boolean); // Split by square brackets
123
+ const type = parts[0];
124
+
125
+ switch (type) {
126
+ case 'RND':
127
+ if (parts.length === 1) {
128
+ return await RNDNUMBER(); // {RND} - Default to 5-digit number
129
+ }
130
+ else if (parts.length === 2) {
131
+ return await RNDNUMBER(parseInt(parts[1])); // {RND[length]}
132
+ } else if (parts.length === 3) {
133
+ return await RNDNUMBER(parseInt(parts[1]), parseInt(parts[2])); // {RND[min][max]}
134
+ } else {
135
+ return await RNDNUMBER(); // {RND} - Default to 5-digit number
136
+ }
137
+ break;
138
+
139
+ case 'RNDDECIMAL':
140
+ console.log(parts);
141
+ if (parts.length === 3) {
142
+ return await RNDDECIMAL(parseInt(parts[1]), undefined, parseInt(parts[2])); // {RNDDECIMAL[length][decimalPlaces]}
143
+ } else if (parts.length === 4) {
144
+ return await RNDDECIMAL(parseInt(parts[1]), parseInt(parts[2]), parseInt(parts[3])); // {RNDDECIMAL[length][decimalPlaces]}
145
+ } else {
146
+ return await RNDDECIMAL(6, undefined, 2); // {RNDDECIMAL[length][decimalPlaces]}
147
+ }
148
+ break;
149
+
150
+ case 'RANDOMTEXT':
151
+ return await RANDOMTEXT(parseInt(parts[1])); // {RANDOMTEXT[length]}
152
+
153
+ case 'CTMSTMP':
154
+ return Date.now(); // Current timestamp
155
+
156
+ case 'RANDOMREGEX':
157
+ const regexString = content.match(/"(.+?)"/)?.[1];
158
+ return await RNDREGEX(regexString); // Generate random string based on regex
159
+ case 'RNDDATE':
160
+ return await RNDDATE(parseInt(parts[1]), parseInt(parts[2])); // Generate random date of birth
161
+ default:
162
+ return match[0]; // If no match found, return original template string
163
+ }
164
+ }));
165
+
166
+ // Replace all matches with their resolved values
167
+ let result = template;
168
+ matches.forEach((match, index) => {
169
+ result = result.replace(match[0], replacements[index]);
170
+ });
171
+ datatype = datatype.toLowerCase();
172
+
173
+ if (datatype == 'integer') {
174
+ result = parseInt(result);
175
+ }
176
+ else if (datatype == 'decimal') {
177
+ console.log("insude decimal");
178
+ result = parseFloat(result);
179
+ }
180
+ else if (datatype == 'string') {
181
+ result = result.toString();
182
+ }
183
+
184
+ return result;
185
+ }
186
+
187
+ // Example function to test the template replacement
188
+ async function main() {
189
+
190
+ let template = "SUBHRASUBUDHI {RNDDATE[1968][1970][yymmdd]} @GMAQIL.COM";
191
+ let result = await RANDOM(template, 'STRING');
192
+ console.log(result);
193
+ console.log(typeof result);
194
+ }
195
+
196
+ main();
55
197
  module.exports = {
56
198
  RNDNUMBER,
57
199
  RNDFLOAT,
@@ -59,14 +201,7 @@ module.exports = {
59
201
  RANDOMTEXT,
60
202
  RNDALPHANUM,
61
203
  RNDDECIMAL,
62
- RNDREGEX
63
- };
64
-
65
- // console.log(RNDNUMBER(1, 100));
66
- // console.log(RNDFLOAT());
67
- // console.log(RNDINT());
68
- // console.log(RANDOMTEXT(10));
69
- // console.log(RNDALPHANUM(10));
70
- // console.log(RNDDECIMAL(100, 10000, 4));
71
- // console.log(RNDDECIMAL(2));
72
- // console.log(RNDREGEX(/[a-z]{4}\d{4}/));
204
+ RNDREGEX,
205
+ RANDOM,
206
+ RNDDATE
207
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
 
5
5
  "readme": "WebdriverIO Integration",
6
6
  "description": "WebdriverIO and BrowserStack App Automate",