Getting Started with Robot Framework
Learn how to automate email testing in Robot Framework
Mailosaur makes it easy to test emails and SMS messages using Robot Framework (for example when automating email verification and password reset workflows).
This page provides a very basic example of how to get up and running with Robot Framework.
Step 1: Create a helper class
First, we need to create a helper class, which we’ll name Mailosaur.py
. Having this file allows us to write helper methods, which exposes the functionality of the official Mailosaur client library as keywords within Robot Framework tests:
from mailosaur import MailosaurClient
from mailosaur.models import SearchCriteria
class Mailosaur(object):
def __init__(self, api_key):
self.client = MailosaurClient(api_key)
def generate_email_address(self, server_id):
return self.client.servers.generate_email_address(server_id)
def get_email(self, server_id, email_address):
criteria = SearchCriteria()
criteria.sent_to = email_address
return self.client.messages.get(server_id, criteria)
def subject_should_equal(self, message, expected):
assert(message.subject == expected)
You can of course continue to write as many helper methods as you need for your test suite.
Step 2: Use Mailosaur in your Robot Framework tests
Now we can use the helper methods we created above in our Robot Framework tests. Simply include Mailosaur.py
as a Library, being sure to pass in your API key (see our quick start guide for more information on where to find this):
*** Settings ***
Library SeleniumLibrary
Library Mailosaur.py <<API_KEY>>
*** Variables ***
${SERVER_ID} <<SERVER_ID>>
${SIGNUP_URL} https://yoursite.com/signup/
*** Test Cases ***
Test Sign Up Email
Sign Up New User
*** Keywords ***
Sign Up New User
${RANDOM_EMAIL}= Mailosaur.generate_email_address ${SERVER ID}
Open Browser ${SIGNUP URL}
Input Text name:name Jane Doe
Input Text name:email ${RANDOM_EMAIL}
Input Text name:password Password123!
Click Button css:.btn-primary
${MESSAGE}= Mailosaur.fetch_email ${SERVER ID} ${RANDOM_EMAIL}
Mailosaur.subject_should_equal ${MESSAGE} Thanks for joining!
[Teardown] Close Browser