Creating a Unique Email Address to Use in Selenium tests from Release Pipeline

Recently I needed to come up with a way to create a unique email address each time I run my Selenium tests. This is because I’m running Sign Up tests to ensure the Sign Up process works properly.

Since I’m using Azure DevOps Release Pipeline to run my tests, I thought I might be able to use a custom variable to increment an email address. Then I can pass the variable to my tests using .runsettings. I’m using Gmail for my testing, so creating a working, custom email address is fairly easy. I can just utilize their [email protected] functionality.

For those of you who aren’t familiar with + functionality within Gmail, you can actually add a + to the end of your email address. This way the email address looks different, but it actually goes to the same mailbox. For example, if you had an email address of [email protected], you can use [email protected] and still receive emails sent to the +whatever address.

I created a newEmailAddress variable in the Release Pipeline and just set it to some test email, the value doesn’t really matter, we’ll change it during our release.

In my Selenium code, I added three PowerShell scripts, one for each of my stages. The scripts look like this:

$release = $env:RELEASE_RELEASENAME; # Get the current release name from the Release Pipeline
$email = "tester+" + $release + "[email protected]"; # Create the email address
Write-Host "##vso[task.setvariable variable=newEmailAddress]$email"; # Set the Release Pipeline variable to the email address we want to use.

When the Release Pipeline runs, the PowerShell script runs as a task first. Now that the newEmailAddress variable is set to the email address we want to use, we can use this custom variable in our VS Test task. In the VS Test task, we pass this variable to our tests using the override test run parameters field. My parameter looks like this:

-newEmailAddress “$(newEmailAddress)”

The -newEmailAddress corresponds to the parameter I have outline in my .runsettings file. Then the following variable is our custom variable created in the Release Pipeline.

Now we can use this custom email address in our code!

Leave a Reply

Your email address will not be published. Required fields are marked *