playwright-ci-caching
CI/CD環境(GitHub ActionsやAzure DevOpsなど)でPlaywrightのブラウザバイナリをキャッシュし、毎回発生するダウンロード時間を短縮して、ビルドを効率化するSkill。
📜 元の英語説明(参考)
Cache Playwright browser binaries in CI/CD pipelines (GitHub Actions, Azure DevOps) to avoid 1-2 minute download overhead on every build.
🇯🇵 日本人クリエイター向け解説
CI/CD環境(GitHub ActionsやAzure DevOpsなど)でPlaywrightのブラウザバイナリをキャッシュし、毎回発生するダウンロード時間を短縮して、ビルドを効率化するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o playwright-ci-caching.zip https://jpskill.com/download/8720.zip && unzip -o playwright-ci-caching.zip && rm playwright-ci-caching.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/8720.zip -OutFile "$d\playwright-ci-caching.zip"; Expand-Archive "$d\playwright-ci-caching.zip" -DestinationPath $d -Force; ri "$d\playwright-ci-caching.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
playwright-ci-caching.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
playwright-ci-cachingフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
CI/CD で Playwright ブラウザをキャッシュする
この Skill を使用するタイミング
この Skill は、以下の場合に使用します。
- Playwright E2E テストを使用するプロジェクトに CI/CD を設定する場合
- ブラウザのダウンロード(~400MB、1〜2分)によりビルド時間が遅い場合
- Playwright のバージョンが変更されたときに、自動的にキャッシュを無効化したい場合
- GitHub Actions または Azure DevOps パイプラインを使用している場合
問題点
Playwright ブラウザ(~400MB)は、デフォルトでは CI の実行ごとにダウンロードする必要があります。これにより、以下の問題が発生します。
- すべてのビルドに 1〜2 分追加される
- 帯域幅を浪費する
- 一時的なネットワークの問題で失敗する可能性がある
- PR のフィードバックループが遅くなる
コアパターン
- キャッシュキーとして使用するために、
Directory.Packages.props(CPM) から Playwright のバージョンを抽出します。 - プラットフォームに適したパスを使用して、ブラウザのバイナリをキャッシュします。
- 条件付きインストール - キャッシュミスの場合のみダウンロードします。
- 自動キャッシュ破棄 - キーにはバージョンが含まれているため、パッケージのアップグレードによりキャッシュが無効になります。
OS ごとのキャッシュパス
| OS | パス |
|---|---|
| Linux | ~/.cache/ms-playwright |
| macOS | ~/Library/Caches/ms-playwright |
| Windows | %USERPROFILE%\AppData\Local\ms-playwright |
GitHub Actions
- name: Get Playwright Version
shell: pwsh
run: |
$propsPath = "Directory.Packages.props"
[xml]$props = Get-Content $propsPath
$version = $props.Project.ItemGroup.PackageVersion |
Where-Object { $_.Include -eq "Microsoft.Playwright" } |
Select-Object -ExpandProperty Version
echo "PlaywrightVersion=$version" >> $env:GITHUB_ENV
- name: Cache Playwright Browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PlaywrightVersion }}
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: pwsh
run: ./build/playwright.ps1 install --with-deps
Multi-OS GitHub Actions
複数のオペレーティングシステムで実行されるワークフローの場合:
- name: Cache Playwright Browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
~/Library/Caches/ms-playwright
~/AppData/Local/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PlaywrightVersion }}
Azure DevOps
- task: PowerShell@2
displayName: 'Get Playwright Version'
inputs:
targetType: 'inline'
script: |
[xml]$props = Get-Content "Directory.Packages.props"
$version = $props.Project.ItemGroup.PackageVersion |
Where-Object { $_.Include -eq "Microsoft.Playwright" } |
Select-Object -ExpandProperty Version
Write-Host "##vso[task.setvariable variable=PlaywrightVersion]$version"
- task: Cache@2
displayName: 'Cache Playwright Browsers'
inputs:
key: 'playwright | "$(Agent.OS)" | $(PlaywrightVersion)'
path: '$(HOME)/.cache/ms-playwright'
cacheHitVar: 'PlaywrightCacheHit'
- task: PowerShell@2
displayName: 'Install Playwright Browsers'
condition: ne(variables['PlaywrightCacheHit'], 'true')
inputs:
filePath: 'build/playwright.ps1'
arguments: 'install --with-deps'
ヘルパースクリプト: playwright.ps1
Playwright CLI を検出して実行する build/playwright.ps1 スクリプトを作成します。これにより、プロジェクト構造によって異なる Playwright CLI の場所が抽象化されます。
# build/playwright.ps1
# Microsoft.Playwright.dll を検出し、バンドルされた Playwright CLI を実行します
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Arguments
)
# Playwright DLL を検索します (dotnet build/restore 後)
$playwrightDll = Get-ChildItem -Path . -Recurse -Filter "Microsoft.Playwright.dll" -ErrorAction SilentlyContinue |
Select-Object -First 1
if (-not $playwrightDll) {
Write-Error "Microsoft.Playwright.dll not found. Run 'dotnet build' first."
exit 1
}
$playwrightDir = $playwrightDll.DirectoryName
# playwright CLI を検索します (パスは OS と node のバージョンによって異なります)
$playwrightCmd = Get-ChildItem -Path "$playwrightDir/.playwright/node" -Recurse -Filter "playwright.cmd" -ErrorAction SilentlyContinue |
Select-Object -First 1
if (-not $playwrightCmd) {
# Unix 実行可能ファイルを試す
$playwrightCmd = Get-ChildItem -Path "$playwrightDir/.playwright/node" -Recurse -Filter "playwright" -ErrorAction SilentlyContinue |
Where-Object { $_.Name -eq "playwright" } |
Select-Object -First 1
}
if (-not $playwrightCmd) {
Write-Error "Playwright CLI not found in $playwrightDir/.playwright/node"
exit 1
}
Write-Host "Using Playwright CLI: $($playwrightCmd.FullName)"
& $playwrightCmd.FullName @Arguments
使用例:
# ブラウザをインストールする
./build/playwright.ps1 install --with-deps
# 特定のブラウザをインストールする
./build/playwright.ps1 install chromium
# インストールされているブラウザを表示する
./build/playwright.ps1 install --dry-run
前提条件
このパターンは以下を前提としています。
-
Directory.Packages.propsを使用した Central Package Management (CPM):<Project> <ItemGroup> <PackageVersion Include="Microsoft.Playwright" Version="1.40.0" /> </ItemGroup> </Project> -
playwright.ps1を実行する前に プロジェクトがビルドされている (DLL が存在するように) -
PowerShell が利用可能 であること (GitHub Actions および Azure DevOps にはプリインストールされています)
バージョンベースのキャッシュキーが重要な理由
キャッシュキーに Playwright のバージョンを使用することで、以下が保証されます。
- Playwright をアップグレードしたときの 自動無効化
- SDK バージョンと一致しない 古いブラウザバイナリがない
- バージョンアップ後に 手動でキャッシュをクリアする必要がない
キャッシュキーをハードコードした場合(例:playwright-browsers-v1)、Playwright をアップグレードするたびに手動でキーを更新する必要があります。そうしないと、不可解なバージョンミスマッチエラーが発生します。
トラブルシューティング
キャッシュが使用されていない
- バージョン抽出ステップが正しいバージョンを出力することを確認します。
- キャッシュパスが OS と一致することを確認します。
Directory.Packages.propsが存在し、Playwright パッケージが含まれていることを確認します。
キャッシュヒット後に「ブラウザが見つかりません」
キャッシュされたブラウザが Playwright SDK のバージョンと一致しません。これは、
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Caching Playwright Browsers in CI/CD
When to Use This Skill
Use this skill when:
- Setting up CI/CD for a project with Playwright E2E tests
- Build times are slow due to browser downloads (~400MB, 1-2 minutes)
- You want automatic cache invalidation when Playwright version changes
- Using GitHub Actions or Azure DevOps pipelines
The Problem
Playwright browsers (~400MB) must be downloaded on every CI run by default. This:
- Adds 1-2 minutes to every build
- Wastes bandwidth
- Can fail on transient network issues
- Slows down PR feedback loops
Core Pattern
- Extract Playwright version from
Directory.Packages.props(CPM) to use as cache key - Cache browser binaries using platform-appropriate paths
- Conditional install - only download on cache miss
- Automatic cache bust - key includes version, so package upgrades invalidate cache
Cache Paths by OS
| OS | Path |
|---|---|
| Linux | ~/.cache/ms-playwright |
| macOS | ~/Library/Caches/ms-playwright |
| Windows | %USERPROFILE%\AppData\Local\ms-playwright |
GitHub Actions
- name: Get Playwright Version
shell: pwsh
run: |
$propsPath = "Directory.Packages.props"
[xml]$props = Get-Content $propsPath
$version = $props.Project.ItemGroup.PackageVersion |
Where-Object { $_.Include -eq "Microsoft.Playwright" } |
Select-Object -ExpandProperty Version
echo "PlaywrightVersion=$version" >> $env:GITHUB_ENV
- name: Cache Playwright Browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PlaywrightVersion }}
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: pwsh
run: ./build/playwright.ps1 install --with-deps
Multi-OS GitHub Actions
For workflows that run on multiple operating systems:
- name: Cache Playwright Browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: |
~/.cache/ms-playwright
~/Library/Caches/ms-playwright
~/AppData/Local/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PlaywrightVersion }}
Azure DevOps
- task: PowerShell@2
displayName: 'Get Playwright Version'
inputs:
targetType: 'inline'
script: |
[xml]$props = Get-Content "Directory.Packages.props"
$version = $props.Project.ItemGroup.PackageVersion |
Where-Object { $_.Include -eq "Microsoft.Playwright" } |
Select-Object -ExpandProperty Version
Write-Host "##vso[task.setvariable variable=PlaywrightVersion]$version"
- task: Cache@2
displayName: 'Cache Playwright Browsers'
inputs:
key: 'playwright | "$(Agent.OS)" | $(PlaywrightVersion)'
path: '$(HOME)/.cache/ms-playwright'
cacheHitVar: 'PlaywrightCacheHit'
- task: PowerShell@2
displayName: 'Install Playwright Browsers'
condition: ne(variables['PlaywrightCacheHit'], 'true')
inputs:
filePath: 'build/playwright.ps1'
arguments: 'install --with-deps'
Helper Script: playwright.ps1
Create a build/playwright.ps1 script that discovers and runs the Playwright CLI. This abstracts away the Playwright CLI location which varies by project structure.
# build/playwright.ps1
# Discovers Microsoft.Playwright.dll and runs the bundled Playwright CLI
param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$Arguments
)
# Find the Playwright DLL (after dotnet build/restore)
$playwrightDll = Get-ChildItem -Path . -Recurse -Filter "Microsoft.Playwright.dll" -ErrorAction SilentlyContinue |
Select-Object -First 1
if (-not $playwrightDll) {
Write-Error "Microsoft.Playwright.dll not found. Run 'dotnet build' first."
exit 1
}
$playwrightDir = $playwrightDll.DirectoryName
# Find the playwright CLI (path varies by OS and node version)
$playwrightCmd = Get-ChildItem -Path "$playwrightDir/.playwright/node" -Recurse -Filter "playwright.cmd" -ErrorAction SilentlyContinue |
Select-Object -First 1
if (-not $playwrightCmd) {
# Try Unix executable
$playwrightCmd = Get-ChildItem -Path "$playwrightDir/.playwright/node" -Recurse -Filter "playwright" -ErrorAction SilentlyContinue |
Where-Object { $_.Name -eq "playwright" } |
Select-Object -First 1
}
if (-not $playwrightCmd) {
Write-Error "Playwright CLI not found in $playwrightDir/.playwright/node"
exit 1
}
Write-Host "Using Playwright CLI: $($playwrightCmd.FullName)"
& $playwrightCmd.FullName @Arguments
Usage:
# Install browsers
./build/playwright.ps1 install --with-deps
# Install specific browser
./build/playwright.ps1 install chromium
# Show installed browsers
./build/playwright.ps1 install --dry-run
Prerequisites
This pattern assumes:
-
Central Package Management (CPM) with
Directory.Packages.props:<Project> <ItemGroup> <PackageVersion Include="Microsoft.Playwright" Version="1.40.0" /> </ItemGroup> </Project> -
Project has been built before running
playwright.ps1(so DLLs exist) -
PowerShell available on CI agents (pre-installed on GitHub Actions and Azure DevOps)
Why Version-Based Cache Keys Matter
Using the Playwright version in the cache key ensures:
- Automatic invalidation when you upgrade Playwright
- No stale browser binaries that don't match the SDK version
- No manual cache clearing needed after version bumps
If you hardcode the cache key (e.g., playwright-browsers-v1), you'll need to manually bump it every time you upgrade Playwright, or you'll get cryptic version mismatch errors.
Troubleshooting
Cache not being used
- Verify the version extraction step outputs the correct version
- Check that the cache path matches your OS
- Ensure
Directory.Packages.propsexists and has the Playwright package
"Browser not found" after cache hit
The cached browsers don't match the Playwright SDK version. This happens when:
- The cache key doesn't include the version
- The version extraction failed silently
Fix: Ensure the Playwright version is in the cache key.
playwright.ps1 can't find the DLL
Run dotnet build or dotnet restore before running the script. The Playwright DLL only exists after NuGet restore.
References
This pattern is battle-tested in production projects:
Related Skills
dotnet-skills:playwright-blazor- Writing Playwright tests for Blazor applicationsdotnet-skills:project-structure- Central Package Management setup