How to Generate Parameterized Email Addresses for Your Test Runs with BlazeData
In this blog post I would like to show you a very fundamental functionality we have in BlazeData: the ability to reference parameters inside other parameters, to create email addresses. In other words, this means you can use the value of one parameter, to generate another parameter: the email address. This will help you quickly generate valid emails for your software tests.
Let's see some examples of how it works.
Use Case 1: Generating an Email Address from Parameters
Let’s say I would like to use an email address in my test and I want BlazeData to generate one for me.
We will divide the email value into several standalone values - the first name, the last name and the domain name. This is the best way to keep my data model clean and easy to read.
So I have defined these three params:
Firstname - randFromSeedlist("firstnames")
Lastname - randFromSeedlist("lastnames")
Domain - "acme.com"
As you can see, I used the randFromSeedlist function, which returns a random value from a stored list.
Pro tip #1: In BlazeData, we provide several seedlists out of the box.
Now we can take these parameters and put them together into an email address.
Email - $Firstname + "." + $Lastname + "@" + $Domain
Prop tip #2:: You can always hit ‘preview’ to see what your value will look like before generating it.
Pro tip #3: You can add the "." separator into a standalone parameter if you know you will be changing it. Then it would look like this:
Separator - “.”
Email - $Firstname + $Separator + $Lastname + "@" + $Domain
Use Case 2: Generating an Email Address Without Spaces
With the replacement function our parameters will look like this:
Firstname - randFromSeedlist("firstnames").replace(" ", ".")
Lastname - randFromSeedlist("lastnames").replace(" ", ".")
Use Case 3: Regular Expressions
The replacement function from before can also work with regular expressions, which are more powerful and can perform multiple actions at once. We can leverage this capability: instead of replacing one space occurrence in each parameter, we can replace all occurrences in the email address at once. It will look like this:
Email - ($Firstname + "."+ $Lastname + "@" + $Domain).replace(/ /g, ".")
This final statement provides quite a robust way to generate nice and valid email addresses.
That’s it! This is everything I want to show you today. Now you know how to parameterize your tests and how to link parameters inside another parameter which brings you much better flexibility during creating your tests.
To get started with BlazeMeter, sign up for free here.