1.4.5 • Published 5 months ago

playwright-cli-runner v1.4.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Playwright CLI Runner šŸŽ­

A simple CLI tool to run Playwright scripts.

Installation

npm install -g playwright-cli-runner

Features

  • āœ… Interactive Test Selection: Users can select test files interactively via CLI.
  • āœ… Automated Test Execution: If a test file is selected, it is automatically executed using Playwright.
  • āœ… Manual Testing Option: If no test file is found, the script prompts for a URL and opens it in a browser.
  • āœ… Browser Selection: Supports Chromium, Firefox, and WebKit.
  • āœ… Headless Mode: Option to run tests in headless or headed mode.
  • āœ… Screenshot Capture: Saves a screenshot after navigation.
  • āœ… JSON Test Report: Generates a detailed JSON report with test execution details, including status, duration, assertions, steps, screenshots, and environment info.
  • āœ… Page Object Model (POM) Support: Uses POM for better test organization and maintainability.
  • āœ… HTML Test Report: Generates an HTML test report after execution.

Usage

Run the CLI tool in your project directory:

playwright-cli

Interactive Mode

  1. Select a test file (if available).
  2. Choose a browser (Chromium, Firefox, WebKit).
  3. Enter a URL (only if no test files are found).
  4. Choose headless or headed mode.

Running Tests

  • If a test file is selected, the script runs:
    npx playwright test tests/<selected-test>.spec.ts --browser=<selected-browser>
  • If no test file is available, it launches Playwright in manual mode:
    Opening <URL> in <selected-browser> (Headless/Headed)...

Example:

? Select a test file: login.spec.ts
? Select a browser: chromium
šŸš€ Running test: login.spec.ts in chromium (Headed)...

Screenshot Feature

  • If running in manual mode, a screenshot (screenshot.png) is saved after navigation.

JSON Test Report

After test execution, a JSON report (report.json) is generated with the following structure:

{
  "testFile": "new-test.spec.ts",
  "testName": "Example Domain Navigation",
  "testDescription": "Tests navigation and clicks on Example Domain",
  "browserType": "firefox",
  "url": "https://example.com",
  "headless": true,
  "status": "Passed",
  "startTime": "2025-02-13T13:14:28.496Z",
  "endTime": "2025-02-13T13:14:38.022Z",
  "duration": "9.526 seconds",
  "totalSteps": 8,
  "assertions": {
    "total": 3,
    "passed": 3,
    "failed": 0
  },
  "steps": [
    { "step": 1, "action": "navigate", "url": "https://example.com", "status": "passed" },
    { "step": 2, "action": "click", "selector": "h1", "status": "passed" },
    { "step": 3, "action": "click", "selector": "p", "status": "passed" }
  ],
  "screenshots": ["screenshots/step1.png", "screenshots/failure.png"],
  "video": "videos/test-run.mp4",
  "environment": {
    "OS": "Windows 11",
    "NodeVersion": "18.16.0",
    "PlaywrightVersion": "1.39.0"
  },
  "retries": 1,
  "errorMessage": "",
  "errorStack": ""
}

HTML Test Report

  • After test execution, an HTML report is generated in the playwright-report/ folder.
  • Open playwright-report/index.html in a browser to view the results.

Page Object Model (POM) Structure

The project follows a POM structure for better organization and maintainability:

/playwright-pom-project
│── /tests                   # Test cases
│   ā”œā”€ā”€ login.spec.ts        # Login test
│   ā”œā”€ā”€ homepage.spec.ts     # Homepage test
│── /pages                   # Page Object Model (POM) files
│   ā”œā”€ā”€ basePage.ts          # Base Page (common methods)
│   ā”œā”€ā”€ loginPage.ts         # Login Page class
│   ā”œā”€ā”€ homePage.ts          # Home Page class
│── /utils                   # Utility functions
│   ā”œā”€ā”€ utils.ts             # Common utility functions
│── /config                  # Configuration settings
│   ā”œā”€ā”€ playwright.config.ts # Playwright config file
│── /playwright-report       # HTML reports (generated after running tests)
│── /screenshots             # Screenshots taken during test execution
│── /videos                  # Videos recorded during test execution
│── package.json             # NPM package file
│── tsconfig.json            # TypeScript configuration file
│── README.md                # Documentation
│── node_modules/            # Installed dependencies

Requirements

  • Node.js installed

License

MIT

1.4.5

5 months ago

1.3.4

5 months ago

1.2.4

5 months ago

1.1.4

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago