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);
引数
-
添付ファイル名。この名前はサニタイズされ、ディスクに保存する際のファイル名のプレフィックスとしても使用されます。
-
options
Object (任意)
戻り値
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
// ...
});
});
引数