Created
December 5, 2025 23:19
-
-
Save ckenst/486f33eef02084799bb3199dede62ca9 to your computer and use it in GitHub Desktop.
Mailinator SMS OTP login demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { test, expect } = require(‘@playwright/test’); | |
| const axios = require(‘axios’); | |
| test(‘Login using OTP code via SMS’, async ({ page }) => { | |
| const phoneNumber = ‘15555555555’; // Replace with a Mailinator test phone number | |
| // Navigate to the login page and initiate login | |
| await page.goto(‘https://yourapp.com/login’); | |
| await page.fill(‘#phone’, phoneNumber); | |
| await page.click(‘button[type=”submit”]’); | |
| // Wait for the OTP SMS to arrive | |
| const apiToken = ‘YOUR_MAILINATOR_API_TOKEN’; | |
| const smsResponse = await axios.get(`https://api.mailinator.com/api/v2/domains/private/inboxes/${phoneNumber}`, { | |
| headers: { ‘Authorization’: apiToken } | |
| }); | |
| const messages = smsResponse.data.msgs; | |
| const otpMessage = messages.find(msg => msg.subject.includes(‘Your OTP Code’)); | |
| // Fetch the full message content | |
| const messageResponse = await axios.get(`https://api.mailinator.com/api/v2/domains/private/messages/${otpMessage.id}`, { | |
| headers: { ‘Authorization’: apiToken } | |
| }); | |
| const otpCodeMatch = messageResponse.data.parts[0].body.match(/\d{6}/); | |
| const otpCode = otpCodeMatch ? otpCodeMatch[0] : null; | |
| // Enter the OTP and complete login | |
| await page.fill(‘#otp’, otpCode); | |
| await page.click(‘button[type=”submit”]’); | |
| // Verify successful login | |
| await expect(page).toHaveURL(‘https://yourapp.com/dashboard’); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment