0Pricing
Electron Desktop App Development · Lezione

Test E2E moderni con Playwright

Testate la vostra app Electron end-to-end usando Playwright, il moderno successore di Spectron, automatizzando finestre reali e verificando il comportamento della UI.

Test E2E moderni con Playwright è una lezione Electron Desktop App Development gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Electron Desktop App Development, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Electron Desktop App Development include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Why Playwright for Electron

Spectron is deprecated. Playwright has first-class Electron support and drives your real app like a user would.

Installing Playwright

Add Playwright as a dev dependency. Its test runner and Electron launcher come bundled.

npm install --save-dev @playwright/test

Launching the App

Use _electron.launch to start your packaged or source app under test control.

const { _electron: electron } = require('playwright');
const app = await electron.launch({ args: ['.'] });

Getting the First Window

firstWindow() returns the renderer page so you can interact with the DOM.

const window = await app.firstWindow();
await window.waitForLoadState('domcontentloaded');

Locating Elements

Use resilient locators based on roles and labels rather than brittle CSS selectors.

function selectorFor(role, name) {
  return 'role=' + role + '[name="' + name + '"]';
}
console.log(selectorFor('button', 'Save'));

Interacting With the UI

Click, type, and assert just like a user.

await window.fill('#title', 'My Note');
await window.click('text=Save');

Assertions

Use expect with auto-waiting matchers so flaky timing issues disappear.

await expect(window.locator('.toast')).toHaveText('Saved');

Evaluating in the Main Process

Playwright can run code in the main process via app.evaluate, letting you assert on app state.

const isPackaged = await app.evaluate(({ app }) => app.isPackaged);

Taking Screenshots

Capture screenshots on failure to debug visually. Playwright does this automatically when configured.

await window.screenshot({ path: 'failure.png' });

Closing Cleanly

Always close the app after each test to avoid leaked processes.

await app.close();

Running in CI

Run E2E tests headlessly in CI on every push. Use a virtual display on Linux runners when needed.

Quick Check

Test your Playwright knowledge.

Recap

You learned modern E2E testing with Playwright: launching the app, grabbing windows, using resilient locators, asserting with auto-waiting matchers, evaluating main-process state, and running in CI.

Domande Frequenti

La lezione «Test E2E moderni con Playwright» è gratuita?

Sì — il testo completo di «Test E2E moderni con Playwright» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Electron Desktop App Development, passa a CoddyKit PRO. Il corso Electron Desktop App Development include 4 lezioni in totale.

Cosa imparerò in «Test E2E moderni con Playwright»?

Testate la vostra app Electron end-to-end usando Playwright, il moderno successore di Spectron, automatizzando finestre reali e verificando il comportamento della UI. Eserciti Electron Desktop App Development con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Electron Desktop App Development?

Non è richiesta alcuna esperienza precedente. Electron Desktop App Development su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.

Quanto tempo richiede la lezione «Test E2E moderni con Playwright»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Electron Desktop App Development?

Sì. Ogni lezione Electron Desktop App Development include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Debug dei processi main e renderer
  2. Test unitari con Spectron
  3. Flussi di test end-to-end
  4. Test E2E moderni con Playwright
← Torna a Electron Desktop App Development