saveScreenshot
現在のブラウジングコンテキストのスクリーンショットをOS上のPNGファイルに保存します。一部のブラウザドライバは ドキュメント全体のスクリーンショットを撮影する(例:FirefoxのGeckodriver)場合があり、 他のドライバは現在のビューポートのみを撮影する(例:ChromeのChromedriver)場合があることに注意してください。
Usage
browser.saveScreenshot(filepath, { fullPage, format, quality, clip })
Parameters
Name | Type | Details |
---|---|---|
filepath | String | 実行ディレクトリからの相対パスで指定した生成される画像のパス(.png 拡張子が必要) |
options | Object | スクリーンショットのオプション |
options.fullPage=false optional | Boolean | ページ全体のスクリーンショットを撮るか、現在のビューポートのみのスクリーンショットを撮るか |
options.format='png' optional | String | スクリーンショットの形式(png またはjpeg ) |
options.quality=100 optional | Number | JPEG形式の場合のスクリーンショットの品質(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
: スクリーンショットバッファ