What you'll need
- You'll need a Mailosaur account. If you don’t already have one, just create a free trial account first.
- Log into your account and generate an API key as you will need this to run automated tests.
- Finally, make sure you know how to send emails (or SMS) into your account.
Express: Generate with a sample project
If you have npm installed, then the quickest way to get started is by generating a basic starter project for Selenium via the command line:
npm create mailosaur@latest
This will give you a simple Selenium project with Mailosaur already configured, along with some basic tests so you can see how a project would typically work. You can also check out similar sample code on GitHub.
Integrate with an existing Selenium project
If you have an existing Selenium project (or created one just now), here is how to install and configure Mailosaur's API client library:
Install the Mailosaur Java library
Gradle users can add this dependency to their project’s build file:
// MAILOSAUR_JAVA_VERSION available at:
// https://github.com/mailosaur/mailosaur-java/releases/latest)
implementation "com.mailosaur:mailosaur-java:MAILOSAUR_JAVA_VERSION"
Maven users should add this dependency to their project’s POM:
<dependency>
<groupId>com.mailosaur</groupId>
<artifactId>mailosaur-java</artifactId>
<version>MAILOSAUR_JAVA_VERSION</version>
</dependency>
If you don’t use Gradle or Maven, refer to the README within the GitHub repository.
Make your first API call
// Replace API_KEY with the one from your account
var mailosaur = new MailosaurClient("API_KEY");
// Make a simple API call to find the name of your inbox
var result = mailosaur.servers().list();
System.out.println("Inbox name is " + result.items().get(0).name());
Install the Mailosaur Python library
Run this command to install the Mailosaur Python package:
pip install mailosaur
Make your first API call
# Replace API_KEY with the one from your account
mailosaur = MailosaurClient("API_KEY")
# Make a simple API call to find the name of your inbox
result = mailosaur.servers().list()
print("Inbox name is " + result.items[0].name)
Install the Mailosaur .NET library
Run this command to install the Mailosaur NuGet package:
dotnet add package mailosaur
Make your first API call
// Replace API_KEY with the one from your account
var mailosaur = new MailosaurClient("API_KEY");
// Make a simple API call to find the name of your inbox
var result = mailosaur.Servers.List();
Console.WriteLine("Inbox name is " + result.Items[0].Name);
Install the Mailosaur Ruby library
Run this command to install the Mailosaur Ruby package:
gem install mailosaur
Make your first API call
# Replace API_KEY with the one from your account
mailosaur = Mailosaur::MailosaurClient.new("API_KEY")
# Make a simple API call to find the name of your inbox
result = mailosaur.servers().list()
puts("Inbox name is " + result.items[0].name)
Install the Mailosaur Node.js library
Use npm to install the Mailosaur Node.js library:
npm install mailosaur
Make your first API call
// Replace API_KEY with the one from your account
const MailosaurClient = require("mailosaur");
const mailosaur = new MailosaurClient("API_KEY");
// Make a simple API call to find the name of your inbox
const result = await mailosaur.servers().list();
console.log("Inbox name is " + result.items[0].name);
Start testing
Now that you have a project connected to the Mailosaur API, you can start creating all kinds of tests:
- Email testing - test password resets, account verification, order confirmations, etc.
- SMS testing - test alerts, notifications, and 2FA logins
- 2FA app testing - mimic the functionality of apps like Google Authenticator and 0Auth
- Email deliverability testing
Previous
Using Mailosaur with Selenium