Videos
Check out our tutorial video series.
Testing web app user sign up with TestNG and MailSlurp: a Java-based end-to-end test suite using real email addresses for authentication.
TestNG is a popular Java test framework that can be used with Selenium and MailSlurp to test web applications end to end. In this example we will use MailSlurp test email accounts to test a demo application sign up process end to end using real email addresses.
The full code for the example can be found on GitHub. See the MailSlurp JavaDocs site for more information.
For this example we will use a React App hosting at playground.mailslurp.com. The app has a typical user sign authentication flow:
We will use MailSlurp to create a test email account for the user and sign-up using Selenium. A successful sign-up and login results in a happy dog being displayed to the user.
Create a new directory and add the following :
Install the dependencies with . This will install TestNG, Selenium, and MailSlurp. MailSlurp is free to use - you just need to an API Key. Get an API Key from the MailSlurp dashboard by creating an account.
Now time to write some tests. Create directories. We will use
for this demo. Then create a test class:
Selenium requires a webdriver to run tests in a browser. We will use a Makefile to download a FireFox (Geckodriver) webdriver and pass the location to our tests with an environment variable.
Run to install the driver locally on a linux machine. Next let's set up a
method to initialize the driver with selenium.
Let's also add an method to close the webdriver when finished:
First step: load the MailSlurp playground app.
Click the sign up button to begin a user sign up.
Now we can create a test email address for the user using MailSlurp and sign up with it in the Playground.
You can wait for the confirmation email to arrive for the user by using the WaitForControllerApi methods. We expect the user's email address to receive a confirmation code.
We can use a regex pattern to extract the verification code from the email body.
Now that we have the confirmation code we can use Selenium to submit the code.
For the final step sign in using the email address and password that we verified.
When successful we will see a nice dog.
TestNG is a great framework for testing end-to-end with Selenium and Java. You can use MailSlurp to create real test email accounts. You can test user actions like user sign-up and account verification using real email addresses. Try it out for free today.
Find the full code on example.
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.