How to Find Tests That Depend on Previous Tests in Playwright


Have you ever experienced this situation?

You execute your complete Playwright automation suite.

All 50 tests pass.

But when you execute one test individually, it fails.

You run the complete suite again.

This time, it passes.

Why does this happen?

One possible reason is that the failing test depends on another test that ran before it.

This problem is called a test dependency.

It is one of the common design problems in large automation frameworks.

For example, a registration test creates a user, and a profile test expects that user to exist.

If the registration test runs first, the profile test passes.

If the profile test runs alone, it fails.

This guide explains how to find hidden test dependencies in Playwright using practical examples, debugging commands and real-world automation scenarios.

By the end, you will understand how to identify, investigate and fix tests that depend on previous tests.

1. What Are Test Dependencies in Playwright?

A test dependency occurs when one automated test requires another test to complete an action before it can work correctly.

Consider these three tests:

Test A → Create a user.

Test B → Login with that user.

Test C → Update the user's profile.

Here, Test B depends on Test A.

Test C may depend on Test A and Test B.

This creates a chain of test dependencies.

The problem is that each test is no longer independent.

If Test A fails, the remaining tests may also fail.

Important: Not every setup dependency is bad. A test may legitimately depend on a controlled fixture or setup project. The problem is relying on an ordinary test's side effects without explicitly managing that dependency.

2. Common Signs That Your Playwright Tests Have Dependencies

Before debugging, learn how to recognize the symptoms.

Sign 1: Tests Pass Together but Fail Individually

This is one of the strongest warning signs.

Example:

Complete test suite → Passed.

Individual test execution → Failed.

Possible reason:

The test expects data created by another test.

Sign 2: Test Results Change When Execution Order Changes

Imagine:

Test A → Create customer.

Test B → Update customer.

Test C → Delete customer.

When executed in this order, everything works.

But when Test C runs first, the test fails because the customer does not exist.

This indicates an execution-order dependency.

Sign 3: Tests Fail When Workers Increase

Your automation suite works with one worker.

But when you increase the workers to four, some tests fail.

Possible reasons include:

  • Shared user accounts.

  • Shared database records.

  • Common files.

  • Shared server-side settings.

  • Tests expecting another test's side effects.

Separate browser contexts do not prevent every type of shared-resource conflict.

Sign 4: Retrying a Failed Test Makes It Pass

Suppose a test fails during the first execution but passes during the retry.

This may indicate:

  • Shared state.

  • Incomplete setup.

  • Unstable application data.

  • Timing problems.

  • An external dependency.

A retry is a debugging clue, not proof of a test dependency.

Sign 5: Removing Another Test Causes Failures

If deleting or skipping one test causes another test to fail, investigate whether the removed test was preparing something the second test expected.

3. Method 1: Run the Suspected Test Individually

The first debugging method is simple.

Run the suspected test without executing the complete test suite.

Command:

npx playwright test tests/profile.spec.ts

Suppose the test looks like this:

import { test, expect } from '@playwright/test';


test('Update customer profile', async ({ page }) => {


  await page.goto('/profile');


  await page.getByLabel('Full Name')

    .fill('Rakesh');


  await page.getByRole('button', {

    name: 'Save'

  }).click();


  await expect(

    page.getByText('Profile updated')

  ).toBeVisible();


});

If this test expects an authenticated customer but does not perform authentication or receive an authenticated fixture, it may fail when executed independently.

Investigate:

  1. Is the user logged in?

  2. Does the customer record exist?

  3. Does the test need a particular account?

  4. Is the required profile data available?

  5. Is another test creating this data?

This gives you the first set of clues.

4. Method 2: Execute Tests With Different Workers

One of the best ways to discover shared-state problems is to compare execution with different worker counts.

First, execute using one worker.

npx playwright test --workers=1

Next, execute using four workers.

npx playwright test --workers=4

Compare the results.

Execution

Result

One worker

All tests pass

Four workers

Some tests fail

This suggests a possible shared-state or concurrency problem.

However, it does not automatically prove a dependency between two tests.

You should investigate shared accounts, database records, files and external services.

5. Method 3: Check Whether Tests Share the Same Data

Test data is one of the most common sources of hidden dependencies.

