Skip to content

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.

Notifications You must be signed in to change notification settings

markomilenkovic546/playwright-otp-auth

Repository files navigation

🔐 OTP Authentication Testing with Playwright & Mailsac API

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.

🌐 Website Under Test

The website under test is accessible at https://practice.expandtesting.com/otp-login.

✨ Features

  • ✅ Automated OTP login flow using Playwright
  • ✅ Access OTP from email inbox using API (no UI interaction)
  • ✅ Uses mailsac-typescript-api for structured API communication
  • ✅ Random test data generation using faker.js
  • ✅ Clean test architecture using the Page Object Model (POM) pattern
  • ✅ Custom EmailHelper class to interact with Mailsac API and extract OTP
  • ✅ Custom Playwright fixtures to inject page objects into the tests

📬 How Mailsac Works

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.


🔧 Technologies Used

  • 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

🔑 Environment Setup

  1. Create a free Mailsac account
  2. Generate your Mailsac API Key
  3. Create a .env file 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>

Running Locally

Clone project locally

Install dependencies:

npm install
# or
yarn install
# or
pnpm install

Run tests:

npm run e2e
# or
yarn e2e
# or
pnpm run e2e

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published