How do you handle authentication in a large UI test suite without making every test log in through the UI?
What the interviewer wants to hear
- Test the login UI itself in a few dedicated tests
- Log in once via API or setup step and reuse session state
- Separate state per role or user
- Handle token expiry and parallel workers
- Keep credentials in secrets
Model answer
I test the login page itself thoroughly in a few dedicated tests, including wrong passwords and MFA. Every other test should not pay for it. In Playwright I use a setup project that logs in once per role, through the API where possible, and saves storage state files with the cookies and local storage. Tests then start already signed in as admin, viewer or customer by choosing the right file. In Selenium I do the same by calling the auth API and injecting the session cookie. When tests change account data, I give each parallel worker its own account so they do not interfere. I make sure tokens are refreshed if a run is long, and all credentials come from the CI secret store. This often cuts minutes from the suite while keeping real authentication in the loop.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Automation Test Engineer questions
- How would you design a test automation framework from scratch for a web app?
- A test fails randomly in CI about 1 in 20 runs. Walk me through how you find and fix the cause.
- How do you manage test data in an automated suite that runs in parallel on shared environments?
- When should automated tests mock external services, and when should they use real ones?
- How do you make automated test results useful to developers and managers?
- Your suite needs to run in parallel across many workers. What do you change to make that safe?
- Describe how you would set up automated tests in a CI/CD pipeline for a web application.
- You are asked to load test a new checkout API before a big sale. How do you plan and run it?
- How would you approach test automation for a mobile app on Android and iOS?