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 typed | Result |
|---|---|
111111 | approved |
000000 | invalid |
222222 | expired |
333333 | max attempts |
Playwright
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)
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 answers429withretry_after. - Blocked numbers.
+15005550021to+15005550027each answer403 verification_blockedwith one reason, like a live key would. See the table in Verify. - Email codes. Any address works,
example.comincluded, and the code is111111.cooldown@textkit.testalways 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.