This project demonstrates automated testing of OTP (One-Time Password) authentication using Playwright with an efficient and programmable approach to accessing email inbox content via the Mailsac API.
Instead of interacting with the inbox through a web UI, this approach leverages Mailsac's API to fetch OTP codes quickly and reliably using the mailsac-typescript-api wrapper.
The website under test is accessible at https://practice.expandtesting.com/otp-login.
- ✅ Automated OTP login flow using Playwright
- ✅ Access OTP from email inbox using API (no UI interaction)
- ✅ Uses
mailsac-typescript-apifor structured API communication - ✅ Random test data generation using
faker.js - ✅ Clean test architecture using the Page Object Model (POM) pattern
- ✅ Custom
EmailHelperclass to interact with Mailsac API and extract OTP - ✅ Custom Playwright fixtures to inject page objects into the tests
Mailsac allows public email inbox access for any address under the @mailsac.com domain.
This means you can send emails to any email like [email protected], and it will be accessible via their API without any special configuration.
- playwright/test – Testing framework
- faker.js – Generates random data
- Mailsac – Email sandbox for test inboxes
- mailsac-typescript-api – Typed wrapper for Mailsac API
- dotenv – For managing environment variables
- Create a free Mailsac account
- Generate your Mailsac API Key
- Create a
.envfile in the root directory of the project with the following variables:
MAILSAC_API_BASE_URL=https://mailsac.com/api
MAILSAC_API_KEY=<your mailsac api key>Clone project locally
Install dependencies:
npm install
# or
yarn install
# or
pnpm installRun tests:
npm run e2e
# or
yarn e2e
# or
pnpm run e2e