1. Introduction to Monorepos for Playwright TypeScript
Modern software companies often maintain multiple web applications, such as customer portals, admin dashboards, payment applications, and inventory systems.
Testing each application using a separate automation framework can create maintenance problems. QA engineers may need to maintain duplicate dependencies, configurations, page objects, utilities, and reporting mechanisms.
A monorepo provides a centralized solution.
Playwright TypeScript monorepo setup allows automation teams to maintain multiple Playwright projects inside a single Git repository while sharing common testing components.
Using npm workspaces, teams can organize application-specific tests, reusable fixtures, shared TypeScript configurations, and common utilities.
In this tutorial, we will build a practical monorepo containing two applications:
- E-commerce application.
- Admin application.
We will also implement shared page objects, reusable fixtures, independent test execution, parallel testing, and GitHub Actions integration.
2. What Is a Monorepo and When Should You Use One?
A monorepo, or monolithic repository, is a development approach where multiple projects are maintained inside one version-controlled repository.
Instead of creating separate Git repositories for every automation project, teams organize all related applications and packages under one root directory.
Example:
playwright-monorepo/
│
├── apps/
│ ├── ecommerce/
│ └── admin/
│
├── packages/
│ └── shared/
│
├── package.json
├── tsconfig.json
└── package-lock.json
Each application has its own test cases and configuration. The shared package contains reusable automation components.
Benefits of Playwright Monorepo Architecture
- Code reusability: Share page objects, fixtures, and utilities across applications.
- Centralized dependencies: Manage common packages from one root directory.
- Easy maintenance: Update shared automation components in one location.
- Independent execution: Run regression tests for individual applications.
- Consistent standards: Maintain common TypeScript and Playwright conventions.
- Team collaboration: Multiple QA engineers can contribute to different application projects.
A monorepo is particularly useful when applications share automation infrastructure. Completely independent applications may be better maintained in separate repositories.
3. Prerequisites and Project Setup
Before starting the playwright typescript monorepo setup tutorial, install:
- Node.js LTS.
- npm.
- Visual Studio Code.
- Git.
- Basic TypeScript knowledge.
- Basic Playwright knowledge.
Step 1: Create the Root Project
Open your terminal:
mkdir playwright-monorepo
cd playwright-monorepo
npm init -y
Install Playwright and TypeScript:
npm install -D @playwright/test typescript
Install browser binaries:
Step 2: Create Application Directories
mkdir -p apps/ecommerce/tests
mkdir -p apps/ecommerce/pages
mkdir -p apps/admin/tests
mkdir -p apps/admin/pages
mkdir -p packages/shared/pages
mkdir -p packages/shared/fixtures
mkdir -p packages/shared/utils
These directories separate application-specific automation from reusable components.
4. Choose a Workspace Tool: npm Workspaces, pnpm, or Turborepo
Workspace tools help manage multiple packages inside one repository.
| Tool | Main purpose | Recommended usage |
| npm workspaces | Built-in package management | Beginners and standard projects |
| pnpm workspaces | Efficient dependency installation | Large monorepos |
| Turborepo | Task orchestration and caching | Complex enterprise repositories |
For this playwright typescript monorepo setup example, we will use npm workspaces because it is simple and beginner-friendly.
Configure Root package.json
Update the root package.json:
{
“name”: “playwright-monorepo”,
“version”: “1.0.0”,
“private”: true,
“workspaces”: [
“apps/*”,
“packages/*”
],
“scripts”: {
“test:ecommerce”: “npm run test –workspace=@qa/ecommerce,
“test:admin”: “npm run test –workspace=@qa/admin,
“test:all”: “npm run test –workspaces –if-present”
},
“devDependencies”: {
“@playwright/test”: “^1.56.0”,
“typescript”: “^5.9.0”
}
}
The version numbers are illustrative. Use compatible versions available in your environment.
Important properties:
- private: true prevents accidental publication of the root package.
- workspaces identifies application and shared packages.
- test:ecommerce executes e-commerce tests.
- test:admin executes admin tests.
- test:all runs test scripts across configured workspaces.
5. Create the Complete Monorepo Folder Structure
The recommended Playwright Monorepo Architecture looks like this:
playwright-monorepo/
│
├── apps/
│ ├── ecommerce/
│ │ ├── tests/
│ │ │ └── product.spec.ts
│ │ ├── pages/
│ │ │ └── product.page.ts
│ │ ├── playwright.config.ts
│ │ └── package.json
│ │
│ └── admin/
│ ├── tests/
│ │ └── login.spec.ts
│ ├── pages/
│ │ └── login.page.ts
│ ├── playwright.config.ts
│ └── package.json
│
├── packages/
│ └── shared/
│ ├── pages/
│ │ └── header.page.ts
│ ├── fixtures/
│ │ └── base.fixture.ts
│ ├── utils/
│ │ └── test-data.ts
│ └── package.json
│
├── .github/
│ └── workflows/
│ └── playwright.yml
│
├── package.json
├── package-lock.json
└── tsconfig.json
This architecture provides clear project boundaries and makes future application additions easier.
6. Configure Shared TypeScript Settings and Dependencies
Create a root tsconfig.json:
{
“compilerOptions”: {
“target”: “ES2022”,
“module”: “CommonJS”,
“moduleResolution”: “Node”,
“strict”: true,
“esModuleInterop”: true,
“skipLibCheck”: true,
“forceConsistentCasingInFileNames”: true
},
“include”: [
“apps/**/*.ts”,
“packages/**/*.ts”
]
}
The shared configuration ensures consistent TypeScript compilation across applications.
Configure E-commerce Workspace
Create apps/ecommerce/package.json:
{
“name”: “@qa/ecommerce”,
“version”: “1.0.0”,
“private”: true,
“scripts”: {
“test”: “playwright test”,
“test:headed”: “playwright test –headed,
“test:debug”: “playwright test –debug
}
}
Configure Admin Workspace
Create apps/admin/package.json:
{
“name”: “@qa/admin”,
“version”: “1.0.0”,
“private”: true,
“scripts”: {
“test”: “playwright test”,
“test:headed”: “playwright test –headed”,
“test:debug”: “playwright test –debug”
}
}
Both applications use the root Playwright dependency.
Create packages/shared/package.json:
{
“name”: “@qa/shared”,
“version”: “1.0.0”,
“private”: true
}
Run:
npm install
npm will create or update the root lockfile and link the workspace packages.
7. Create Separate Playwright Test Projects for Different Applications
Each application should have an independent Playwright configuration.
E-commerce Configuration
Create apps/ecommerce/playwright.config.ts:
import { defineConfig } from ‘@playwright/test’;
export default defineConfig({
testDir: ‘./tests’,
fullyParallel: true,
reporter: ‘html’,
use: {
baseURL: ‘https://example.com’,
browserName: ‘chromium’,
headless: true
},
workers: 2
});
Admin Configuration
Create apps/admin/playwright.config.ts:
import { defineConfig } from ‘@playwright/test’;
export default defineConfig({
testDir: ‘./tests’,
fullyParallel: true,
reporter: ‘html’,
use: {
baseURL: ‘https://admin.example.com’,
browserName: ‘chromium’,
headless: true
},
workers: 2
});
Each configuration defines its own application URL, test directory, browser, and execution settings.
This separation prevents unnecessary configuration conflicts between applications.
8. Share Page Objects, Fixtures, Utilities, and Test Data
Shared components are one of the biggest advantages of a TypeScript Monorepo.
Instead of implementing common functionality repeatedly, create reusable automation components.
Step 1: Create a Shared Page Object
Create packages/shared/pages/header.page.ts:
import { Page, Locator } from ‘@playwright/test’;
export class HeaderPage {
readonly logo: Locator;
readonly searchBox: Locator;
constructor(private page: Page) {
this.logo = page.locator(‘.logo’);
this.searchBox = page.locator(‘#search’);
}
async searchProduct(product: string) {
await this.searchBox.fill(product);
await this.searchBox.press(‘Enter’);
}
}
Step 2: Create Shared Test Data
Create packages/shared/utils/test-data.ts:
export const testData = {
product: {
name: ‘Laptop’,
price: 50000
},
user: {
email: ‘test@example.com’,
password: ‘Password123’
}
};
Keep actual passwords and tokens in environment variables or a secrets manager.
Step 3: Create a Shared Fixture
Create packages/shared/fixtures/base.fixture.ts:
import {
test as base,
expect
} from ‘@playwright/test’;
import { HeaderPage } from ‘../pages/header.page’;
type Fixtures = {
headerPage: HeaderPage;
};
export const test = base.extend<Fixtures>({
headerPage: async ({ page }, use) => {
await use(new HeaderPage(page));
}
});
export { expect };
Now application-specific tests can reuse the same fixture.
Example:
import {
test,
expect
} from ‘../../../packages/shared/fixtures/base.fixture’;
test(‘Verify product search’, async ({
page,
headerPage
}) => {
await page.goto(‘/products’);
await headerPage.searchProduct(‘Laptop’);
await expect(
page.getByText(‘Laptop’)
).toBeVisible();
});
This approach improves maintainability and reduces duplicate code.
9. Configure Scripts to Run Tests Independently or Together
A good Playwright Workspace Setup should support flexible test execution.
Run e-commerce tests:
npm run test:ecommerce
Run admin tests:
npm run test:admin
Run all workspace tests:
npm run test:all
Run e-commerce tests in headed mode:
npm run test:headed –workspace=@qa/ecommerce
Run tests with four workers:
npx playwright test \
-c apps/ecommerce/playwright.config.ts \
–workers=4
Parallel execution reduces testing time, but worker counts should be adjusted according to available system resources and application stability.
10. Integrate Monorepo Tests with GitHub Actions or Jenkins
CI/CD integration ensures that application regression tests execute automatically during development.
Create .github/workflows/playwright.yml:
name: Playwright Monorepo Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
ecommerce-tests:
runs-on: ubuntu-latest
steps:
– uses: actions/checkout@v4
– uses: actions/setup-node@v4
with:
node-version: lts/*
– run: npm ci
– run: npx playwright install –with-deps chromium
– run: npm run test:ecommerce
admin-tests:
runs-on: ubuntu-latest
steps:
– uses: actions/checkout@v4
– uses: actions/setup-node@v4
with:
node-version: lts/*
– run: npm ci
– run: npx playwright install –with-deps chromium
– run: npm run test:admin
Both jobs run independently, allowing e-commerce and admin regression tests to execute in parallel.
For Jenkins, use the same npm workspace commands in separate pipeline stages.
pipeline {
agent any
stages {
stage(‘Install Dependencies’) {
steps {
sh ‘npm ci’
}
}
stage(‘Install Browsers’) {
steps {
sh ‘npx playwright install –with-deps chromium’
}
}
stage(‘E-commerce Tests’) {
steps {
sh ‘npm run test:ecommerce’
}
}
stage(‘Admin Tests’) {
steps {
sh ‘npm run test:admin’
}
}
}
}
For enterprise pipelines, also publish HTML reports and test artifacts for each application.
11. Troubleshooting Common Monorepo Issues
| Problem | Possible Solution |
| Workspace package not found | Verify package names and workspace patterns |
| Playwright command not recognized | Install Playwright at the root and run npm install |
| Tests execute from the wrong directory | Specify the correct configuration path |
| Shared imports fail | Verify TypeScript paths and relative imports |
| Configuration conflicts | Maintain separate application configurations |
| Parallel tests fail | Check shared data and application state |
| Dependency version conflicts | Centralize shared dependencies |
| Browser installation fails in CI | Install browsers using Playwright’s installation command |
Best Practices
Follow these recommendations when developing an enterprise automation framework:
- Keep application-specific tests in separate directories.
- Maintain shared fixtures and utilities centrally.
- Use consistent TypeScript configurations.
- Avoid unnecessary dependency duplication.
- Keep application environments separate.
- Use meaningful workspace package names.
- Support independent test execution.
- Configure parallel workers carefully.
- Store credentials securely.
- Maintain separate test reports.
- Review shared framework changes through pull requests.
- Avoid putting unrelated application logic into shared packages.
12. Frequently Asked Questions (FAQs)
Q1. What is playwright typescript monorepo setup?
It is an approach to managing multiple Playwright automation projects inside a single repository using TypeScript, shared dependencies, and workspace tools.
Q2. How do I get started with playwright typescript monorepo setup?
Create a root Node.js project, install Playwright and TypeScript, configure npm workspaces, create application directories, and add shared fixtures and utilities.
Q3. What are the benefits of playwright typescript monorepo setup?
The main benefits include code reusability, centralized dependency management, independent test execution, easier maintenance, and consistent automation standards.
Q4. Which workspace tool is best for Playwright?
npm workspaces are suitable for beginners. pnpm is useful for efficient dependency management, while Turborepo is suitable for advanced task orchestration and caching.
Q5. Can multiple Playwright applications run in one monorepo?
Yes. Each application can have an independent Playwright configuration, test directory, environment, and npm script.
Q6. Can we share page objects between applications?
Yes. Place reusable page objects in a shared package and import them into application-specific tests. Share only components with compatible behavior.
Q7. Is a monorepo suitable for enterprise automation?
Yes. It is useful when multiple applications share testing infrastructure and teams need centralized tooling, reusable components, and coordinated regression testing.
