qe-fe-automation
Version:
FE test automation framework using cypress
27 lines (22 loc) • 870 B
text/typescript
import crypto = require('crypto');
export class Random {
static randomString(length = 6): string {
return crypto.randomBytes(length).toString('hex').slice(0, length);
}
static getRandomValueFromArray<T>(array: T[]): T {
const randomArrayIndex = Math.floor(Math.random() * array.length);
return array[randomArrayIndex];
}
static getTwoUniqueRandomValueFromArray<T>(array: T[]): [T, T] {
const firstLocation = this.getRandomValueFromArray(array);
let secondLocation = this.getRandomValueFromArray(array);
while (firstLocation === secondLocation) {
secondLocation = this.getRandomValueFromArray(array);
}
return [firstLocation, secondLocation];
}
static getRandomValueFrom2DArray<T>(array: T[][]): T[] {
const randomArrayIndex = Math.floor(Math.random() * array.length);
return array[randomArrayIndex];
}
}