Playwright BDD 導入検証用 (introduction)
PlaywrightとBDDの動作確認のためのサンプル
推奨 (recommendation) node version -> newer LTS (Node Releases)
Important
task (go-task) のインストールが必要
ない場合は taskfile.yml に定義されているコマンドを直接実行できます
例: 「task bdd-test」 npx bddgen && npx playwright test
clone files
git clone https://github.com/o-kazuhide-takahashi/sample-playwright-bdd.git
npm install
cd sample-playwright-bdd
npm i
install browser (chrome)
npx playwright install
execute test
サンプルテスト(feature)はgoogleとyahooを表示するシナリオ
task bdd
or
npx bddgen && npx playwright test
テストで複数のブラウザでテスト可能
例: chrome and msedge and firefox and safari(webkit)
Tip
各ブラウザについて 参考 (reference browsers)
https://playwright.dev/docs/browsers
chromium, chrome, msedge, firefox, webkit (others...)
npx playwright install chrome
npx playwright install msedge
npx playwright install webkit
before (not activated)
// {
// name: 'Google Chrome',
// use: {
// ...devices['Desktop Chrome'], channel: 'chrome',
// // storageState: process.env.BDD_PL_STORAGE_STATE_FILEPATH ?? 'tests/state.json',
// colorScheme: "dark",
// timezoneId: "Asia/Tokyo",
// //geolocation: {latitude: longitude: accuracy: },
// //permissions: ['geolocation'], // ジオロケーション(GPS)の権限を許可
// },
// },
after (activated)
{
name: 'Google Chrome',
use: {
...devices['Desktop Chrome'], channel: 'chrome',
// storageState: process.env.BDD_PL_STORAGE_STATE_FILEPATH ?? 'tests/state.json',
colorScheme: "dark",
timezoneId: "Asia/Tokyo",
//geolocation: {latitude: longitude: accuracy: },
//permissions: ['geolocation'], // ジオロケーション(GPS)の権限を許可
},
},
ファイルは tests/bdd/sample/pl_codegen/$(date '+%Y%m%d%H%M%S').ts
に保存
task pl-code
or
npx playwright codegen https://www.yahoo.co.jp/ -o tests/bdd/sample/pl_codegen/$(date '+%Y%m%d%H%M%S').ts --lang ja_JP
表示されたブラウザで、適当なニューストピックをクリック
(choice random news link in displayed yahoo japan top page)
finename: 20241026142944.ts
import { test, expect } from '@playwright/test';
test.use({
locale: 'ja_JP'
});
test('test', async ({ page }) => {
await page.goto('https://www.yahoo.co.jp/');
await page.getByRole('link', { name: '衆院選 旧統一の「電話かけ」一変 NEW' }).click();
});