Set up
Copy the helper, proxymail_qa.py, from the Python docs into your tests folder, and put an API key in PROXYMAIL_QA_API_KEY, in your shell, a .env file kept out of Git, or your CI’s secrets. The Free plan is enough.
The test
With Playwright for Python:
import re
from playwright.sync_api import Page, expect
from proxymail_qa import create_address, delete_address, now, wait_for_link
def test_sign_up_verifies_the_email(page: Page):
account = create_address()
page.goto("/signup")
page.get_by_label("Email").fill(account["address"])
page.get_by_label("Password").fill(account["password"])
submitted = now()
page.get_by_role("button", name="Sign up").click()
page.goto(wait_for_link(account["address"], since=submitted))
expect(page).to_have_url(re.compile("verified"))
delete_address(account["address"])
For a code, use wait_for_code(address, since=submitted) and type what it returns. With Selenium, the calls are the same: find the fields with driver.find_element and send the code or open the link. since makes the wait ignore anything sent before the form was submitted, so a retried test never reads an old email.
Check the email, not just the link
import time
from proxymail_qa import check_email, count_emails, now, wait_for_link
def test_sign_up_sends_one_good_verification_email(page, account):
submitted = now()
page.get_by_role("button", name="Sign up").click()
wait_for_link(account["address"], since=submitted)
time.sleep(10) # give a duplicate time to arrive
assert count_emails(account["address"], since=submitted, type="link")["count"] == 1
assert check_email(account["address"], since=submitted, expect_host="staging.example.com")["failed"] == []
check_email returns verdicts on SPF, DKIM and DMARC, links to localhost or plain http, where the link goes and more, never the email itself. expect_no_email checks that an action sends nothing, such as a second reset request that should be refused.
Run it in CI, with a report on the pull request
Import the helper’s pytest hooks in conftest.py. In GitHub Actions, add the Proxy Mail QA action before the tests: the report on the pull request then says which test each email came from, and lists the failed tests with what their emails did.
from proxymail_qa import pytest_runtest_setup, pytest_runtest_teardown, pytest_runtest_logreport, pytest_sessionfinish
- uses: aaquib90/proxymail-qa-action@v1
with:
api-key: ${{ secrets.PROXYMAIL_QA_API_KEY }}
- run: pytest
env:
PROXYMAIL_QA_API_KEY: ${{ secrets.PROXYMAIL_QA_API_KEY }}
The hooks do nothing outside a run, and never fail your tests themselves. More in the Python docs and Running in CI.