Skip to content

Playwright Aide-mémoire

Framework d'automatisation et de test de navigateurs développé par Microsoft.

01

Premiers pas

Test de base

Les tests Playwright utilisent des fixtures comme { page }.

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

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

Interactions

Méthodes d'interaction courantes.

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

Locators

API Locator pour une sélection résiliente des éléments.

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

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

Fonctionnalités

Multi-navigateurs

Tests multi-navigateurs intégrés dès l'installation.

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

Capture d'écran

Tests de régression visuelle.

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

Was this helpful?