Playwrightによる最新のE2Eテスト
Spectronの後継にあたる最新のPlaywrightを使ってElectronアプリをエンドツーエンドでテストし、実際のウィンドウを自動操作してUIの動作を検証します。
「Playwrightによる最新のE2Eテスト」はCoddyKit上の無料Electron Desktop App Developmentレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはElectron Desktop App Development学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Electron Desktop App Developmentコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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/testLaunching 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.
よくある質問
「Playwrightによる最新のE2Eテスト」レッスンは無料ですか?
はい。「Playwrightによる最新のE2Eテスト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Electron Desktop App Developmentコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Electron Desktop App Developmentコースには全4レッスンが含まれています。
「Playwrightによる最新のE2Eテスト」で何を学びますか?
Spectronの後継にあたる最新のPlaywrightを使ってElectronアプリをエンドツーエンドでテストし、実際のウィンドウを自動操作してUIの動作を検証します。 ブラウザで直接実行するハンズオンコードでElectron Desktop App Developmentを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Electron Desktop App Developmentを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのElectron Desktop App Developmentは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「Playwrightによる最新のE2Eテスト」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このElectron Desktop App Developmentレッスンでコードを書いて実行できますか?
はい。すべてのElectron Desktop App Developmentレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- mainプロセスとrendererプロセスのデバッグ
- Spectronによる単体テスト
- エンドツーエンドテストのワークフロー
- Playwrightによる最新のE2Eテスト