TestStepInfo
TestStepInfoには、現在実行中のテストステップに関する情報が含まれています。これはステップ関数への引数として渡されます。TestStepInfoはテストステップの実行を制御するユーティリティを提供します。
import { test, expect } from '@playwright/test';
test('basic test', async ({ page, browserName }) => {
await test.step('check some behavior', async step => {
step.skip(browserName === 'webkit', 'The feature is not available in WebKit');
// ... rest of the step code
});
});
メソッド
attach
追加バージョン: v1.51現在のテストステップに値またはディスク上のファイルを添付します。一部のレポーターはテストステップの添付ファイルを表示します。pathまたはbodyのいずれかを指定する必要がありますが、両方を指定することはできません。このメソッドを呼び出すと、添付ファイルがステップに帰属します。これに対し、すべての添付ファイルをテストレベルで保存するtestInfo.attach()とは異なります。
例えば、スクリーンショットをテストステップに添付できます。
import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
await page.goto('https://playwright.dokyumento.jp');
await test.step('check page rendering', async step => {
const screenshot = await page.screenshot();
await step.attach('screenshot', { body: screenshot, contentType: 'image/png' });
});
});
または、APIが返すファイルを添付することもできます。
import { test, expect } from '@playwright/test';
import { download } from './my-custom-helpers';
test('basic test', async ({}) => {
await test.step('check download behavior', async step => {
const tmpPath = await download('a');
await step.attach('downloaded', { path: tmpPath });
});
});
testStepInfo.attach()は、添付ファイルをレポーターがアクセスできる場所にコピーする処理を自動的に行います。attach呼び出しを待機した後、添付ファイルを安全に削除できます。
使用法
await testStepInfo.attach(name);
await testStepInfo.attach(name, options);
引数
-
添付ファイル名。名前はサニタイズされ、ディスクに保存する際のファイル名のプレフィックスとしても使用されます。
-
optionsObject (optional)-
bodystring | Buffer (optional)#添付ファイルの本文。pathとは相互排他的です。
-
contentTypestring (optional)#レポートで適切に表示するためのこの添付ファイルのコンテンツタイプ。例えば、
'application/json'または'image/png'です。省略された場合、コンテンツタイプはpathに基づいて推測されるか、string添付ファイルの場合はtext/plain、Buffer添付ファイルの場合はapplication/octet-streamがデフォルトとなります。 -
添付ファイルへのファイルシステム上のパス。bodyとは相互排他的です。
-
戻り値
skip()
追加バージョン: v1.51現在実行中のステップを中止し、スキップ済みとしてマークします。現在失敗しており、近い将来修正が予定されているステップに役立ちます。
使用法
import { test, expect } from '@playwright/test';
test('my test', async ({ page }) => {
await test.step('check expectations', async step => {
step.skip();
// step body below will not run
// ...
});
});
skip(condition)
追加バージョン: v1.51現在実行中のステップを条件付きで中止し、オプションの説明を付けてスキップ済みとしてマークします。特定のケースで実行すべきでないステップに役立ちます。
使用法
import { test, expect } from '@playwright/test';
test('my test', async ({ page, isMobile }) => {
await test.step('check desktop expectations', async step => {
step.skip(isMobile, 'not present in the mobile layout');
// step body below will not run
// ...
});
});
引数
プロパティ
titlePath
追加されたバージョン: v1.55テストファイル名から始まる、ステップタイトルを含む完全なタイトルパスです。testInfo.titlePathも参照してください。
使用法
testStepInfo.titlePath
タイプ