0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Playwright の HTML レポートを固定 URL で共有するシェルスクリプト

0
Posted at

Playwright の HTML レポートは playwright-report/index.html に出力されます。スクリーンショット・動画・トレースが無い実行であれば、このファイルは単体で完結しています(3 テストのサンプルで約 510 KB)。困るのはチームメイトへの渡し方で、チャットに zip を貼ったり、CI のアーティファクトを落として npx playwright show-report を実行してもらったりと、地味に手間がかかります。

この記事では、その 1 ファイルを deed.page に PUT して、固定の HTTPS URL で共有する小さなシェルスクリプトを紹介します。deed.page はアカウント不要で 1 回の PUT で公開できる静的ホスティングです。リンクを知っていれば誰でも開けるので、スクリプトは公開前に必ず確認を求めます。

開示: この記事は deed.page チームが書いています。

1. レポートを作る

npx playwright test --reporter=html
ls playwright-report/   # index.html(添付があるときだけ data/ も)

2. 公開スクリプト

publish-playwright-report.sh として保存し、chmod +x します。ポイントは 3 つです。

  • data/ フォルダ(スクショやトレース)があるレポートは、添付が壊れた状態で公開しないよう途中で止めます。
  • y と答えない限り何もアップロードしません。
  • 初回公開時に返ってくるオーナートークンは ~/.config/deed-page/token(パーミッション 600)に保存し、出力ではマスクします。ターミナルのログや CI の出力にトークンが残りません。
#!/bin/sh
# Playwright の HTML レポート(単一の index.html)を deed.page の固定 URL に公開する
# 使い方: ./publish-playwright-report.sh playwright-report/index.html my-app-e2e-7k2p
set -eu
FILE=${1:?path to playwright-report/index.html}; SLUG=${2:?slug, e.g. my-app-e2e-7k2p}
DIR=$(dirname "$FILE")
if [ -d "$DIR/data" ] && [ -n "$(ls -A "$DIR/data" 2>/dev/null)" ]; then
  echo "This report has attachments in $DIR/data (screenshots, traces). Upload the whole folder with the manifest flow in https://deed.page/docs instead."; exit 1
fi
printf 'Publish %s to https://%s.deed.page/ ? Anyone with the link can open it. [y/N] ' "$FILE" "$SLUG"
read -r ans; [ "$ans" = "y" ] || { echo "Not published."; exit 0; }
DEEDPAGE_TOKEN=${DEEDPAGE_TOKEN:-$(cat ~/.config/deed-page/token 2>/dev/null || true)}
set --; if [ -n "$DEEDPAGE_TOKEN" ]; then set -- -H "Authorization: Bearer $DEEDPAGE_TOKEN"; fi
RESP=$(curl -sS -T "$FILE" -H "Content-Type: text/html" "https://deed.page/v1/sites?slug=$SLUG" -H "X-Client: playwright-report-script" "$@")
TOKEN=$(printf '%s' "$RESP" | sed -n 's/.*"token": *"\(deed_tok_[^"]*\)".*/\1/p')
if [ -n "$TOKEN" ]; then (umask 077 && mkdir -p ~/.config/deed-page && chmod 700 ~/.config/deed-page && printf '%s' "$TOKEN" > ~/.config/deed-page/token && chmod 600 ~/.config/deed-page/token); fi
printf '%s\n' "$RESP" | sed 's/"token": *"[^"]*"/"token":"<saved>"/'

3. 実行する

./publish-playwright-report.sh playwright-report/index.html checkout-e2e-7k2p
# Publish playwright-report/index.html to https://checkout-e2e-7k2p.deed.page/ ? ... [y/N] y
# {"ok":true,"url":"https://checkout-e2e-7k2p.deed.page/", ... "token":"<saved>"}

2 回目以降は保存済みのトークンを送るので、同じスラッグのレポートがその場で置き換わります。PR の説明に貼ったリンクが常に最新の実行結果を指すわけです。中身が同じファイルを再公開すると "unchanged":true が返ります。

4. 片付け

curl -X DELETE -H "Authorization: Bearer $(cat ~/.config/deed-page/token)" \
  https://deed.page/v1/sites/checkout-e2e-7k2p

削除後、URL は 404 を返します。

注意点

  • スラッグにはランダムな接尾辞を付けてください。my-site のような短い名前は予約されています。
  • スクショやトレース付きのレポートは data/ を含むので、フォルダごとアップロードするマニフェスト方式を使います。手順は deed.page のドキュメント にあります。
  • 無料サイトは公開扱いで、小さな「Published with deed.page」バッジが付きます。シークレット、顧客データ、社内 URL を含むレポートは公開しないでください。
  • CI の無人ジョブに確認プロンプトを入れないでください。人が実行するステップにするか、明示的な承認入力を必須にしてください。

2026-11-03 に @playwright/test で、拒否・公開・再公開(unchanged)・削除(削除後 404)の流れをエンドツーエンドで確認しました。スクリプトの元リポジトリは f-o-x11/playwright-report-link、エージェント向けのスキルは deed-page-skill です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?