How to test SMS 2FA login in CI with GitHub Actions

· 5 min read · QuickInbox team

  • GitHub Actions
  • CI
  • SMS

An SMS 2FA test that only runs on your laptop doesn't protect much. Here's how to run it in GitHub Actions without flaky failures.

Step 1: add the secret

In your repository go to Settings > Secrets and variables > Actions and add QI_KEY with a QuickInbox API key. Make a separate key for CI so you can rotate it without touching anyone's laptop.

Step 2: the workflow

# .github/workflows/sms-e2e.yml
name: SMS 2FA e2e
on:
  push:
    branches: [main]
  workflow_dispatch:

concurrency:
  group: sms-test-number   # only one run uses the number at a time
  cancel-in-progress: false

jobs:
  sms-e2e:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npm ci
      - run: npx playwright install --with-deps chromium
      - run: npx playwright test --project=sms --workers=1
        env:
          QI_KEY: ${{ secrets.QI_KEY }}
          BASE_URL: https://staging.example.com

The concurrency group is the important part. If two pushes land close together, the second run waits instead of reading the first run's code.

Step 3: the test

Use the helper and test from SMS OTP in Playwright. They record existing texts first and wait only for a new code, which also protects you from old messages.

When to run it

  • Every pull request: mocked SMS tests, fast and free.
  • Merges to main or nightly: the real SMS test, as above.
  • Before a release: run it by hand with workflow_dispatch.

Debugging failures

  • Upload the Playwright report as an artifact so you can see the screen at the moment it failed.
  • If no text arrived, check the SMS page in your workspace: if the text is there, the test missed it; if not, the app or provider didn't send it.
  • Email codes in CI too? See email testing in GitHub Actions.

Related guides

Get a test number: every paid QuickInbox plan includes a real US phone number and a monthly SMS allowance, with plans from $9 a month. Extra packs start at $5 a month. See SMS testing and pricing.

← All articles