Skip to content

Fix Playwright Test Fail – Test Not Passing in CI

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Fix Playwright Test Fail. We cover key concepts, practical examples, and best practices.

Your Playwright tests pass every time on your local machine. You push to CI β€” and they fail. "Timeout 30000ms exceeded", "locator not found", or "browser did not open". You didn't change anything.

Wrong ❌

// test.spec.js
test('user can login', async ({ page }) => {
  await page.goto('http://localhost:3000');
  await page.fill('#username', 'admin');
  await page.fill('#password', 'pass123');
  await page.click('button[type="submit"]');
  await page.waitForURL('**/dashboard');   // ❌ may timeout in CI
});

In CI:

TimeoutError: locator.waitFor: Timeout 30000ms exceeded.
waiting for locator('#username')

The app hasn't loaded yet. CI machines are slower.

## Right βœ…

```<a href="/programming-languages/javascript/">javascript</a>
// <a href="/testing-qa/playwright/">playwright</a>.config.js
import { defineConfig } from '@<a href="/testing-qa/playwright/">playwright</a>/test';

export default defineConfig({
  timeout: 60000,
  expect: {
    timeout: 10000,
  },
  use: {
    headless: true,
    viewport: { width: 1280, height: 720 },
    actionTimeout: 15000,                // wait up to 15s for elements
    navigationTimeout: 30000,
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },
  webServer: {
    command: 'npm run dev',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
    timeout: 120000,                     // 2 min to start
  },
});

```javascript
// test.spec.js β€” robust selectors and waits
test('user can login', async ({ page }) => {
  await page.goto('http://localhost:3000', { waitUntil: 'networkidle' });

  // Wait for elements explicitly
  const usernameInput = page.getByLabel('Username');
  await usernameInput.waitFor({ state: 'visible' });
  await usernameInput.fill('admin');

  await page.getByLabel('Password').fill('pass123');
  await page.getByRole('button', { name: 'Sign in' }).click();

  // Wait for navigation β€” not timeout
  await expect(page.getByText('Dashboard')).toBeVisible({ timeout: 10000 });
});

**CI-specific config:**

```<a href="/programming-languages/javascript/">javascript</a>
// <a href="/testing-qa/playwright/">playwright</a>.config.ci.js
import config from './<a href="/testing-qa/playwright/">playwright</a>.config.js';
export default {
  ...config,
  retries: 2,                           // retry flaky tests
  workers: 2,                           // limit parallel workers
  reporter: [['list'], ['html', { outputFolder: '<a href="/testing-qa/playwright/">playwright</a>-report' }]],
};

```bash
# CI run
npx playwright test --config playwright.config.ci.js

**Debug CI failures:**

```bash
# Upload test artifacts
- uses: actions/upload-artifact@v4
  if: always()
  with:
    name: <a href="/testing-qa/playwright/">playwright</a>-report
    path: <a href="/testing-qa/playwright/">playwright</a>-report/

## Root Cause

CI machines have fewer resources (CPU, memory) and different timing. Tests that rely on `setTimeout` or implicit waits pass locally (fast machine) but fail in CI (slow machine). Headless mode may expose rendering differences.

## Prevention

- Use `getByRole`, `getByLabel`, `getByText` β€” never CSS selectors dependent on implementation details.
- Set explicit `timeout` and `actionTimeout` in the config.
- Run tests with `--reporter=list` in CI β€” better visibility.
- Use `retries: 2` for flaky tests β€” but fix the root cause instead of masking it.


## Common Mistakes with test fail

1. **Using `head` and `tail` instead of pattern matching, causing runtime errors on empty lists**
2. **Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks**
3. **Using `return` to exit a function early instead of wrapping a pure value in the monad**

These mistakes appear frequently in real-world <a href="/testing-qa/playwright/">PLAYWRIGHT</a> code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

## Practice Exercise

**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

## FAQ

<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Should I use `waitForTimeout`?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Never β€” it's a brittle anti‑pattern. Wait for a specific condition instead.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Why do tests fail in headless mode but pass headed?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: The browser viewport or font rendering may differ. Set an explicit <code>viewport</code> in config.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How do I test file downloads?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Use <code>page.waitForEvent('download')</code> instead of checking the file system.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I run <a href="/testing-qa/playwright/">Playwright</a> tests in parallel?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes β€” set <code>workers: 4</code> in config. Ensure tests are fully isolated (no shared state).</p>
</div></details>

---

*<a href="/testing-qa/playwright/">Playwright</a> in CI is covered in the [DodaTech E2E Testing with <a href="/testing-qa/playwright/">Playwright</a> course](https://dodatech.com/courses/<a href="/testing-qa/playwright/">playwright</a>).*

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro