MailFlatDocs
Documentation/Test frameworks & CI/Robot Framework

Using MailFlat with Robot Framework

Wrap the Python client in a small keyword library and your suites get New Inbox and Wait For Otp as ordinary Robot keywords.

How it fits together

Robot Framework talks to Python, and our Python client is two calls, so the library file is short. Once it exists, the suite reads like every other Robot suite.

The keyword library

One Python file, three keywords.
Python
# MailFlatLibrary.py
import os, uuid
from mailflat import MailFlat
 
class MailFlatLibrary:
def __init__(self):
self._mf = MailFlat(api_key=os.environ["MAILFLAT_API_KEY"])
self._inbox = None
 
def new_inbox(self):
self._inbox = self._mf.create(
prefix=f"robot-{uuid.uuid4().hex[:8]}", retention_hours=2
)
return self._inbox.address
 
def wait_for_otp(self, timeout=60):
return self._inbox.wait_for_otp(timeout=int(timeout))
 
def delete_inbox(self):
if self._inbox:
self._inbox.delete()
self._inbox = None

The suite

Robot converts method names to keywords: new_inbox becomes New Inbox.
Robot Framework
*** Settings ***
Library SeleniumLibrary
Library MailFlatLibrary
Test Teardown Delete Inbox
 
*** Test Cases ***
User Can Sign Up With A Real Code
${address}= New Inbox
Go To https://staging.example.com/signup
Input Text id:email ${address}
Click Button id:submit
 
${otp}= Wait For Otp 60
Input Text id:code ${otp}
Location Should Contain /dashboard

Worth knowing

Library scope defaults to per-suite. Use ROBOT_LIBRARY_SCOPE = 'TEST' if you want a fresh inbox per test case.