30 Days of Automation in Testing: Bonus Challenge


(Pablo) #1

The following is a simple solution that can be folded into your test scripts. It builds on the work of many others and has been confirmed to be working as desired. I tested it using a javascript framework:

Javascript customize to your heart’s content
var firstName = Math.random().toString(36).replace(/[^a-z]+/g, ‘’).substr(2, 3);
var lastName = Math.random().toString(36).replace(/[^a-z]+/g, ‘’).substr(2, 5);
var phoneLine = Math.random().toString().replace(‘0.’, ‘’).substr(0, 3);
var phoneExt = Math.random().toString().replace(‘0.’, ‘’).substr(0, 4);
var phoneNumber = ‘212’+phoneLine+phoneExt;
var auth_USN = ‘user_’+Math.random().toString().replace(‘0.’, ‘’).substr(0, 3);
var auth_PASS = ‘pAss’+Math.random().toString(36).replace(/[^a-z]+/g, ‘’).substr(0, 7)+’!@#’;
var auth_EMAIL = ‘tester’+Math.random().toString().replace(‘0.’, ‘’).substr(0, 4)+’@domain.com’;

JAVA

For Python - sub where necessary with the following:


(AMIT) #2

function generateRandomNumber($size) {
var $number = “”;
var $possible = “1234567890”;

	for (var $i = 0; $i < $size; $i++) {
		$number = $number + $possible.charAt(Math.floor(Math.random() * $possible.length));
	}
	return $number;
}

function generateRandomString($len) {
var $string = “”;
var $possible = “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz”;

	for (var $i = 0; $i < $len; $i++) {
		$string = $string + $possible.charAt(Math.floor(Math.random() * $possible.length));
	}

	return $string;
}

(Heather) #3