Skip to content

Playwright Spickzettel

Browser-Automatisierungs- und Testing-Framework von Microsoft.

01

Erste Schritte

Einfacher Test

Playwright-Tests nutzen Fixtures wie { page }.

playwright
import { test, expect } from "@playwright/test";

test("home", async ({ page }) => {
  await page.goto("/");
  await expect(page).toHaveTitle("Welcome");
});

Interaktionen

Übliche Interaktionsmethoden.

playwright
await page.fill("input", "hello");
await page.click("button");
await page.waitForSelector(".result");

Locators

Locator-API für robuste Elementauswahl.

playwright
const button = page.getByRole("button", { name: "Submit" });
await button.click();

const item = page.getByText("Hello");
await expect(item).toBeVisible();
02

Features

Multi-Browser

Browserübergreifendes Testing ab Werk.

playwright
test.describe.configure({ mode: "serial" });
test("works in all", async ({ page, browserName }) => {
  // runs in chromium, firefox, webkit
});

Screenshot

Visuelles Regression-Testing.

playwright
await page.screenshot({ path: "screenshot.png" });
await expect(page).toHaveScreenshot();

Was this helpful?