Playwright + TS · Lesson 13 of 36

0/36 done

Module 13: Automation Project Structure

13. Enterprise Project Architecture & Folder Standards

15 minlesson

Try it yourself

Define the StandardFolder union type and isStandardFolder type guard:

  1. Allowed values: "tests", "pages", "components", "fixtures", "utils", "data", "types", "config".
  2. Return true if folderName is in the standard list.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

The Standard Playwright Project Blueprint

A chaotic test repository with tests, locators, and configs mixed together in the root directory quickly collapses under maintenance debt. Here is the industry standard structure:

text
playwright-project/
├── playwright.config.ts    # Central Playwright runner settings
├── tsconfig.json           # TypeScript compilation and path aliases
├── package.json            # Dependencies and npm scripts
│
├── tests/                  # Spec files (.spec.ts) organized by feature/domain
│   ├── auth/
│   │   ├── login.spec.ts
│   │   └── reset-password.spec.ts
│   └── checkout/
│       └── checkout-flow.spec.ts
│
├── pages/                  # Page Object Model classes (business workflows)
│   ├── BasePage.ts
│   ├── LoginPage.ts
│   └── DashboardPage.ts
│
├── components/             # Reusable UI fragments (Navigation, Modals, Tables)
│   ├── HeaderComponent.ts
│   └── NotificationToast.ts
│
├── fixtures/               # Custom test fixtures (injected page objects, states)
│   └── test-base.ts
│
├── utils/                  # Non-browser utilities (date formatting, string helpers)
│   └── string-utils.ts
│
├── data/                   # Test fixtures, mock payloads, JSON files
│   ├── users.json
│   └── orders.json
│
├── types/                  # Shared TypeScript interfaces and type definitions
│   ├── user.types.ts
│   └── api.types.ts
│
└── config/                 # Environment endpoints and credentials
    └── environment.config.ts

Folder Roles Explained

  1. `tests/`: Contains only the test specifications (*.spec.ts). Tests should read like plain English user stories and contain minimal raw locators.
  2. `pages/`: Represents entire screens or routes. Encapsulates locators and user actions.
  3. `components/`: UI widgets that appear across multiple pages (e.g. Header bar, Sidebar menu, Confirmation dialog).
  4. `fixtures/`: Playwright's powerful dependency injection setup. Exposes pre-authenticated pages or initialized POMs directly into test function arguments.
  5. `utils/`: Pure functions for data manipulation, mathematical operations, or date calculations.
  6. `data/`: Raw static fixtures, sample CSV files, or test data mocks.
  7. `types/`: Strict TypeScript interfaces for API responses and test models.
  8. `config/`: URLs, credentials, and feature flags.

Key Takeaways & Walkthrough Summary

Before diving into browser actions, let's explore professional automation project structure. In this lesson, we will tour a clean industry-standard Playwright repository, breaking down the purpose of tests, pages, components, fixtures, utils, data, types, and config directories. Let's explore the blueprint!

Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why separate components/ from pages/?

A navigation header or modal dialog appears on dozens of pages. Creating a single HeaderComponent avoids duplicating navigation locators in every single Page Object.

Should test data JSON files live inside tests/ folder?

No. Keeping data/ centralized allows multiple test suites to reuse identical mock payloads and prevents test specs from becoming bloated with raw JSON strings.

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

TypeScript
Skip