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 (オプション)-
添付ファイルの本文。path と同時に指定することはできません。
-
レポートで適切に表示するための、この添付ファイルのコンテンツタイプ。例:
'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
// ...
});
});
引数