1 You are logging in through the UI in every single test.
Open the app. Type the email. Type the password. Click login. Wait for the redirect.
Now multiply that by 200 tests. That is 200 login screens that have nothing to do with what you are actually testing.
We audited a suite last month. 38% of total test runtime was spent on the login page. Not on testing features. On typing credentials into a form.
The fix is simple. Log in once via API, save the session, and every test loads that file and starts already authenticated.
// BEFORE - Every test logs in through the UI
test('check dashboard stats', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill('admin@company.com');
await page.getByLabel('Password').fill('password123');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.waitForURL('/dashboard');
await expect(page.getByTestId('stats-panel')).toBeVisible();
});
// AFTER - Login once, reuse session across all tests
// auth.setup.ts
setup('authenticate', async ({ request }) => {
await request.post('/api/auth/login', {
data: { email: 'admin@company.com', password: 'password123' },
});
await request.storageState({ path: '.auth/admin.json' });
});
// playwright.config.ts
projects: [
{ name: 'auth-setup', testMatch: 'auth.setup.ts' },
{ name: 'chromium', use: { storageState: '.auth/admin.json' },
dependencies: ['auth-setup'] },
]
// your test - starts already logged in
test('check dashboard stats', async ({ page }) => {
await page.goto('/dashboard');
await expect(page.getByTestId('stats-panel')).toBeVisible();
});
Your tests begin exactly where the user lands after login. The login screen never appears in your results again.
How does your team handle auth? UI login every time or something smarter?
Drop it in the comments.
Top comments (0)