CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-playwright

A high-level API to automate web browsers and comprehensive framework for web testing

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

Playwright

Playwright is a comprehensive framework for web testing and automation that enables cross-browser testing across Chromium, Firefox, and WebKit with a single API. It provides both a high-level testing framework (Playwright Test) and low-level automation capabilities, featuring headless execution support, reliable element interactions, automatic waiting mechanisms, and powerful debugging tools.

Package Information

  • Package Name: playwright
  • Package Type: npm
  • Language: TypeScript/JavaScript
  • Installation: npm install playwright

Core Imports

import { chromium, firefox, webkit, devices } from 'playwright';

For testing framework:

import { test, expect } from 'playwright/test';

CommonJS:

const { chromium, firefox, webkit } = require('playwright');
const { test, expect } = require('playwright/test');

Basic Usage

Browser Automation

import { chromium } from 'playwright';

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  
  await page.goto('https://example.com');
  await page.click('button');
  await page.fill('input[name="email"]', 'user@example.com');
  await page.screenshot({ path: 'screenshot.png' });
  
  await browser.close();
})();

Testing Framework

import { test, expect } from 'playwright/test';

test('basic test', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page.locator('h1')).toHaveText('Welcome');
  await page.click('button');
  await expect(page.locator('.result')).toBeVisible();
});

Architecture

Playwright is structured around several key components:

  • Browser Types: Entry points for launching different browsers (Chromium, Firefox, WebKit)
  • Browser Management: Browser instances, contexts for isolation, and page management
  • Element Interaction: Locators with auto-waiting, element handles, and input simulation
  • Network Control: Request/response interception, API testing, and mocking capabilities
  • Testing Framework: Full-featured test runner with fixtures, assertions, and reporting
  • Mobile & Desktop: Device emulation, mobile testing, and Electron app automation
  • Debugging Tools: Tracing, video recording, screenshots, and inspector integration

Capabilities

Browser Control

Core browser automation functionality for launching browsers, managing contexts, and controlling pages across Chromium, Firefox, and WebKit.

const chromium: BrowserType;
const firefox: BrowserType;  
const webkit: BrowserType;

interface BrowserType {
  launch(options?: LaunchOptions): Promise<Browser>;
  launchPersistentContext(userDataDir: string, options?: BrowserContextOptions & LaunchOptions): Promise<BrowserContext>;
  connect(wsEndpoint: string, options?: ConnectOptions): Promise<Browser>;
}

Browser Control

Page Interaction

Page navigation, element interaction, and content manipulation with automatic waiting and cross-frame support.

interface Page {
  goto(url: string, options?: PageGotoOptions): Promise<Response | null>;
  locator(selector: string): Locator;
  click(selector: string, options?: PageClickOptions): Promise<void>;
  fill(selector: string, value: string, options?: PageFillOptions): Promise<void>;
  screenshot(options?: PageScreenshotOptions): Promise<Buffer>;
}

interface Locator {
  click(options?: LocatorClickOptions): Promise<void>;
  fill(value: string, options?: LocatorFillOptions): Promise<void>;
  textContent(): Promise<string | null>;
  isVisible(): Promise<boolean>;
}

Page Interaction

Network & API Testing

HTTP request interception, response mocking, and API testing capabilities with full request/response control.

const request: APIRequest;

interface APIRequestContext {
  get(url: string, options?: APIRequestContextOptions): Promise<APIResponse>;
  post(url: string, options?: APIRequestContextOptions): Promise<APIResponse>;
  put(url: string, options?: APIRequestContextOptions): Promise<APIResponse>;
  delete(url: string, options?: APIRequestContextOptions): Promise<APIResponse>;
}

interface Route {
  fulfill(response: RouteResponse): Promise<void>;
  abort(errorCode?: string): Promise<void>;
  continue(overrides?: RouteContinueOptions): Promise<void>;
}

Network & API Testing

Testing Framework

Comprehensive test framework with fixtures for browser automation, parallel execution, and extensive assertion library.

const test: TestType<PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
const expect: Expect<{}>;

interface PlaywrightTestArgs {  
  page: Page;
  context: BrowserContext;
}

interface PlaywrightWorkerArgs {
  browser: Browser;
  browserName: string;
  playwright: typeof import('playwright-core');
}

function defineConfig(config: PlaywrightTestConfig): PlaywrightTestConfig;

Testing Framework

Mobile & Device Testing

Mobile browser emulation, device-specific testing, and Android automation for comprehensive cross-platform testing.

const devices: Devices;
const _android: Android;

interface Devices {
  [key: string]: DeviceDescriptor;
}

interface DeviceDescriptor {
  userAgent: string;
  viewport: ViewportSize;
  deviceScaleFactor: number;  
  isMobile: boolean;
  hasTouch: boolean;
}

interface Android {
  devices(): Promise<AndroidDevice[]>;
  connect(wsEndpoint: string): Promise<AndroidDevice>;
}

Mobile & Device Testing

Visual Testing & Debugging

Screenshot comparison, video recording, tracing, and debugging tools for test development and maintenance.

interface Page {
  screenshot(options?: PageScreenshotOptions): Promise<Buffer>;
}

interface Tracing {
  start(options?: TracingStartOptions): Promise<void>;
  stop(options?: TracingStopOptions): Promise<void>;
}

interface Video {
  path(): Promise<string>;  
  delete(): Promise<void>;
}

Visual Testing & Debugging

Types

Core Configuration Types

interface LaunchOptions {
  headless?: boolean;
  executablePath?: string;
  args?: string[];
  ignoreDefaultArgs?: boolean | string[];
  proxy?: ProxySettings;
  downloadsPath?: string;
  chromiumSandbox?: boolean;
}

interface BrowserContextOptions {
  viewport?: ViewportSize | null;
  userAgent?: string;
  locale?: string;
  timezoneId?: string;
  geolocation?: Geolocation;
  permissions?: string[];
  httpCredentials?: HTTPCredentials;
  offline?: boolean;
  ignoreHTTPSErrors?: boolean;
}

interface ViewportSize {
  width: number;
  height: number;
}

interface Geolocation {
  latitude: number;
  longitude: number;
  accuracy?: number;
}

interface HTTPCredentials {
  username: string;
  password: string;
}

Install with Tessl CLI

npx tessl i tessl/npm-playwright
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/playwright@1.55.x
Publish Source
CLI
Badge
tessl/npm-playwright badge