Simple Playwright Framework
The `simple-playwright-framework` (current version 0.0.33) is a lightweight and modular TypeScript-based automation framework built on Microsoft Playwright. It aims to accelerate the setup of scalable UI and API test automation projects by providing a clean architecture, reusable fixtures, and streamlined onboarding processes. Key features include custom Playwright fixtures for authentication and state management, a `scenarioLoader` for environment-driven test data (supporting JSON, API, or DB integration), and a flexible provider registry for various authentication flows. It supports environment-aware configuration, offers reusable helpers for common test scenarios, and integrates with modern reporting tools like Playwright HTML, Allure, and TestRail. The framework also includes a CLI scaffolding tool (`npx init-demo-project`) to generate demo projects with recommended structures, promoting CI/CD readiness through parallel safety and isolated test states. Given its pre-1.0 version, the release cadence is likely agile, with frequent updates that may include API adjustments.
Common errors
-
Error: Cannot find module 'simple-playwright-framework' or its corresponding type declarations.
cause The package is either not installed, or your module resolver (TypeScript compiler, bundler, or Node.js runtime) cannot locate the package correctly. This was a known issue in earlier versions related to module bundling.fixRun `npm install simple-playwright-framework`. Verify your `tsconfig.json`'s `moduleResolution` and `baseUrl`/`paths` settings are compatible with an ESM-first package. If using CommonJS, ensure you are using dynamic `import()` or configuring your build tools for ESM compatibility. -
TypeError: scenarioLoader is not a function
cause This error typically indicates that `scenarioLoader` was not correctly imported or is not available from the imported module. This can occur with incorrect `require` syntax in CommonJS contexts or if module bundling/tree-shaking inadvertently removes the export.fixEnsure you are using the correct ESM import syntax: `import { scenarioLoader } from 'simple-playwright-framework';`. Avoid CommonJS `require` statements directly. Verify the package is installed and at a version that exports `scenarioLoader`. -
Playwright test run failed: No tests found
cause This occurs when `playwright` cannot locate any test files. This might be due to running the `npx playwright test` command from an incorrect directory (not the project root) or if the `playwright.config.ts` file has an incorrect `testMatch` pattern.fixAfter scaffolding, navigate into the generated `demo-project` directory (e.g., `cd demo-project`). Confirm that your `playwright.config.ts` has a `testMatch` property that correctly identifies your test files (e.g., `testMatch: '**/*.spec.ts'`).
Warnings
- breaking Earlier versions experienced 'Compiled JS confusion' which led to module resolution changes, moving output to 'dist' and enforcing root-level exports. This likely necessitated updating import paths or build configurations for users upgrading from older pre-1.0 versions.
- gotcha The framework emphasizes correct usage of its custom fixtures and helpers. Users might inadvertently bypass these by importing Playwright's base `test` object or not properly configuring `playwright.config.ts` to utilize framework-provided extensions.
- gotcha As a pre-1.0 (0.0.x) package, `simple-playwright-framework` does not strictly adhere to Semantic Versioning. Minor or even patch releases may introduce breaking changes to the API without a major version increment.
- gotcha The framework is designed for parallel safety by advocating 'test-scoped' state and avoiding 'global mutation'. Improper handling of shared state across tests or Playwright workers can lead to flaky or inconsistent test results.
Install
-
npm install simple-playwright-framework -
yarn add simple-playwright-framework -
pnpm add simple-playwright-framework
Imports
- scenarioLoader
const scenarioLoader = require('simple-playwright-framework').scenarioLoader;import { scenarioLoader } from 'simple-playwright-framework'; - initDemoProject
npx init-demo-project
- test, expect (Playwright base)
import { test, expect } from '@playwright/test';
Quickstart
npm install --save-dev @playwright/test playwright
npm install simple-playwright-framework
npx init-demo-project
# Navigate into the generated project
cd demo-project
# Example test from the generated project (e.g., tests/login.spec.ts)
// import { test, expect } from '@playwright/test';
// import { scenarioLoader } from 'simple-playwright-framework';
// test('login works', async ({ page }) => {
// const data = scenarioLoader(__filename).get("validLogin");
// await page.goto(data.baseUrl);
// await page.fill('#username', data.username);
// await page.fill('#password', data.password);
// await page.click('#login');
// await expect(page).toHaveURL(/dashboard/);
// });
# Run tests
npx playwright test
# Or run tests with Playwright UI runner
npx playwright test --ui