📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 7

Retour
Playwright - Générer du code (Codegen)
Facile
npx playwright codegen wikipedia.org
Playwright - Hook 'beforeEach'
Facile
test.beforeEach(async ({ page }) => {
  await page.goto('http://localhost:3000');
});
Playwright - Lancer les tests en mode 'headed'
Facile
npx playwright test --headed
Playwright - Lancer un navigateur et visiter une page
Facile
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto('http://example.com');
  await browser.close();
})();
Playwright - Prendre une capture d'écran
Facile
await page.screenshot({ path: 'screenshot.png' });
Playwright - Sélectionner un élément (locator)
Facile
await page.locator('.ma-classe').click();
Playwright - Structure d'un test
Facile
const { test, expect } = require('@playwright/test');

test('ma page de titre', async ({ page }) => {
  await page.goto('https://playwright.dev/');
  await expect(page).toHaveTitle(/Playwright/);
});