Session Validation
This guide explains how TrueAssert validates and reuses authenticated sessions to speed up test execution.
Overview
Session validation is the "fast path" that allows tests to skip the full login process when a valid authenticated session already exists. This significantly speeds up test execution.
How Session Validation Works
The Validation Flow
When a test with login_required=True runs:
Check for Session Data:
TrueAssert checks if
SessionDataexists for the project's domainIf no session exists → Proceed to full login
If session exists → Attempt validation
Load Session:
Execute LOAD_SESSION command
Browser navigates to real domain (not
data:URL)Session data (cookies, localStorage, sessionStorage) is injected
Execute Validation Steps:
Execute last 2 steps from login test:
Step 6: GOTO to authenticated page
Step 7: WAIT for confirmation element
If both steps succeed → Session is valid
If either step fails → Session is invalid
Decision:
Valid Session: Skip full login, proceed with main test
Invalid Session: Discard session, execute full login
Why Session Validation Exists
Benefits
Faster Execution: Skips 5 login steps (username, password, click, etc.)
Reduced Load: Less stress on authentication system
Better UX: Tests run faster for users
Cost Savings: Fewer authentication requests
When It's Used
Session validation is attempted when:
Test has
login_required=TrueSessionData exists for project's domain
Login test is READY
Validation Steps
Step 6: GOTO to Authenticated Page
This step navigates to a page that requires authentication:
Example: https://example.com/dashboard
Purpose: Verify we can access authenticated content
If fails: Session is invalid
Step 7: WAIT for Confirmation Element
This step waits for an element that confirms authentication:
Example:
//div[@id='user-menu']or//a[contains(text(), 'Logout')]Purpose: Verify we're actually logged in
If fails: Session is invalid
Why These Steps?
These steps are chosen because:
They're fast (just navigation + wait)
They're reliable (confirmation element should always exist when logged in)
They're sufficient (if we can access authenticated page and see confirmation, we're logged in)
Session Validation vs Full Login
Session Validation (Fast Path)
When Used: Session exists and is valid
Steps Executed:
LOAD_SESSION
GOTO (to authenticated page)
WAIT (for confirmation)
Time: ~2-3 seconds
Result: was_login_needed=False, is_actual_login_happened=False
Full Login (Slow Path)
When Used: No session or validation failed
Steps Executed:
CLEAR_BROWSER
GOTO (to login page)
FILL (username)
FILL (password)
CLICK (login button)
WAIT (for login confirmation)
GOTO (to authenticated page)
WAIT (for confirmation)
SAVE_SESSION
Time: ~10-15 seconds
Result: was_login_needed=True, is_actual_login_happened=True
Understanding the Flow
First Run (No Session)
Test Starts
↓
Check SessionData → None found
↓
Full Login Required
↓
Execute all 7 login steps
↓
SAVE_SESSION
↓
Session saved to database
↓
Execute main testSecond Run (Session Exists)
Test Starts
↓
Check SessionData → Found
↓
Session Validation Attempt
↓
LOAD_SESSION
↓
GOTO authenticated page → Success
↓
WAIT for confirmation → Success
↓
Session Valid! Skip login
↓
Execute main testThird Run (Session Expired)
Test Starts
↓
Check SessionData → Found
↓
Session Validation Attempt
↓
LOAD_SESSION
↓
GOTO authenticated page → Success
↓
WAIT for confirmation → FAIL (element not found)
↓
Session Invalid! Discard session
↓
Full Login Required
↓
Execute all 7 login steps
↓
SAVE_SESSION (new session)
↓
Execute main testTracking Login Behavior
Login Tracking Fields
TestExecution and DraftingAttempt have two boolean fields:
was_login_needed:
True: Full login was required (no session or validation failed)False: Session validation succeeded, login skipped
is_actual_login_happened:
True: Full login steps were executed (username/password entered)False: Only session validation happened (no username/password)
Example Scenarios
Scenario 1: First Run
was_login_needed=True(no session existed)is_actual_login_happened=True(full login executed)
Scenario 2: Second Run (Session Valid)
was_login_needed=False(session was valid)is_actual_login_happened=False(only validation, no login)
Scenario 3: Third Run (Session Expired)
was_login_needed=True(validation failed)is_actual_login_happened=True(full login executed again)
Troubleshooting
Validation Always Fails
Problem: Session validation fails even with valid session.
Possible Causes:
Confirmation Element Changed: The element used for validation no longer exists
Session Expired: Cookies expired on server
Domain Mismatch: Session domain doesn't match test URL domain
GOTO URL Changed: Authenticated page URL changed
Solutions:
Update login test validation steps (last 2 steps)
Clear session data and create new session
Verify domain matches test target URL
Update GOTO URL in login test
Validation Succeeds But Test Fails
Problem: Session validation passes but main test fails.
Possible Causes:
Session is valid but insufficient permissions
Test needs different authentication level
Session is for different user
Solutions:
Check if session has correct permissions
Verify test requirements match session
Clear session and re-authenticate with correct user
Session Not Being Reused
Problem: Full login happens every time, session not reused.
Possible Causes:
Session validation steps are incorrect
Confirmation element selector is wrong
Session data not being saved
Solutions:
Review login test validation steps
Update confirmation element selector
Check that SAVE_SESSION executed successfully
Verify SessionData exists in database
Best Practices
Validation Steps
Use Stable Selectors: Confirmation element should have stable selector (ID, data-testid)
Test Manually: Verify validation steps work manually
Update When Needed: If page structure changes, update validation steps
Session Management
Monitor Reuse: Check
was_login_neededto see if sessions are being reusedClear When Needed: Clear sessions if authentication changes
Verify Domain: Ensure session domain matches test domain
Debugging
Check Tracking Fields: Review
was_login_neededandis_actual_login_happenedReview Logs: Check controller logs for validation attempts
Test Validation Steps: Manually test GOTO + WAIT steps
Related Topics
Setting Up Login - Configure login flow
Per-Domain Sessions - Domain-specific sessions
Running Tests - Execute tests with session management
Core Concepts - Session management architecture
Last updated