Test Authenticated Flows
Learn how to test applications that require login, 2FA, OTP, and magic links.
Creating a Persona
A Persona is a set of login credentials that BugBrain uses to authenticate before running tests.
1
Go to Personas
Dashboard → Personas → New Persona
2
Enter Basic Info
Persona name (e.g., 'Test User 1'), Email, Password
3
Select Auth Type
Choose: Basic Auth / Email OTP / TOTP / Magic Link
4
Configure Auth Details
Add required credentials (TOTP secret, Mailosaur address, etc.)
5
Save Persona
Use immediately in test plans
Auth Type: Basic Login
Simplest authentication method
Setup
- Create Persona
- Enter email and password
- No additional config needed
- Save
How It Works
- BugBrain navigates to login page
- Fills email + password fields automatically
- Clicks login button
- Session cached for 8 hours
- Next test reuses login (faster execution)
Test It
1. Create test: "Login Flow"
2. First step: Create and link persona
3. Run test → BugBrain logs in automatically
4. Create second test with same persona
5. Note: Much faster (login cached!)Auth Type: Email OTP (One-Time Password)
Requires Mailosaur integration
Prerequisites
- Mailosaur account (free tier available)
- API key and Server ID
- Set environment variables:
MAILOSAUR_API_KEY=your_key MAILOSAUR_SERVER_ID=your_server_id
Setup
- Create Persona
- Select “Email OTP” auth type
- Enter Mailosaur email address (e.g.,
test@ABC123.mailosaur.net) - BugBrain retrieves OTP automatically during login
- Save
How It Works
- User enters email at login prompt
- BugBrain submits login form
- Application sends OTP to email
- BugBrain calls
retrieve_email_code()action - Mailosaur API fetches OTP from inbox
- BugBrain enters OTP automatically
- Session cached for future tests
Test It
1. Create Persona with Mailosaur address
2. Test: "Login with OTP"
3. Steps:
- Navigate to /login
- Fill email (uses persona email)
- Click "Send OTP"
- Wait for OTP form
- BugBrain auto-fills OTP
- Click submit
- Assert logged inAuth Type: Magic Link
Email link-based login
Setup
- Create Persona with Mailosaur address
- Select “Email OTP / Magic Link” auth type
- Save
How It Works
- User enters email
- App sends magic link email
- BugBrain retrieves magic link from Mailosaur
- Navigates to link automatically
- User logged in
- Session cached
Test It
1. Test: "Magic Link Login"
2. Steps:
- Navigate to /login
- Fill email
- Click "Send magic link"
- Wait for confirmation message
- BugBrain retrieves link from Mailosaur
- Navigate to link
- Assert logged in (home page)Auth Type: TOTP / 2FA
Time-based one-time passwords (Google Authenticator, Authy)
Prerequisites
- TOTP secret (base32 encoded seed)
- Usually provided during 2FA setup
Where to Find Secret
-
From dev account setup:
- Look for “Secret key” or “Manual entry code”
- Save the 32-character base32 string
-
Extract from QR code:
# QR code scanner tools can extract secret # Or check your password manager
Setup
- Create Persona
- Select “TOTP / 2FA” auth type
- Paste TOTP secret (base32 format)
- Save
How It Works
- BugBrain uses pyotp library to generate 6-digit codes
- Codes valid for 30 seconds (standard TOTP)
- Auto-fills 2FA field during login
- Works with Google Authenticator, Authy, etc.
Test It
1. Create Persona with TOTP secret
2. Test: "Login with 2FA"
3. Steps:
- Navigate to /login
- Fill email
- Fill password
- Click login
- BugBrain generates TOTP code
- Auto-fills 2FA field
- Click verify
- Assert logged inUsing Personas in Tests
In Test Plans
- Create test step
- Click “Link Persona”
- Select persona from dropdown
- BugBrain logs in automatically
- Subsequent steps run as authenticated user
In Exploratory Sessions
- New Session
- Select “Persona” dropdown
- Choose persona (or leave blank for guest)
- AI explores as authenticated user
- Tests authenticated-only pages
In Discovery Crawls
- Start Discovery
- Select Persona to use
- Crawler logs in automatically
- Discovers authenticated pages and flows
Troubleshooting
”Login Failed: Invalid Credentials”
- Verify persona email/password is correct
- Ensure account isn’t locked
- Check 2FA/OTP codes are generating (TOTP)
“OTP Code Not Retrieved”
- Confirm Mailosaur API key is correct
- Check environment variables are set
- Verify email address receives OTP
- Check Mailosaur server ID is correct
”TOTP Code Wrong”
- Verify TOTP secret is base32 format
- Check if secret uses spaces or dashes (remove them)
- Ensure time is synchronized on server
”Session Timeout”
- Default 8-hour cache TTL
- Increase in Persona settings if needed
- Sessions reset if persona credentials change
”Multiple Users, Same Email”
- Create separate personas with different emails
- Use unique test accounts per persona
- Example: test-user-1@example.com, test-user-2@example.com
Best Practices
- ✅ Use test accounts for personas (not real user accounts)
- ✅ Keep TOTP secrets secure (use secrets manager)
- ✅ Regularly rotate test account passwords
- ✅ Name personas clearly (e.g., “Admin User”, “Free Tier User”)
- ✅ Document which tests use which personas
- ❌ Don’t share persona credentials in Slack
- ❌ Don’t hardcode passwords in test code
- ❌ Don’t use production accounts for testing