Session Management
This guide explains how to configure authentication flows for your tests using TrueAssert's session management system.
Overview
TrueAssert's session management allows you to:
Automatically handle login flows for tests
Reuse authenticated sessions across test runs
Store browser session data (cookies, localStorage, sessionStorage)
Skip login when session is still valid
When to Use Session Management
Use session management when:
Your tests require authentication
You want to avoid logging in for every test run
You need to test authenticated user flows
You want faster test execution (session reuse)
Setting Up Login
Step 1: Configure Project Login Settings
Navigate to Project Settings → Login (Project Settings Login)
Fill in the login form:
Login URL: The URL where users log in (e.g., https://example.com/login)
Login Username: Username for authentication
Login Password: Password for authentication
Click "Save"
Step 2: Generate Login Test
After saving login settings:
TrueAssert automatically creates a Login Test for your project
The login test has
is_system_test=True(hidden from main test list)Status starts as DRAFTING
Background processor generates login steps automatically
Step 3: Review Login Test
Go to Project Settings → Login
Click "Review Login" button
Review the generated login steps:
GOTO to login page
FILL username field
FILL password field
CLICK login button
WAIT for confirmation element
GOTO authenticated page
WAIT for confirmation element
Verify steps are correct
Click "Finish Review" to mark test as READY
Step 4: Use in Tests
When creating a test:
Check "Login Required" checkbox
Test will automatically use login flow
Session will be saved after first successful login
Future runs will reuse session if still valid
Login Test Structure
The login test follows a specific 7-step structure:
GOTO - Navigate to login page
FILL - Enter username
FILL - Enter password
CLICK - Click login button
WAIT - Wait for login confirmation element
GOTO - Navigate to authenticated page (e.g., dashboard)
WAIT - Wait for confirmation element on authenticated page
Important: The last 2 steps (GOTO + WAIT) are used for session validation.
How Login Flow Works
During Test Execution
When a test with login_required=True runs:
Session Validation (first attempt):
Check if SessionData exists for project's domain
If exists, execute LOAD_SESSION command
Execute validation steps (last 2 steps from login test)
If validation succeeds: Skip full login, proceed with test
If validation fails: Proceed to full login
Full Login (if validation fails or no session):
Execute CLEAR_BROWSER command
Execute all 7 login test steps
Execute SAVE_SESSION command
Save session data to database
Proceed with main test
Session Data Storage
Session data is stored in the SessionData model:
OneToOne relationship with Project
Domain field for per-domain storage
Data field (JSON) containing:
cookies: All browser cookieslocalStorage: Browser localStorage datasessionStorage: Browser sessionStorage data
Session Persistence
Sessions persist until manually cleared
Sessions are domain-specific
One session per project per domain
Sessions are reused across test executions
Login Test Requirements
Status Requirements
The login test must be READY before it can be used:
DRAFTING: Still being generated (not ready)
REVIEW: Steps generated, needs review (not ready)
READY: Ready for execution ✅
Step Requirements
The login test must have:
At least 7 steps (as described above)
Last step must be WAIT (for confirmation element)
Second-to-last step must be GOTO (to authenticated page)
Validation Steps
The last 2 steps are used for session validation:
Step 6: GOTO to authenticated page
Step 7: WAIT for confirmation element
These steps verify that the loaded session is still valid.
Troubleshooting
"No login test found"
Problem: Login test doesn't exist for project.
Solution:
Go to Project Settings → Login
Configure login credentials
Click "Save"
Wait for login test to be generated
Review and finish review
"Login test is not ready"
Problem: Login test exists but status is not READY.
Solution:
Go to Project Settings → Login
Click "Review Login"
Verify login steps are correct
Click "Finish Review"
Ensure status is READY
Login Flow Fails
Problem: Login steps fail during execution.
Possible Causes:
Login URL incorrect
Username/password incorrect
Selectors changed (page structure changed)
Confirmation element not found
Solution:
Check error messages in test execution
Review login test steps
Update selectors if needed
Verify credentials are correct
Session Validation Always Fails
Problem: Session validation fails even with valid session.
Possible Causes:
Session expired (cookies expired)
Confirmation element changed
Domain mismatch
Solution:
Clear session data
Re-run test to create new session
Update validation steps if needed
Best Practices
Login Test Setup
Use Stable Selectors: Ensure login test uses stable selectors (IDs, data-testid)
Test Manually First: Verify login flow works manually before automating
Review Steps Carefully: Check that all steps are correct before marking READY
Update When Needed: If login page changes, update login test
Session Management
Clear Sessions Periodically: Clear old sessions if authentication changes
Monitor Session Validity: Check if sessions are being reused (faster execution)
Domain Matching: Ensure session domain matches test target URL domain
Test Session Reuse: Verify that second run uses session validation
Test Configuration
Use Login Required: Check "Login Required" for tests needing authentication
Don't Mix Options: Don't use both "Login Required" and "Use Predefined Session"
Verify After Changes: Re-run tests after updating login settings
Related Topics
Session Validation - How session reuse works
Per-Domain Sessions - Managing sessions across domains
Running Tests - Execute tests with login
Debugging Failed Tests - Fix login issues
Last updated