# 30 Days of Automation in Testing: Bonus Challenge

**URL:** <https://club.ministryoftesting.com/t/30-days-of-automation-in-testing-bonus-challenge/17194>\
**Category:** 30 Days of Testing\
**Tags:** 30-days-of-testing, automation\
**Created:** [28 July 2018 00:20 UTC](https://club.ministryoftesting.com/t/30-days-of-automation-in-testing-bonus-challenge/17194 "2018-07-28T00:20:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pabs616](https://sea2.discourse-cdn.com/flex020/user_avatar/club.ministryoftesting.com/pabs616/32/13139_2.png) [@pabs616](https://club.ministryoftesting.com/u/pabs616)\
**Post date:** [28 July 2018 00:20 UTC](https://club.ministryoftesting.com/t/30-days-of-automation-in-testing-bonus-challenge/17194/1 "2018-07-28T00:20:46Z")

</div>

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**

- Using Apache’s [RandomStringGenerator class](https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/RandomStringGenerator.html) swap out Math.random() … with the class, where applicable

**For Python** - sub where necessary with the following:

- ‘’.join(random.choices(string.ascii\_uppercase + string.digits, k=N))  
source: [Stack Overflow: Random string generation with upper case letters and digits in Python](https://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python)

---

<div class="post-metadata">

**Author:** ![amtoya](https://sea2.discourse-cdn.com/flex020/user_avatar/club.ministryoftesting.com/amtoya/32/3441_2.png) [@amtoya](https://club.ministryoftesting.com/u/amtoya)\
**Post date:** [30 July 2018 03:52 UTC](https://club.ministryoftesting.com/t/30-days-of-automation-in-testing-bonus-challenge/17194/2 "2018-07-30T03:52:27Z")

</div>

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;
}
```

---

<div class="post-metadata">

**Author:** ![heather\_reid](https://sea2.discourse-cdn.com/flex020/user_avatar/club.ministryoftesting.com/heather_reid/32/29_2.png) [@heather\_reid](https://club.ministryoftesting.com/u/heather_reid)\
**Post date:** [31 July 2018 15:53 UTC](https://club.ministryoftesting.com/t/30-days-of-automation-in-testing-bonus-challenge/17194/3 "2018-07-31T15:53:22Z")

</div>

> <https://twitter.com/ManukhinaDarya/status/1024251853029167104>
