Playwright Test と Reporter API
この付録では、Playwright Test Runner の設定、Fixture、Reporter などの API を一覧表示します。
Test 関数
| メソッド | 説明 |
test(name, fn) | テストを定義する |
test.describe(name, fn) | テストグループを定義する |
test.describe.serial(name, fn) | シリアルテストグループ |
test.describe.parallel(name, fn) | 並列テストグループ |
test.describe.configure(options) | グループの動作を設定する(mode、retries) |
test.skip(name?, fn?) | テストをスキップする |
test.fail(name?, fn?) | 期待失敗としてマークする |
test.fixme(name?, fn?) | 修正待ちとしてマークする |
test.slow(name?, fn?) | スローテストとしてマークする(タイムアウト×3) |
test.only(name, fn) | このテストのみ実行する |
test.beforeEach(fn) | 各テストの前に実行 |
test.afterEach(fn) | 各テストの後に実行 |
test.beforeAll(fn) | すべてのテストの前に一度実行 |
test.afterAll(fn) | すべてのテストの後に一度実行 |
test.extend(fixtures) | カスタム Fixture を作成する |
test.use(options) | 現在のスコープの設定を上書きする |
test.setTimeout(ms) | 現在のテストのタイムアウトを設定する |
test.step(name, fn) | テストステップを定義する(レポートで表示可能) |
test.info() | TestInfo オブジェクトを取得する |
TestConfig 設定インターフェース
| フィールド | 型 | 説明 |
testDir | string | テストディレクトリ |
fullyParallel | boolean | 完全並列 |
workers | number | Worker 数 |
retries | number | 再試行回数 |
timeout | number | テスト全体のタイムアウト |
reporter | string | array | レポーター |
forbidOnly | boolean | 禁止only |
testMatch | string | RegExp | テストマッチパターン |
testIgnore | string | RegExp | 無視パターン |
projects | Project[] | プロジェクトリスト |
webServer | object | Web サーバー設定 |
globalSetup | string | グローバル Setup スクリプトのパス |
globalTeardown | string | グローバル Teardown スクリプトのパス |
use | object | 共有設定 |
expect | object | アサーション設定 |
TestInfo インターフェース
| フィールド/メソッド | 説明 |
testInfo.title | テスト名 |
testInfo.file | テストファイルのパス |
testInfo.line | テストの行番号 |
testInfo.column | テストの列番号 |
testInfo.expectedStatus | 期待ステータス:'passed' | 'failed' | 'skipped' |
testInfo.timeout | 現在のテストのタイムアウト |
testInfo.annotations | 注釈リスト |
testInfo.attachments | 添付ファイルリスト |
testInfo.project.name | 現在のプロジェクト名 |
testInfo.retry | 現在の再試行回数 |
testInfo.parallelIndex | 並列インデックス |
testInfo.skip(reason?) | テストをスキップ(動的) |
testInfo.fail(reason?) | 失敗としてマーク(動的) |
testInfo.attach(name, options?) | レポートにファイルを添付する |
Fixtures インターフェース
| Fixture | 型 | 説明 |
page | Page | ブラウザタブ |
context | BrowserContext | ブラウザコンテキスト |
browser | Browser | ブラウザインスタンス |
browserName | string | ブラウザ名 |
request | APIRequestContext | HTTP リクエストクライアント |
WorkerInfo インターフェース
| フィールド | 説明 |
workerInfo.project.name | プロジェクト名 |
workerInfo.parallelIndex | Worker 並列インデックス |
workerInfo.config | FullConfig オブジェクト |
Reporter インターフェース
| メソッド | 説明 |
reporter.onBegin(config, suite) | テスト開始 |
reporter.onTestBegin(test) | 単一のテスト開始 |
reporter.onTestEnd(test, result) | 単一のテスト終了 |
reporter.onStepBegin(test, result, step) | ステップ開始 |
reporter.onStepEnd(test, result, step) | ステップ終了 |
reporter.onEnd(result) | テスト終了 |
reporter.onExit() | プロセス終了 |
reporter.printsToStdio() | 標準出力に出力するかどうか |
Suite クラス
| フィールド | 説明 |
suite.title | Suite 名 |
suite.suites | 子 Suite リスト |
suite.tests | テストリスト |
suite.location | Suite の位置 |
TestCase クラス
| フィールド | 説明 |
test.title | テスト名 |
test.location | テストの位置 |
test.expectedStatus | 期待ステータス |
test.annotations | 注釈リスト |
test.parent | 所属 Suite |
test.id() | テスト ID |
TestResult クラス
| フィールド | 説明 |
result.status | ステータス:'passed' | 'failed' | 'skipped' | 'interrupted' |
result.duration | 実行時間(ミリ秒) |
result.error | エラー情報(TestError) |
result.attachments | 添付ファイルリスト |
result.stdout | 標準出力 |
result.stderr | 標準エラー |
Electron API
| メソッド | 説明 |
electron.launch(options?) | Electron アプリを起動する |
ElectronApplication クラス
| メソッド | 説明 |
electronApp.firstWindow() | 最初のウィンドウを取得する |
electronApp.windows() | すべてのウィンドウを取得する |
electronApp.close() | アプリを閉じる |
Android API
| メソッド/クラス | 説明 |
android.devices() | 接続されているデバイスリストを取得する |
AndroidDevice | Android デバイスオブジェクト |
AndroidWebView | WebView オブジェクト |
その他の拡張