Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
E2Eテストで開発を止めないためのPlaywright高速化
Search
yuzneri
November 08, 2025
370
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
E2Eテストで開発を止めないためのPlaywright高速化
2025/11/08 PHPカンファレンス福岡2025
yuzneri
November 08, 2025
More Decks by yuzneri
See All by yuzneri
昔つくったIoTデバイス
yuzneri
0
31
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
260
色を視る
yuzneri
0
440
ゲームと乱数
yuzneri
0
70
即売会で使える業務用決算端末
yuzneri
0
63
コードの外側に惹かれた
yuzneri
0
62
ぼくの開発環境2026
yuzneri
1
400
2025年アウトプット振り返り
yuzneri
0
50
努力の方向を変えれば結果は変わる(画像削除済)
yuzneri
2
140
Featured
See All Featured
We Are The Robots
honzajavorek
0
250
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
410
WENDY [Excerpt]
tessaabrams
11
38k
Skip the Path - Find Your Career Trail
mkilby
1
150
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Building AI with AI
inesmontani
PRO
1
1.1k
The untapped power of vector embeddings
frankvandijk
2
1.8k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
360
Transcript
撮影OK、𝕏投稿OK ゆずねり@yuzneri E2Eテストで開発を⽌めない ためのPlaywright⾼速化 2025/11/08 PHPカンファレンス福岡2025
ゆずねり@yuzneri •仕事 •バックエンドたまにフロントエン ドエンジニア •趣味 •ドール、ポーカー、謎解き 𝕏:@yuzneri 2025/11/08
⽬次 1. PHPUnitとPlaywrightの違い 2. テスト並列化 3. 認証情報の共有 4. まとめ 2025/11/08
PHPUnit •PHPアプリケーションのテストフレームワーク •PHPで書かれたコードを⾃動テスト •主にユニットテスト、インテグレーションテス トで使う 2025/11/08
Playwright •Webサイトのテストフレームワーク •Webブラウザを⾃動操作してテスト •主にE2Eテストで使う 2025/11/08
Playwrightの特徴 •Chromium、Firefox、WebKitを⾃動操作 •E2Eテストに強い機能が豊富 •様々な環境、⾔語で動く •Windows、MacOS、Linux、Docker •TS/JS、Python、Java、.NET 2025/11/08
テストピラミッド 2025/11/08 E2Eテスト インテグレーション テスト ユニットテスト 速度 速い 遅い コスト
⾼い 低い
E2Eテストは時間がかかる •ユニットテストと同じテストでも、数⼗〜数百 倍時間がかかる •ブラウザの起動 •ページの読み込み •レンダリング 2025/11/08
それぞれの特徴に合わせて使い分ける •ビジネスロジックの 正確性 •エッジケースを網羅 的にテスト •ユーザー体験を検証 •ブラウザ上での JavaScriptを確認 •UIの表⽰や動作を検証 2025/11/08
PHPUnit Playwright
テスト並列実⾏ •テストを複数同時に実⾏する •前提として、テスト間の依存関係がない状態 2025/11/08
テスト並列化の⽅法 1. ワーカー •1台のマシンの中で並列化 2. シャーディング •複数台のマシンで並列化 2025/11/08
ワーカーとシャーディングの違い 2025/11/08 ワーカー シャーディング マシン1 ワーカー1:テスト1,2,3 ワーカー2:テスト4,5,6 ワーカー3:テスト7,8,9 マシン1 シャード1:テスト1,2,3
マシン2 シャード2:テスト4,5,6 マシン3 シャード3:テスト7,8,9
1. ワーカー •1台のマシンの中でテスト並列化 •主にローカル開発で効果的 2025/11/08
設定ファイルのworkersで設定 import { defineConfig } from '@playwright/test'; export default defineConfig({
workers: process.env.CI ? 1 : undefined, }); 2025/11/08
2. シャーディング •複数台のマシンでテスト並列化 •⼤規模なテストやCI環境で効果的 2025/11/08
シャーディングのやり⽅ •testコマンドに引数を付けるだけ •--shard=シャード番号/分割数 npx playwright test --shard=1/3 npx playwright test
--shard=2/3 npx playwright test --shard=3/3 2025/11/08
分割されたレポートの統合 •merge-reportsコマンドで、バラバラになっ たレポートを統合できる npx playwright merge-reports ¥ --reporter html ./all-blob-reports
2025/11/08
GitHub Actionsでシャーディング •matrixを使うとできる •完全な設定例は公式サイトをご覧ください • https://playwright.dev/docs/test-sharding#github- actions-example 2025/11/08
matrix設定例 jobs: playwright-tests: strategy: fail-fast: false matrix: index: [1, 2,
3] # シャード番号 total: [3] # 分割数 steps: ... 2025/11/08
Shardオプション設定例 steps: # チェックアウトやPlaywrightの設定 - run: npx playwright test --shard=${{matrix.index}}/${{matrix.total}}
- uses: actions/upload-artifact@v4 with: name: blob-report-${{ matrix.shardIndex }} path: blob-report 2025/11/08
レポート統合設定例 merge-reports: steps: # チェックアウトやPlaywrightの設定 - uses: actions/download-artifact@v5 with: path:
all-blob-reports pattern: blob-report-* merge-multiple: true - run: npx playwright merge-reports --reporter html ./all-blob-reports 2025/11/08
実⾏のようす 2025/11/08
クッキーやlocalStorageの共有 •storageStateを使うと、クッキーや localStorageをテスト間で共有できる •テストごとにログインしているような場合、1 回にすることができる 2025/11/08
セッションを保存する test('authenticate', async ({ page }) => { await page.fill('#user',
'user'); await page.fill('#pass', 'pass'); await page.click('#login'); await page.context().storageState({ path: 'auth.json' }); }); 2025/11/08
テスト時にセッションをロードする export default defineConfig({ projects: [ {name: 'setup', testMatch: /.*¥.setup¥.ts/},
{ name: 'chromium', use: { ...devices['Desktop Chrome'], storageState: 'auth.json', }, dependencies: ['setup'], }, 2025/11/08 ① setup プ ロ ジ ェ ク ト が 最 初 に 実 ⾏ さ れ る ↑②auth.jsonが保存される ←③テスト時にauth.jsonが ロードされる
その他の⾼速化⽅法 1. ネットワークの最適化 2. アニメーションの無効化 3. セレクター選択の効率化 4. waitForTimeoutの排除 5.
スモークテスト戦略 2025/11/08
まとめ •Playwrightの役割を理解 •Playwrightの便利な仕組みを使う •ワーカーやシャーディングを使って並列化 •認証を使い回す •その他いろいろ 2025/11/08