Test SMS verification in automated tests

An end-to-end test of a sign-in flow needs a code it can type. With a TextKit test key the code is always 111111: no phone, no inbox to read, and no real text sent. It works the same in Playwright, Cypress, Selenium, or any other test runner, and for coding agents like Claude Code and Codex running your tests.

Set up

Give your test environment a test key (tk_sk_test_). Your app's code doesn't change: it makes the same two Verify calls, and the test key answers like live.

Codes that force each result

Code typedResult
111111approved
000000invalid
222222expired
333333max attempts

Playwright

ts
import { test, expect } from '@playwright/test';

test('sign in with a phone code', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Phone').fill('+14155550132');
  await page.getByRole('button', { name: 'Send code' }).click();
  await page.getByLabel('Code').fill('111111'); // the sandbox code
  await page.getByRole('button', { name: 'Verify' }).click();
  await expect(page).toHaveURL('/dashboard');
});

Selenium (Python)

python
from selenium.webdriver.common.by import By

driver.get("https://localhost:3000/login")
driver.find_element(By.NAME, "phone").send_keys("+14155550132")
driver.find_element(By.ID, "send-code").click()
driver.find_element(By.NAME, "code").send_keys("111111")  # the sandbox code
driver.find_element(By.ID, "verify").click()

The selectors are your app's own; the code and the test key are the only TextKit parts.

Test the edge cases

  • Resend button. The sandbox has no resend cooldown, so you can click it as often as you like. To test the cooldown itself, send to +15005550003: it always answers 429 with retry_after.
  • Blocked numbers. +15005550021 to +15005550027 each answer 403 verification_blocked with one reason, like a live key would. See the table in Verify.
  • Email codes. Any address works, example.com included, and the code is 111111. cooldown@textkit.test always returns the cooldown.

Keep live keys out of CI

A test key never sends a real text and never bills. A live key in CI would text real numbers and charge for each successful check. Set the test key in your CI secrets and the live key only in production.

More on test mode: Sandbox & test numbers.