1.0.24 • Published 5 months ago

playwright-logger v1.0.24

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

Playwright Logger

A simple and effective logging utility for Playwright automation tests. This library enhances debugging by automatically logging each test step and cleaning logs after every test run.

Features

  • Automatically logs every Playwright action.
  • Supports colored logs using chalk.
  • Cleans up logs after test execution.
  • Simple integration with Playwright.

Installation

To install the library, run:

npm install playwright-logger

Usage

Import and Extend Playwright Test

Modify your Playwright test setup to include the logger:

import { test } from 'playwright-logger';

test('Example test with logging', async ({ page }) => {
  await page.goto('https://example.com');
  await page.click('text=More information');
});

Custom Logging

You can use the logger manually within your test:

import { Logger } from 'playwright-logger';

// ✅ You no longer need to import from a submodule (e.g., `playwright-logger/dist`)

const logger = new Logger();
logger.logInfo('This is an informational log');
logger.logError('This is an error log');

Example Output

Here are some examples of how the logs appear in the terminal and log files:

Terminal Log Output

Terminal Log Output

Log File with Error Handling

Log File Example

Standard Log File Output

Standard Log File

Configuration

Package.json Support

Make sure you have the following added in your package.json file.

{
  "type": "module"
}

TypeScript Support

If you're using TypeScript, ensure your tsconfig.json includes:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "NodeNext",
    "outDir": "./dist",
    "rootDir": "./tests",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  },
  "include": ["tests/**/*"],
  "exclude": ["node_modules"]
}

Cleaning Logs

To automatically clean logs after each test, update package.json:

"scripts": {
  "playwright-test": "npx playwright test && rm -rf ./test-results"
}

Troubleshooting

If you encounter issues with chalk, ensure your project is using ES modules ("type": "module" in package.json).

Contributing

Feel free to open issues and submit pull requests on GitHub.

License

MIT License

1.0.24

5 months ago

1.0.23

5 months ago

1.0.22

5 months ago

1.0.21

5 months ago

1.0.20

5 months ago

1.0.19

5 months ago

1.0.18

5 months ago

1.0.17

5 months ago

1.0.16

5 months ago

1.0.15

5 months ago

1.0.14

5 months ago

1.0.13

5 months ago

1.0.12

5 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago