[eggPlant Functional] Dynamic File with Random Content

The below script dynamically generates a file at run time with randomly generated content. The content includes random customer ID numbers, names, and email addresses. This approach can be used to create many different kinds of random data for randomized testing purposes.

//THIS SCRIPT CREATES A FILE WITH DYNAMICALLY GENERATED RANDOM CONTENT\\
//--The file is going to contain a column of customer ID numbers, a column of customer names, and a column of email addresses, all dynamically generated during the script run--\\


//Create Random File Contents
Put 20 into numberofRecords -- define the number of records you want to create

Repeat numberofRecords times -- repeat the nubmer of times you want rows in your file
	//Create Customer ID by Calling Handler
	put createID() & comma into Row
	
	//Create Customer Name by Calling Handler
	put createName() & comma after Row
	
	//Create Customer Email by Calling Handler
	put createEmail() after Row
	
	//Add Row to File
	put row & return after FileContents
end repeat

//Create File and Store the Created Content in it
Put "~/Temp/CustomerEmail.txt" into myFile -- specify a location on the eggPlant system for the file to be created
put "ID,Name,Email" & return into HeaderRow -- create a header row for the file
put HeaderRow before FileContents -- insert the header row before the previously created content
put fileContents into file myFile -- insert the contents into the file, located on the eggPlant system


//FUNCTIONS AND HANDLERS GO AT THE BOTTOM OF THE SCRIPT\\

//Create Customer ID
to createID
	put random(100000,999999) into customerID -- use the Random function to create the numbers for the ID
	put "-" after character 2 of customerID -- put the ID in the correct format by inserting a dash
	return customerID -- return the newly created customer ID to the calling handler
end createID


//Generate Random Names for File
to createName
	put a..z into Letters -- store the alphabet in a variable using a range
	put random(5,10) into NewNameLength -- use the Random function to randomly select a name length
	repeat newNameLength times -- repeat for each character in the new customer name
		put any item of letters after NewName -- create a new name using random letters
	end repeat
	return Capitalized(NewName) -- Capitalize the new customer name and return it to the calling handler
end createName


//Dynamically Create Random Email Addresses
to createEmail
	insert (".com",".net",".org") into ListOfEnds
	set Part1 to (any item of a..z for each item of 1..6) joined by empty -- make a random first half
	set Part2 to (any item of 1..9 for each item of 1..6) joined by empty -- make a random second half
	set EmailEnd to any item of ListOfEnds -- choose a random ending
	put Part1 & "@" & Part2 & EmailEnd into DynamicAddress -- Compile the email address
	Return DynamicAddress -- return the address to the calling handler
end createEmail