froth-webdriverio-framework 4.0.6 → 4.0.7
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;
|
|
@@ -80,6 +82,7 @@ randomint = require(basepath + '/random').RNDINT;
|
|
|
80
82
|
randomalphanum = require(basepath + '/random').RNDALPHANUM;
|
|
81
83
|
randomdecimal = require(basepath + '/random').RNDDECIMAL;
|
|
82
84
|
randomregex = require(basepath + '/random').RNDREGEX;
|
|
85
|
+
random= require(basepath + '/random').RANDOM;
|
|
83
86
|
|
|
84
87
|
storetext = require(basepath + '/storeToBuffer').STORETEXT;
|
|
85
88
|
storevalue = require(basepath + '/storeToBuffer').STOREVALUE;
|
|
@@ -108,6 +111,7 @@ module.exports = {
|
|
|
108
111
|
doubleClick,
|
|
109
112
|
assertText,
|
|
110
113
|
assertAttributeValue,
|
|
114
|
+
random,
|
|
111
115
|
randomtext,
|
|
112
116
|
randomnumber,
|
|
113
117
|
randomfloat,
|
|
@@ -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
|
-
|
|
4
|
-
|
|
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);
|
|
27
|
+
return Math.floor(Math.random() * 100000);
|
|
13
28
|
}
|
|
14
29
|
|
|
15
|
-
|
|
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,128 @@ async function RNDALPHANUM(length) {
|
|
|
38
47
|
return result;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
async function RNDDECIMAL(
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
// Main function to process templates and replace placeholders with random values
|
|
85
|
+
async function RANDOM(template,datatype) {
|
|
86
|
+
const regex = /\{(.*?)\}/g;
|
|
87
|
+
let matches = [...template.matchAll(regex)];
|
|
88
|
+
|
|
89
|
+
// Iterate over all matches and replace them with the resolved values
|
|
90
|
+
let replacements = await Promise.all(matches.map(async (match) => {
|
|
91
|
+
const content = match[1]; // Get the content inside { ... }
|
|
92
|
+
|
|
93
|
+
const parts = content.split(/[\[\]]/).filter(Boolean); // Split by square brackets
|
|
94
|
+
const type = parts[0];
|
|
95
|
+
|
|
96
|
+
switch (type) {
|
|
97
|
+
case 'RND':
|
|
98
|
+
if (parts.length === 1) {
|
|
99
|
+
return await RNDNUMBER(); // {RND} - Default to 5-digit number
|
|
100
|
+
}
|
|
101
|
+
else if (parts.length === 2) {
|
|
102
|
+
return await RNDNUMBER(parseInt(parts[1])); // {RND[length]}
|
|
103
|
+
} else if (parts.length === 3) {
|
|
104
|
+
return await RNDNUMBER(parseInt(parts[1]), parseInt(parts[2])); // {RND[min][max]}
|
|
105
|
+
} else {
|
|
106
|
+
return await RNDNUMBER(); // {RND} - Default to 5-digit number
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
case 'RNDDECIMAL':
|
|
111
|
+
console.log(parts);
|
|
112
|
+
if (parts.length === 3) {
|
|
113
|
+
return await RNDDECIMAL(parseInt(parts[1]), undefined, parseInt(parts[2])); // {RNDDECIMAL[length][decimalPlaces]}
|
|
114
|
+
} else if (parts.length === 4) {
|
|
115
|
+
return await RNDDECIMAL(parseInt(parts[1]), parseInt(parts[2]), parseInt(parts[3])); // {RNDDECIMAL[length][decimalPlaces]}
|
|
116
|
+
} else {
|
|
117
|
+
return await RNDDECIMAL(6, undefined, 2); // {RNDDECIMAL[length][decimalPlaces]}
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
case 'RANDOMTEXT':
|
|
122
|
+
return await RANDOMTEXT(parseInt(parts[1])); // {RANDOMTEXT[length]}
|
|
123
|
+
|
|
124
|
+
case 'CTMSTMP':
|
|
125
|
+
return Date.now(); // Current timestamp
|
|
126
|
+
|
|
127
|
+
case 'RANDOMREGEX':
|
|
128
|
+
const regexString = content.match(/"(.+?)"/)?.[1];
|
|
129
|
+
return await RNDREGEX(regexString); // Generate random string based on regex
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
return match[0]; // If no match found, return original template string
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
// Replace all matches with their resolved values
|
|
137
|
+
let result = template;
|
|
138
|
+
matches.forEach((match, index) => {
|
|
139
|
+
result = result.replace(match[0], replacements[index]);
|
|
140
|
+
});
|
|
141
|
+
datatype = datatype.toLowerCase();
|
|
142
|
+
|
|
143
|
+
if(datatype == 'integer'){
|
|
144
|
+
result = parseInt(result);
|
|
145
|
+
}
|
|
146
|
+
else if(datatype == 'decimal'){
|
|
147
|
+
console.log("insude decimal");
|
|
148
|
+
result = parseFloat(result);
|
|
149
|
+
}
|
|
150
|
+
else if(datatype == 'string'){
|
|
151
|
+
result = result.toString();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Example function to test the template replacement
|
|
158
|
+
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');
|
|
167
|
+
console.log(result);
|
|
168
|
+
console.log(typeof result);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
main();
|
|
55
172
|
module.exports = {
|
|
56
173
|
RNDNUMBER,
|
|
57
174
|
RNDFLOAT,
|
|
@@ -59,14 +176,6 @@ module.exports = {
|
|
|
59
176
|
RANDOMTEXT,
|
|
60
177
|
RNDALPHANUM,
|
|
61
178
|
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}/));
|
|
179
|
+
RNDREGEX,
|
|
180
|
+
RANDOM
|
|
181
|
+
};
|