Private by design. No sign-up, no personal data.
See plans
TempifyTempify

Working test, run November 25, 2026

Temp mail for Selenium: test signups with a disposable inbox

By Waqar Habib Khan | Published 2026-11-25 | The test below was executed locally before this page shipped

Quick answer

How do I use temp mail in a Selenium test?

Create a fresh Tempify inbox with POST /api/v1/inbox, fill the signup form with that address, wait for the verification mail with GET /api/v1/inbox/{address}/wait, read the extracted code from GET /api/v1/inbox/{address}/otp, enter it, and assert success. The full working test is on this page, and it runs with one environment variable: TEMPIFY_API_KEY.
  • One inbox per test run: runs never share state and never flake on each other.
  • One long-poll instead of a polling loop: the wait call counts as one API call.
  • Needs a Premium, Developer, or Business API key: the Free plan returns 402.

How the test works

1. Create a fresh inbox. The test POSTs to /api/v1/inbox with fetch and gets a random address back, plus its expiry. It asserts the address matches the expected shape and expires in the future, so a broken API response fails fast instead of failing later at the form.

2. Prove the inbox starts empty. It calls the OTP endpoint before any mail exists. The endpoint answers 200 with message: null, which tells the test that empty inboxes are normal and distinct from a missing inbox (404).

3. Sign up. Selenium opens the signup URL in headless Chrome, types the disposable address into the email field, and submits. The URL and the selectors all come from environment variables, so the same test runs against staging and production.

4. Wait, then read the code. The wait endpoint holds the request for up to 55 seconds until the verification mail lands. Then the OTP endpoint returns the code the server extracted from the message, so the test never parses an email body itself.

5. Enter the code and assert. The test types the code, clicks the visible submit button, and waits for the success text. The inbox is never reused: the next run creates its own.

The full test

Save it as temp-mail-selenium.test.mjs, or download the same file here: temp-mail-selenium.test.mjs. It was executed locally on November 25, 2026 with Node 24 and selenium-webdriver against a stub that mirrors the real endpoint paths, status codes, and JSON shapes, with a fake signup page that sends a real verification code through the same flow; the live endpoints were probed the same day and return the documented 401 responses without a key. It has not been run end to end against the live API with a paid key in this environment, because no paid-plan key exists here: the first run with a real key is yours, and the test is written to make that run the same as the local one.

temp-mail-selenium.test.mjs

import test from "node:test";
import assert from "node:assert/strict";
import { Builder, By, until } from "selenium-webdriver";
import chrome from "selenium-webdriver/chrome.js";

const API_BASE = (process.env.TEMPIFY_API_BASE ?? "https://tempify.org/api/v1").replace(
  /\/$/,
  "",
);
const API_KEY = process.env.TEMPIFY_API_KEY ?? "";
const SIGNUP_URL = process.env.SIGNUP_URL ?? "";
const EMAIL_SELECTOR = process.env.SIGNUP_EMAIL_SELECTOR ?? 'input[type="email"]';
const SUBMIT_SELECTOR =
  process.env.SIGNUP_SUBMIT_SELECTOR ?? 'button[type="submit"]';
const CODE_SELECTOR = process.env.SIGNUP_CODE_SELECTOR ?? 'input[name="code"]';
const SUCCESS_TEXT = process.env.SIGNUP_SUCCESS_TEXT ?? "Welcome";

async function api(path, options = {}) {
  const res = await fetch(`${API_BASE}/${path.replace(/^\//, "")}`, {
    ...options,
    headers: { "x-api-key": API_KEY, ...(options.headers ?? {}) },
  });
  return { status: res.status, body: await res.json() };
}

