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:

  1. Check “Start from logged-in state”

  2. Select a login test from the dropdown

  3. 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

  1. 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”)

  2. State Management

    • Save login states from tests that perform authentication

    • Reuse login states to reduce test execution time

    • Consider test dependencies when managing states

  3. 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:

// Example test structure
1. Admin Login Test (saves login state)
2. Customer Login Test (saves login state)
3. Feature Test A (uses admin login state)
4. Feature Test B (uses customer login state)

E-commerce Flow

For an e-commerce website:

1. Customer Login Test
   - Navigate to login page
   - Enter credentials
   - Verify successful login
   - Save login state

2. Purchase Flow Test
   - Start from customer login state
   - Add items to cart
   - Complete checkout

Troubleshooting

Common authentication issues and solutions:

  1. 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

  2. Session Expiration

    • Consider adding refresh token handling

    • Implement automatic re-login when needed

    • Use shorter test sequences

  3. 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.