メインコンテンツにスキップ

saveScreenshot

現在のブラウジングコンテキストのスクリーンショットをOS上のPNGファイルに保存します。一部のブラウザドライバは ドキュメント全体のスクリーンショットを撮影する(例:FirefoxのGeckodriver)場合があり、 他のドライバは現在のビューポートのみを撮影する(例:ChromeのChromedriver)場合があることに注意してください。

Usage
browser.saveScreenshot(filepath, { fullPage, format, quality, clip })
Parameters
NameTypeDetails
filepathString実行ディレクトリからの相対パスで指定した生成される画像のパス(.png拡張子が必要)
optionsObjectスクリーンショットのオプション
options.fullPage=false
optional
Booleanページ全体のスクリーンショットを撮るか、現在のビューポートのみのスクリーンショットを撮るか
options.format='png'
optional
Stringスクリーンショットの形式(pngまたはjpeg
options.quality=100
optional
NumberJPEG形式の場合のスクリーンショットの品質(0-100パーセントの範囲)
options.clip
optional
Objectスクリーンショットの特定の領域を切り取る
Examples
saveScreenshot.js
it('should save a screenshot of the browser viewport', async () => {
await browser.saveScreenshot('./some/path/screenshot.png');
});

it('should save a screenshot of the full page', async () => {
await browser.saveScreenshot('./some/path/screenshot.png', { fullPage: true });
});

it('should save a screenshot of a specific rectangle', async () => {
await browser.saveScreenshot('./some/path/screenshot.png', { clip: { x: 0, y: 0, width: 100, height: 100 } });
});

it('should save a screenshot of the full page in JPEG format', async () => {
await browser.saveScreenshot('./some/path/screenshot.jpeg', { fullPage: true, format: 'jpeg' });
});

it('should save a screenshot of the full page in JPEG format with quality 50', async () => {
await browser.saveScreenshot('./some/path/screenshot.jpeg', { fullPage: true, format: 'jpeg', quality: 50 });
});

running from a hook, make sure to explicitly define the hook as async:

wdio.conf.js
afterTest: async function(test) {
await browser.saveScreenshot('./some/path/screenshot.png');
}
Returns
  • <Buffer> return: スクリーンショットバッファ

Welcome! How can I help?

WebdriverIO AI Copilot