Videos
Check out our tutorial video series.
End-to-End Testing User Sign-Up in .NET Core with Selenium and MailSlurp SDK
Selenium is a common integration test framework popular with C# developers. With the MailSlurp DotNet SDK you can send and receive emails from code and tests.
If you write .NET applications you probably deal with email addresses at some point: for user sign-up, email newsletters, password resets and more. If you want to test this functionality end-to-end you need test email accounts.
MailSlurp is a free API that lets you create email addresses in C# then send and receive emails with them. This article will show you how to test a web applications user sign-up using Nunit, .NET Core 2.1, Selenium and Firefox Gecko Driver.
For an example of using emails in selenium with .NET we will use a dummy web app hosted at https://playground.mailslurp.com.
This app has a real sign-up process. It lets users sign-up with an email address, then it sends them a confirmation code via email. The user can then submit the confirmation code and confirm their account. Finally the user can sign in and see a welcome screen.
We'll test this process end to end. Full source code available on GitHub.
To test the Playgrounds authentication process with real email addresses lets set up a .NET Core 2.1 project.
MailSlurp's CSharp Package on NuGet supports .Net Core 2.x and 3.x. If You need another target consider the REST API.
First you need Firefox and the Selenium Gecko Driver. You can install them with or download them manually and add them to your Path.
Create a new .NET Core project and add the following dependencies in :
Next create an Nunit test:
Next we need to configure Selenium. We will add a FirefoxDriver and tell it to start before our tests. Then we'll add a shutdown method after the tests have finished. Put the following inside the class:
Now we can write some tests. So let's load the playground app and click the sign-up button:
Next we need to start a user sign-up. We will need a new test email account first. Create one with MailSlurp then use it to fill the sign-up form:
If we run the test the result should look like this:
Once the sign-up form is submitted the playground app will send a confirmation code to the email address. We can wait for the email to arrive using MailSlurp.
Next let's find the verification code in the email and submit it to the confirmation screen:
Running the test should look as follows:
Finally we can test that a confirmed user can sign in. Load the playground again and sign in.
The login should look like this:
Once logged in the user will be greeted with a welcome message.
Selenium is a powerful testing tool. When combined with test email accounts you can test email related processes end-to-end. MailSlurp is free email API with C# bindings. Check out the documentation to get started.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.