Playwright "Error in global setup" - globalSetup Failures in CI
Playwright runs globalSetup once before the suite - often to log in and save storageState. If that script throws, the entire run aborts before any test, and every project shows as failed.
What this error means
The run dies at the start with "Error in global setup" and the underlying exception. Tests that depend on a saved auth state then cannot run, because the setup that produces it never finished.
Error: Error in global setup.
at loadConfigAndRunGlobalSetup (playwright/lib/runner.js)
Caused by: page.fill: Timeout 30000ms exceeded.
waiting for getByLabel('Password')Common causes
The setup script threw
A failed login, an unreachable backend, or a selector that times out inside globalSetup raises an exception that aborts the whole run.
storageState never written or path wrong
If setup is supposed to save storageState but the path is wrong or the save is skipped on error, dependent tests fail to load the auth state.
How to fix it
Make global setup robust and save state explicitly
// global-setup.ts
export default async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(process.env.BASE_URL + '/login');
await page.getByLabel('Email').fill(process.env.E2E_USER);
await page.getByLabel('Password').fill(process.env.E2E_PASS);
await page.getByRole('button', { name: 'Sign in' }).click();
await page.context().storageState({ path: 'storage/state.json' });
await browser.close();
};Wire setup and state into the config
- Reference
globalSetupanduse.storageStateinplaywright.config.ts. - Ensure the app/backend is up before setup runs (use
webServeror a healthcheck). - Confirm required env (
E2E_USER/E2E_PASS,BASE_URL) is present in CI.
How to prevent it
- Gate
globalSetupbehind a backend healthcheck. - Fail fast with a clear message if required env is missing.
- Save
storageStateto a stable, configured path.