playwright-tools
v0.1.6
Published
π A collection of utilities for Playwright TypeScript
Maintainers
Readme
π playwright-tools
A comprehensive collection of utilities for Playwright testing that simplify common testing patterns and enhance your automation workflow.
β¨ Features
- π‘οΈ Safe Element Interactions - Built-in waits and error handling for reliable interactions
- π Retry Mechanisms - Exponential backoff retry logic for flaky operations
- πΈ Enhanced Screenshots - Timestamped screenshots with debugging annotations
- π Element Queries - Existence checks and bulk operations without throwing errors
- π Navigation Utilities - Safe navigation with loading state checks
- β¨οΈ Advanced Interactions - File uploads, drag & drop, keyboard shortcuts
- π Table Utilities - Extract and validate table data efficiently
- π― Accessibility Helpers - Check ARIA attributes and accessibility properties
- πΎ Storage Management - Handle localStorage and sessionStorage operations
- π Network Helpers - Wait for specific requests and monitor network activity
- π§ Page Objects - Reusable page object patterns and utilities
- π Test Data Factories - Generate consistent test data across tests
- π Assertions - Enhanced assertion helpers for multiple elements
- β‘ Test Utilities - Filter and dispatch tests with skip/runOnly flags
- π§ͺ TypeScript Support - Full type safety with comprehensive TypeScript definitions
- πͺΆ Zero Dependencies - No additional dependencies beyond Playwright
π¦ Installation
npm install playwright-toolsPeer Dependency: This package requires @playwright/test to be installed in your project.
npm install @playwright/testπ Quick Start
Basic Usage
import { safeClick, safeFill, elementExists } from "playwright-tools";
// Safe element interactions
await safeClick(page.locator("#submit-button"));
await safeFill(page.locator("#username"), "[email protected]");
// Check element existence without throwing
const exists = await elementExists(page.locator("#optional-element"));Modular Imports
Import specific modules for better tree-shaking:
// Import specific modules
import { safeClick, safeFill } from "playwright-tools/interactions";
import { waitForElements, elementExists } from "playwright-tools/element-queries";
import { takeTimestampedScreenshot } from "playwright-tools/screenshots";
import { retryAction } from "playwright-tools/retry";
// Or import everything
import * as pwUtils from "playwright-tools";π Documentation
π Complete documentation is available in the docs directory:
- π Main Documentation - Overview and navigation
- π― Element Interactions - Safe clicks, fills, and form handling
- π Element Queries - Existence checks and bulk operations
- π Navigation - Safe navigation and page management
- β¨οΈ Advanced Interactions - File uploads, drag & drop, keyboard shortcuts
- π Locator Decorator - Extend Playwright locators with custom methods
- πΈ Screenshots - Timestamped and debug screenshots
- π Assertions - Enhanced assertion helpers
- β³ Waiting - Smart waiting strategies
- π Retry - Exponential backoff retry logic
- π― Accessibility - ARIA and accessibility testing
- πΎ Storage - localStorage and sessionStorage management
- π Network - Network request monitoring and waiting
- π Network Monitoring - Advanced network analysis
- π¬ Dialogs - Modal and popup handling
- π Tables - Table data extraction and validation
- π§ Page Objects - Reusable page object patterns
- β‘ Performance - Performance measurement utilities
- π οΈ Error Handling - Error handling patterns
- β‘ Test Utils - Test filtering and dispatching
Guides & Examples
- π Examples - Practical usage examples
- π Migration Guide - From raw Playwright to playwright-tools
- π οΈ Best Practices - Recommended patterns and configurations
π‘ Quick Examples
Form Handling
import { fillForm, safeClick } from "playwright-tools";
await fillForm([
{ locator: page.locator("#username"), value: "john.doe" },
{ locator: page.locator("#password"), value: "secure123" },
{ locator: page.locator("#email"), value: "[email protected]" },
]);
await safeClick(page.locator("#submit"));Element Queries
import { elementExists, waitForElements } from "playwright-tools";
// Check if element exists without throwing
const exists = await elementExists(page.locator("#optional-element"));
// Wait for multiple elements concurrently
await waitForElements([
page.locator("#header"),
page.locator("#navigation"),
page.locator("#content"),
]);Network Monitoring
import { waitForNetworkRequest } from "playwright-tools";
// Wait for specific API call
const response = await waitForNetworkRequest(page, "/api/users", {
method: "GET",
status: 200,
timeout: 10000,
});Retry Logic
import { retryAction } from "playwright-tools";
// Retry flaky operations with exponential backoff
const result = await retryAction(
async () => {
await page.click("#sometimes-slow-button");
return await page.locator("#result").textContent();
},
{ maxRetries: 3, baseDelay: 1000 }
);Locator Decorator
The Locator Decorator lets you extend Playwright locators with custom methods, enhanced safe interactions, and even method overrides. This makes your locators more powerful, reusable, and tailored to your app.
Key Features
- Add your own methods to any locator
- Use enhanced methods like
safeClick,safeFill,extractData, and more - Override existing locator methods (e.g., custom
click) - Factory and page extension patterns for consistent usage
Quick Example
import { createEnhancedLocator, extendPage } from "playwright-tools";
// Enhance a single locator
const enhanced = createEnhancedLocator(page.locator("#my-btn"), {
customMethods: {
async highlight() {
await this.evaluate(el => el.style.border = "2px solid red");
}
}
});
await enhanced.safeClick();
await enhanced.highlight();
// Or extend the whole page for consistent usage
const enhancedPage = extendPage(page, {
customMethods: {
async waitForAnimation() {
await this.waitForFunction(() => !document.querySelector('[style*="animation"]'));
}
}
});
const btn = enhancedPage.locator("#my-btn");
await btn.safeClick();
await btn.waitForAnimation();See the full documentation:
π Locator Decorator Guide
π Quick Links
- π Full Documentation
- π Examples
- π Migration Guide
- π οΈ Best Practices
- π Issues & Bug Reports
- π¬ Discord Community
π Resources & Learning Materials
π¦ Practice Application
- GAD (GUI API Demo) - Our free application designed specifically for automation practice
π΅π± Polish Resources
- Free Playwright Resources - Comprehensive Polish learning materials
- Playwright Basics - YouTube series (Polish)
- Playwright Elements - Advanced concepts (Polish)
- Playwright MCP - MCP course (Polish)
- Discord Community - First Polish Playwright community!
- Playwright Info - First and only Polish Playwright blog
π¬π§ English Resources
- VS Code Extensions - Our free Playwright plugins
- Playwright Documentation - Official documentation
- Playwright GitHub - Source code and issues
π Contact & Support
Feel free to reach out to us:
- π Website: jaktestowac.pl
- πΌ LinkedIn: jaktestowac.pl
- π¬ Discord: Polish Playwright Community
- π§ Support: Check our website for contact details
- π Issues: GitHub Issues
π Show Your Support
If you found this package helpful:
- β Star this repository to show your support
- π Share with your team to help spread knowledge about advanced Playwright testing patterns
- π£οΈ Tell the community about your experience with playwright-tools
- π Contribute by submitting issues or pull requests
Happy testing and automating tests! π
jaktestowac.pl Team πβ€οΈ
PS. For more resources and updates, follow us on our website and GitHub.
Built with πβ€οΈ for the Playwright and testing automation community
