SMS utilities
SDK function for reading incoming SMS messages in tests.
Overview
The Heal SDK lets tests read incoming SMS messages, typically OTP codes or verification messages sent during login and signup flows.
Phone numbers are assigned to your organisation on request. Contact the Heal team to get a number provisioned.
| Method | What it does |
|---|---|
Heal.readSMS(phoneNumber, since?) | Returns the plain-text body of the most recent SMS to that number |
How it works
readSMS runs server-side through Heal's proxy. It polls until a message arrives, with a default timeout of 2 minutes. Heal deletes the message after reading so it doesn't bleed into subsequent test runs.
Heal.readSMS(phoneNumber, since?)
Polls for and returns the plain-text body of the most recent SMS delivered to the given number. Pass a since date captured just before the action that triggers the SMS so stale messages are ignored.
static readSMS(phoneNumber: string, since?: Date): Promise<string>;| Parameter | Type | Description |
|---|---|---|
phoneNumber | string | The number to read from (e.g. '+14155552671') |
since | Date | Ignore messages older than this timestamp |
Example
const since = new Date();
await agent.healClick('the Send code button');
const code = await Heal.readSMS('+14155552671', since);
await agent.healType('the verification code field', code);
await agent.healClick('the Verify button');Full example: SMS verification flow
import { Heal } from '@heal-dev/sdk';
test('user can verify their phone number', async () => {
const heal = await Heal.init({ headless: true });
try {
const { page, agent } = await heal.getPage();
await page.goto('https://app.example.com/verify-phone');
await agent.healType('the phone number field', '+14155552671');
const since = new Date();
await agent.healClick('the Send code button');
const code = await Heal.readSMS('+14155552671', since);
await agent.healType('the verification code field', code);
await agent.healClick('the Verify button');
await agent.healAssert('phone number is verified');
} finally {
await heal.close();
}
});Related pages
- SDK overview: SDK overview
- Email utilities: Email utilities
- Full API reference: SDK reference