Imagine two tests use the same customer.

Test A:

test('Update customer email', async ({ request }) => {


  await request.put('/api/customer/123', {

    data: {

      email: 'new@example.com'

    }

  });


});

Test B:

test('Verify original customer email', async ({ request }) => {


  const response = await request.get('/api/customer/123');


  const customer = await response.json();


  expect(customer.email).toBe('old@example.com');


});

What happens if Test A executes before Test B?

Test B may fail because Test A changed the email.

The problem is not necessarily Playwright.

The tests are modifying the same backend record.

How to fix this problem

Give each test its own customer record.

For example:

test('Update customer email', async ({ request }) => {


  const customerId = `customer-${Date.now()}`;


  // Create a unique customer using your test API.


  // Update the customer.


  // Verify the updated email.


  // Clean up the customer.

});

In a production framework, use a reliable unique identifier or test-data factory rather than relying only on timestamps.

The important rule is:

One test should not unexpectedly change the data another test needs.

6. Method 4: Search for Shared Variables

Global variables can create hidden dependencies.

Example:

let orderId: string;


test('Create order', async () => {


  orderId = 'ORD123';


});


test('Verify order', async () => {


  console.log(orderId);


});

The second test assumes that the first test has assigned a value.

This is dangerous.

Playwright may execute tests in separate worker processes. A variable in one worker is not a reliable way to communicate state to another worker.

What should you search for?

Inspect your framework for:

  • Global variables.

  • Module-level variables.

  • Shared objects.

  • Variables modified by multiple tests.

  • Common mutable arrays.

  • Shared file paths.

Better approach

Create the order within the test that needs it, or use a fixture that creates the order and manages its cleanup.

7. Method 5: Inspect beforeEach, beforeAll and afterEach Hooks

Hooks are useful, but incorrect hook design can introduce hidden state.

Consider:

test.beforeAll(async ({ browser }) => {


  const page = await browser.newPage();


  await page.goto('/login');


});

This creates a page in a shared setup scope rather than using each test's normal page fixture.

If tests reuse mutable state from that page, they may interfere with each other.

For ordinary independent UI tests, prefer test-scoped page setup.

Example:

test.beforeEach(async ({ page }) => {


  await page.goto('/login');


  await page.getByLabel('Email')

    .fill('user@example.com');


  await page.getByLabel('Password')

    .fill('Password123');


  await page.getByRole('button', {

    name: 'Login'

  }).click();


});

The setup executes for each test.

For a deeper understanding, read:

Playwright Hooks: beforeEach and afterEach

8. Method 6: Use Randomized Test Ordering

Changing the execution order can help reveal tests that secretly depend on previous tests.

For example, your tests may normally execute as:

  1. Login

  2. Create Product

  3. Add to Cart

  4. Checkout

But a different order may expose hidden assumptions.

Playwright does not provide a universal built-in random-order flag for all test suites.

You can implement controlled randomization using a test-list generator or a suitable test-runner extension.

The important part is to:

  1. Record the randomized order.

  2. Reproduce the failing execution.

  3. Identify the test that prepared the missing state.

  4. Remove the dependency.

  5. Repeat the test.

Do not confuse random ordering with parallel execution. They help expose different problems.

9. Method 7: Use Playwright Reports and Trace Viewer

Playwright provides useful debugging tools.

HTML Report

Execute:

npx playwright test

Open the report:

npx playwright show-report

The report helps you inspect:

  • Failed tests.

  • Passed tests.

  • Execution details.

  • Error messages.

  • Test durations.

Trace Viewer

You can enable tracing in your Playwright configuration.

import { defineConfig } from '@playwright/test';


export default defineConfig({


  use: {


    trace: 'retain-on-failure'


  }


});

After a failure, open the generated trace using the Playwright Trace Viewer.

npx playwright show-trace trace.zip

You can inspect:

  • Browser actions.

  • Screenshots.

  • DOM snapshots.

  • Network activity.

  • Errors.

  • Action timing.

For example, you may discover that the profile page failed because the test was not authenticated.

The trace helps you understand what happened before the failure.

It does not automatically identify every cross-test dependency, so combine it with test-data and execution-order investigation.

10. Real-Time Example: Finding a Hidden Login Dependency

Imagine you have two tests.

Test A:

test('Login to application', async ({ page }) => {


  await page.goto('/login');


  await page.getByLabel('Email')

    .fill('user@example.com');


  await page.getByLabel('Password')

    .fill('Password123');


  await page.getByRole('button', {

    name: 'Login'

  }).click();


});

Test B:

test('Verify account settings', async ({ page }) => {


  await page.goto('/settings');


  await expect(

    page.getByRole('heading', {

      name: 'Account Settings'

    })

  ).toBeVisible();


});

Suppose Test B works after Test A but fails when executed alone.

The investigation reveals that Test B expects an authenticated session.

The correct solution is to prepare authentication independently.

You can use a test-scoped login fixture or Playwright's authentication storage-state approach.

This allows tests to reuse authentication information without depending on another ordinary test.

Remember that authentication storage files contain sensitive information and must not be committed to source control.

Official documentation:

Playwright Authentication

11. Practical Checklist: Find Hidden Test Dependencies

Use this checklist when investigating a large Playwright project.

Investigation

What to check

Individual execution

Does the test pass alone?

Execution order

Does changing the order affect results?

Worker count

Do failures appear with multiple workers?

Shared accounts

Are multiple tests modifying one account?

Global variables

Are tests sharing mutable state?

Database records

Are tests modifying the same records?

Browser state

Is a page or context reused incorrectly?

Hooks

Is setup happening at the correct scope?

Fixtures

Are shared fixtures introducing side effects?

Files

Are multiple tests writing to the same file?

External services

Are tests depending on unstable third-party systems?

12. How to Fix Test Dependencies Permanently

Finding a dependency is only the first step.

You must correct the automation design.

Follow these steps.

Step 1: Identify the failing test.

Run it individually.

Step 2: Find the missing requirement.

Check whether the test needs an account, session, record or file.

Step 3: Find where that requirement is created.

Search your test files, hooks and fixtures.

Step 4: Move setup closer to the test.

Use a test-scoped fixture, API setup or suitable beforeEach hook.

Step 5: Separate shared data.

Create unique accounts and database records when necessary.

Step 6: Execute tests independently.

Verify that the test works without another test running first.

Step 7: Test parallel execution.

Run the suite using an appropriate worker count.

Step 8: Check the results again.

The fix should remove the dependency rather than simply hide the failure.

13. Frequently Asked Questions

How do I know if a Playwright test depends on another test?

Run the test individually. If it fails alone but passes after another test executes, investigate shared browser state, test data and setup dependencies.

Why do Playwright tests pass individually but fail in parallel?

Possible causes include shared database records, common accounts, conflicting files, shared server settings and race conditions.

How can I find shared test data in Playwright?

Inspect API setup, database utilities, test-data files, global variables and fixtures. Look for multiple tests modifying the same records.

Can Playwright automatically detect test dependencies?

Playwright provides isolation features and debugging tools, but it does not automatically identify every logical dependency between test cases.

Should I use serial execution to fix dependent tests?

Serial execution may preserve a required order temporarily, but Playwright recommends independent tests rather than relying on serial execution as the normal solution.

What is the best way to prevent test dependencies?

Give every test the state, resources and data it requires through independent setup or appropriately designed fixtures.

Why does increasing workers create failures?

More workers can expose conflicts involving shared resources. Increasing workers does not automatically make an automation suite faster or more reliable.

Conclusion

Finding test dependencies is an important skill for every professional automation tester.

A test that works only after another test executes is difficult to debug, maintain and scale.

Use individual execution, worker comparisons, test-data inspection, hook analysis and Playwright Trace Viewer to identify the actual cause.

Fix the underlying design problem instead of depending on execution order or increasing retries.

Remember: A reliable Playwright test should be able to execute independently without requiring another ordinary test to prepare its state.

Want to develop professional automation testing skills? Explore the Playwright Automation Testing Course at PlaywrightMasters and learn real-time automation framework development.


Comments

Popular posts from this blog

How to Run Only Smoke Tests in Playwright: Step-by-Step Guide

How to Test REST APIs Using Playwright

Playwright Multiple Tabs and Windows Explained: A Practical Guide