test(
  "temp mail signup: create inbox, sign up, wait for code, assert",
  { skip: !API_KEY, timeout: 120_000 },
  async () => {
    // 1. Create a fresh inbox for this test run only.
    const created = await api("inbox", {
      method: "POST",
      headers: { "content-type": "application/json" },
      body: "{}",
    });
    assert.equal(created.status, 201, "create inbox");
    const address = created.body.inbox.address;
    assert.match(address, /^[a-z0-9._-]+@[a-z0-9.-]+$/);
    assert.ok(new Date(created.body.inbox.expires_at).getTime() > Date.now());

    // The inbox starts empty: the OTP endpoint answers 200 with no message.
    const empty = await api(`inbox/${encodeURIComponent(address)}/otp`);
    assert.equal(empty.status, 200, "otp on empty inbox");
    assert.equal(empty.body.message, null);

    if (!SIGNUP_URL) {
      // No app under test configured: prove the wait primitive works and stop.
      // A 10 second wait on an inbox nobody mails to times out cleanly.
      const waited = await api(
        `inbox/${encodeURIComponent(address)}/wait?timeout=10`,
      );
      assert.equal(waited.status, 200, "wait for mail");
      assert.equal(waited.body.timed_out, true);
      assert.deepEqual(waited.body.messages, []);
      return;
    }

    const chromeOptions = new chrome.Options().addArguments(
      "--headless=new",
      "--no-sandbox",
      "--disable-dev-shm-usage",
    );
    if (process.env.SELENIUM_CHROME_BINARY) {
      chromeOptions.setChromeBinaryPath(process.env.SELENIUM_CHROME_BINARY);
    }
    const driver = await new Builder()
      .forBrowser("chrome")
      .setChromeOptions(chromeOptions)
      .build();
    try {
      // 2. Sign up with the disposable address.
      await driver.get(SIGNUP_URL);
      await driver.findElement(By.css(EMAIL_SELECTOR)).sendKeys(address);
      await driver.findElement(By.css(SUBMIT_SELECTOR)).click();

      // 3. Wait for the verification mail (long-poll: one API call, up to 55s).
      const arrived = await api(
        `inbox/${encodeURIComponent(address)}/wait?timeout=55`,
      );
      assert.equal(arrived.status, 200, "wait for verification mail");
      assert.equal(arrived.body.timed_out, false, "verification mail arrived");
      assert.ok(arrived.body.messages.length > 0);

      // 4. Read the code the server extracted from the latest message.
      const otp = await api(`inbox/${encodeURIComponent(address)}/otp`);
      assert.equal(otp.status, 200, "read otp");
      assert.match(otp.body.otp, /^\d{4,8}$/, "verification code extracted");

      // 5. Enter the code and assert the signup completed. Re-query for the
      // submit buttons and click the visible one: many signup flows hide
      // the first form after submit, so the first matching button in the
      // DOM may be hidden. (Selenium uses the browser's native selector
      // engine, so the jQuery-style :visible pseudo-class Cypress accepts
      // is not valid here; filter with isDisplayed() instead.)
      await driver.findElement(By.css(CODE_SELECTOR)).sendKeys(otp.body.otp);
      const submitButtons = await driver.findElements(
        By.css(SUBMIT_SELECTOR),
      );
      const visible = [];
      for (const button of submitButtons) {
        if (await button.isDisplayed()) visible.push(button);
      }
      await visible[0].click();
      await driver.wait(
        until.elementLocated(By.xpath(`//*[contains(text(), '${SUCCESS_TEXT}')]`)),
        10_000,
      );
    } finally {
      await driver.quit();
    }
  },
);

Run it

The test skips itself with a clear message when TEMPIFY_API_KEY is not set, instead of failing with a confusing 401. Without SIGNUP_URL it runs the inbox half of the flow only: create, prove empty, and prove the wait times out cleanly on an inbox nobody mails to. That is the fastest way to check your key and the API wiring before pointing the test at a real signup form. The browser half needs Chrome: Selenium Manager downloads the matching ChromeDriver for you, and if Chrome is not on your PATH, set SELENIUM_CHROME_BINARY to its location.

Run locally

npm install selenium-webdriver

TEMPIFY_API_KEY=your_key SIGNUP_URL=https://example.com/signup \
  node --test temp-mail-selenium.test.mjs

# Against staging, with custom selectors:
TEMPIFY_API_KEY=your_key \
  SIGNUP_URL=https://staging.example.com/signup \
  SIGNUP_SUCCESS_TEXT="Check your inbox" \
  node --test temp-mail-selenium.test.mjs

Run it in CI (GitHub Actions)

Store the key as a repository secret called TEMPIFY_API_KEY and the signup URL as a variable called SIGNUP_URL. Never commit a key to the repository: a key in git history is a key anyone can use against your monthly allowance.

GitHub Actions

name: signup tests
on:
  push:
    branches: [main]
jobs:
  signup:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - uses: browser-actions/setup-chrome@v1
      - run: npm ci
      - run: node --test temp-mail-selenium.test.mjs
        env:
          TEMPIFY_API_KEY: ${{ secrets.TEMPIFY_API_KEY }}
          SIGNUP_URL: ${{ vars.SIGNUP_URL }}

The API calls behind the test

Three inbox endpoints do all the work. The full reference, with error codes, rate limit headers, and the OpenAPI spec, is on the temporary email API page.

CallWhat the test uses it forCost
POST /api/v1/inboxCreate one inbox per run1 call
GET /api/v1/inbox/{address}/waitHold until the verification mail arrives (up to 55s)1 call, however long it holds
GET /api/v1/inbox/{address}/otpRead the server-extracted code1 call

A full run costs 3 to 4 API calls, so the Premium allowance of 1,000 calls a month covers roughly 250 signup tests. If your suite runs hotter than that, Business at $49 a month includes 50,000 calls. The test asserts on every API status, so a 402 (Free plan), 401 (bad key), or 429 (allowance exhausted) fails loudly at the step that caused it instead of surfacing later as a missing code.

Keep going

Temp mail for Selenium questions, answered

The questions QA engineers ask before adding this test to a suite.

Can I use temp mail in a Selenium test?

Yes. The test on this page creates a fresh Tempify inbox through the API with fetch, drives the signup form with Selenium WebDriver, waits for the verification mail with the API long-poll endpoint, reads the extracted code, and asserts the signup completed. Every test run gets its own inbox, so runs never share state.

Do I need a paid plan to use temp mail in Selenium?

Yes. The test calls the Tempify API, and API access starts on Premium at $4.99 a month (1,000 calls a month). The Free plan returns 402 on every API call, so the test skips itself when no key is set and fails with 402 on a Free-plan key. The Developer plan at $19 a month with 10,000 calls a month is coming soon; Business at $49 a month includes 50,000 calls.

How does the test wait for the verification email?

It calls GET /api/v1/inbox/{address}/wait?timeout=55 with fetch, which holds the request until a message arrives or 55 seconds elapse. One wait counts as one API call however long it holds, so the test does not poll in a loop and does not burn the monthly allowance. On timeout the response is 200 with timed_out true, and the test fails with a clear message instead of hanging.

Which browser does the test use?

Chrome, driven headless through selenium-webdriver. Selenium Manager, bundled with selenium-webdriver since version 4.11, downloads the matching ChromeDriver automatically, so there is nothing to install by hand. If Chrome is not on your PATH, point SELENIUM_CHROME_BINARY at the Chrome binary. The same test runs against Firefox by changing the builder to forBrowser("firefox"); the API calls do not change.

How do I run this test in CI?

Save the test file, add your API key as a repository secret called TEMPIFY_API_KEY, install Chrome in the job, and run node --test with TEMPIFY_API_KEY set from the secret. The CI snippet on this page shows the GitHub Actions job. The test reads the signup URL and selectors from environment variables, so the same test runs against staging and production by changing variables, not code.

What if the verification email is slow?

The wait endpoint holds up to 55 seconds per call, which covers most verification mail. If your mailer is slower than that, call wait again with the since parameter set to the first call's start time: only messages after that timestamp are returned, so the second wait does not re-read old mail. Do not generate a new inbox and restart the signup: a new address restarts the sender's delivery clock.

Does the test work with Playwright or Cypress too?

The API calls are plain HTTP, so the same flow works in any framework: create the inbox with POST /api/v1/inbox, submit the form, wait with GET /api/v1/inbox/{address}/wait, and read the code with GET /api/v1/inbox/{address}/otp. Only the browser-driving code changes. The API reference at tempify.org/developers/temporary-email-api documents every call the test uses.