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?

自動テストをやりたくて、Laravel環境にPlaywrightを入れてみた

Last updated at Posted at 2026-01-04

はじめに

自宅にLaravelのアプリケーションがあり、一旦、運用できる状態になったので、フレームワーク、ライブラリのバージョンアップをしていくうえで、リグレッション観点で自動テストをしたいな。と。

Laravelには「Laravel Dusk」もあるが、個人的に「Playwright」を使ってみたいな。と。

インストール手順

Laravelでtailwindを使っていたので、既にpackage.jsonはある。
なので、npmでplaywrightを追加。

npm init playwright@latest

image.png

フォルダだけ「tests/e2e」にする。
元々Laravelで「tests」フォルダがあるため

image.png

サンプルシナリオを実行してみる

中身を見てみる。

インストール時にパスを「tests/e2e」にしたので以下にある。

tests/e2e/example.spec.ts

見てみると、playwright のサイトをテストする感じになっている。

image.png

動かしてみる

npx playwright test

結果を確認

npx playwright show-report

GitHubActionsの動きも見てみる

インストール時にGitHubActionsへも追加としたので、「playwright.yml」も追加済

.github/workflows/playwright.yml

mainブランチにプッシュしてみる

「playwright.yml」を見ると、main,master ブランチに対して、プッシュ OR プルリクエストの場合にのみ、「test」ジョブが動く感じ

image.png

image.png

image.png

結果の「playwright-report」を見てみる

image.png

をクリックして、「playwright-report.zip」を落としてみる。
中身の「index.html」を表示

image.png

感想

インストールは簡単、サンプル実行も簡単。GitHubActionsのymlも自動生成してくれるので至れり尽くせり。
とはいえ、サンプルは「playwright」のサイトを検証しているので、Laravelのアプリケーションをテストしたい場合は、GitHubActions上で、「Laravelのアプリケーション」を起動も必要と思うので。

次回以降

1.Laravelのアプリケーションのシナリオを作成
2.GitHubActions上で、「Laravelのアプリケーション」を起動

をやってみる。
GitHubActions上でのDBはローカルで動かす際に使っている「sqlite」と 環境別(GitHubActions用)に「seeder」(テストデータ投入)を実行するイメージで良いかな。と妄想しています。

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?