froth-webdriverio-framework 4.0.7 → 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.
@@ -29,6 +29,8 @@ let randomint = null;
29
29
  let randomalphanum = null;
30
30
  let randomdecimal = null;
31
31
  let randomregex = null;
32
+ let randomdate = null;
33
+
32
34
  let storetext = null;
33
35
  let storevalue = null;
34
36
  let storeattributevalue = null;
@@ -83,6 +85,7 @@ randomalphanum = require(basepath + '/random').RNDALPHANUM;
83
85
  randomdecimal = require(basepath + '/random').RNDDECIMAL;
84
86
  randomregex = require(basepath + '/random').RNDREGEX;
85
87
  random= require(basepath + '/random').RANDOM;
88
+ randomdate= require(basepath + '/random').RNDDATE;
86
89
 
87
90
  storetext = require(basepath + '/storeToBuffer').STORETEXT;
88
91
  storevalue = require(basepath + '/storeToBuffer').STOREVALUE;
@@ -119,6 +122,7 @@ module.exports = {
119
122
  randomalphanum,
120
123
  randomdecimal,
121
124
  randomregex,
125
+ randomdate,
122
126
  storetext,
123
127
  storevalue,
124
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
 
@@ -60,11 +60,11 @@ async function RNDDECIMAL(minOrLength, max, decimalPlaces) {
60
60
  let integerPart = 0;
61
61
 
62
62
  if (integerLength > 0) {
63
- const minInt = Math.pow(10, integerLength - 1);
64
- const maxInt = Math.pow(10, integerLength) - 1;
63
+ const minInt = Math.pow(10, integerLength - 1);
64
+ const maxInt = Math.pow(10, integerLength) - 1;
65
65
 
66
- // Generate the integer part
67
- integerPart = Math.floor(Math.random() * (maxInt - minInt + 1)) + minInt;
66
+ // Generate the integer part
67
+ integerPart = Math.floor(Math.random() * (maxInt - minInt + 1)) + minInt;
68
68
  }
69
69
  // Generate the decimal part
70
70
  const decimalFactor = Math.pow(10, decimalPlaces);
@@ -81,8 +81,37 @@ async function RNDREGEX(regex) {
81
81
  return new RandExp(regex).gen();
82
82
  }
83
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
+ }
84
113
  // Main function to process templates and replace placeholders with random values
85
- async function RANDOM(template,datatype) {
114
+ async function RANDOM(template, datatype) {
86
115
  const regex = /\{(.*?)\}/g;
87
116
  let matches = [...template.matchAll(regex)];
88
117
 
@@ -127,7 +156,8 @@ async function RANDOM(template,datatype) {
127
156
  case 'RANDOMREGEX':
128
157
  const regexString = content.match(/"(.+?)"/)?.[1];
129
158
  return await RNDREGEX(regexString); // Generate random string based on regex
130
-
159
+ case 'RNDDATE':
160
+ return await RNDDATE(parseInt(parts[1]), parseInt(parts[2])); // Generate random date of birth
131
161
  default:
132
162
  return match[0]; // If no match found, return original template string
133
163
  }
@@ -139,31 +169,26 @@ async function RANDOM(template,datatype) {
139
169
  result = result.replace(match[0], replacements[index]);
140
170
  });
141
171
  datatype = datatype.toLowerCase();
142
-
143
- if(datatype == 'integer'){
172
+
173
+ if (datatype == 'integer') {
144
174
  result = parseInt(result);
145
175
  }
146
- else if(datatype == 'decimal'){
176
+ else if (datatype == 'decimal') {
147
177
  console.log("insude decimal");
148
178
  result = parseFloat(result);
149
179
  }
150
- else if(datatype == 'string'){
180
+ else if (datatype == 'string') {
151
181
  result = result.toString();
152
182
  }
153
-
183
+
154
184
  return result;
155
185
  }
156
186
 
157
187
  // Example function to test the template replacement
158
188
  async function main() {
159
- // let template = "DEMO{RND[5][90]}-{CTMSTMP}-{RND[10]}-SUBHRA{RANDOMTEXT[9]}";
160
- // let result = await RANDOM(template);
161
- // console.log(result); // Example output: "DEMO12345-1617973448012-987654321-SuKbLfGHi"
162
- // template = "{RNDDECIMAL[2][10][3]} - {RNDDECIMAL[4][3]}";
163
- // result = await RANDOM(template);
164
- // console.log(result);
165
- template = "{RNDDECIMAL[4][3]}";
166
- result = await RANDOM(template,'decimal');
189
+
190
+ let template = "SUBHRASUBUDHI {RNDDATE[1968][1970][yymmdd]} @GMAQIL.COM";
191
+ let result = await RANDOM(template, 'STRING');
167
192
  console.log(result);
168
193
  console.log(typeof result);
169
194
  }
@@ -177,5 +202,6 @@ module.exports = {
177
202
  RNDALPHANUM,
178
203
  RNDDECIMAL,
179
204
  RNDREGEX,
180
- RANDOM
205
+ RANDOM,
206
+ RNDDATE
181
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "froth-webdriverio-framework",
3
- "version": "4.0.7",
3
+ "version": "4.0.8",
4
4
 
5
5
  "readme": "WebdriverIO Integration",
6
6
  "description": "WebdriverIO and BrowserStack App Automate",