公式ドキュメントは以下になります。
事前準備
DebianやUbuntuの場合、事前に以下を実行して必要なライブラリをインストールしておきます。
sudo apt-get install libnss3\
libnspr4\
libatk1.0-0\
libatk-bridge2.0-0\
libcups2\
libxkbcommon0\
libatspi2.0-0\
libxdamage1\
libgbm1\
libpango-1.0-0\
libcairo2\
libasound2
インストール
npm init playwright@latest
実行すると、いくつか質問があるので答えていきます。基本的には y を選択します。
$ npm init playwright@latest Need to install the following packages: create-playwright@1.17.134 Ok to proceed? (y) y
以下のようになります。
> npx
> create-playwright
Getting started with writing end-to-end tests with Playwright:
Initializing project in '.'
✔ Do you want to use TypeScript or JavaScript? · TypeScript
✔ Where to put your end-to-end tests? · tests
✔ Add a GitHub Actions workflow? (y/N) · false
✔ Install Playwright browsers (can be done manually via 'npx playwright install')? (Y/n) · true
✔ Install Playwright operating system dependencies (requires sudo / root - can be done manually via 'sudo npx playwright install-deps')? (y/N) · false
Initializing NPM project (npm init -y)…
....
Inside that directory, you can run several commands:
npx playwright test
Runs the end-to-end tests.
npx playwright test --ui
Starts the interactive UI mode.
npx playwright test --project=chromium
Runs the tests only on Desktop Chrome.
npx playwright test example
Runs the tests in a specific file.
npx playwright test --debug
Runs the tests in debug mode.
npx playwright codegen
Auto generate tests with Codegen.
We suggest that you begin by typing:
npx playwright test
And check out the following files:
- ./tests/example.spec.ts - Example end-to-end test
- ./tests-examples/demo-todo-app.spec.ts - Demo Todo App end-to-end tests
- ./playwright.config.ts - Playwright Test configuration
Visit https://playwright.dev/docs/intro for more information. ✨
Happy hacking!
成功したら、以下でサンプルテストを実行してます。
npx playwright test
npx playwright test Running 6 tests using 6 workers 6 passed (6.0s) To open last HTML report run: npx playwright show-report