Authentication
Learn how to configure authentication for your Spur tests
Authentication is a crucial part of many test scenarios. Spur provides flexible options to handle authentication states across your tests.
Start from Logged-in State
Starting from a Logged-in State
When you need to run a test that requires an authenticated user:
-
Check “Start from logged-in state”
-
Select a login test from the dropdown
-
Your test will begin with the authentication state from the selected test
If you’re experiencing issues with authentication in custom configurations, please reach out to the Spur team. We’re here to help optimize authentication for your specific setup.
This is particularly useful for:
-
Tests that require an authenticated user
-
Avoiding redundant login steps
-
Maintaining consistent test states
Save Login State
Saving Login State Configuration
Enable this option when:
-
Your test performs a login that other tests might need
-
You want to make the authentication state reusable
-
You’re creating a dedicated login test
Login states are saved at the end of test execution and can be used by other tests that select this test as their login state source.
Parallel Test Execution with Multiple Accounts
When running tests in parallel, it’s recommended to use different accounts for different test suites to prevent state interference. For example:
-
Use
test_user_1@example.com
for your product browsing test suite -
Use
test_user_2@example.com
for your checkout flow test suite -
Use
test_user_3@example.com
for your account settings test suite
This approach ensures that:
-
Tests can run simultaneously without affecting each other’s states
-
Each test suite has its own isolated authentication context
-
Changes made in one test suite won’t impact the others
-
You can maintain predictable test behavior in parallel execution
Best Practices
-
Create Dedicated Login Tests
-
Make separate tests for different user roles
-
Keep login tests focused and minimal
-
Use clear naming conventions (e.g., “Admin Login”, “Customer Login”)
-
-
State Management
-
Save login states from tests that perform authentication
-
Reuse login states to reduce test execution time
-
Consider test dependencies when managing states
-
-
Security Considerations
-
Use environment variables for credentials
-
Regularly update saved login states
-
Clear authentication data in teardown tests when needed
-
Common Scenarios
Multiple User Roles
When testing features that require different user roles:
E-commerce Flow
For an e-commerce website:
Troubleshooting
Common authentication issues and solutions:
-
Login State Not Available
-
Ensure the login test has “Save login state” enabled
-
Check if the login test completed successfully
-
Verify the correct login test is selected
-
-
Session Expiration
-
Consider adding refresh token handling
-
Implement automatic re-login when needed
-
Use shorter test sequences
-
-
State Conflicts
-
Clear cookies/storage in teardown tests
-
Use separate login states for different flows
-
Implement proper test isolation
-
Custom Authentication Support
Having trouble with a custom authentication setup? The Spur team specializes in handling complex authentication scenarios. Contact us for personalized assistance in optimizing your test configuration.
For more complex authentication scenarios or custom implementations, refer to our JavaScript Actions guide.