1.4.5 ⢠Published 5 months ago
playwright-cli-runner v1.4.5
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
- Select a test file (if available).
- Choose a browser (Chromium, Firefox, WebKit).
- Enter a URL (only if no test files are found).
- 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