saveScreenshot
將目前瀏覽內容的螢幕截圖儲存為作業系統上的 PNG 檔案。請注意,某些瀏覽器驅動程式會截取整個文件(例如,使用 Firefox 的 Geckodriver)的螢幕截圖,而其他則只截取目前的視窗範圍(例如,使用 Chrome 的 Chromedriver)。
用法
browser.saveScreenshot(filepath)
參數
名稱 | 類型 | 詳細資訊 |
---|---|---|
filepath | 字串 | 相對於執行目錄產生的影像路徑 (必須有 .png 副檔名) |
範例
saveScreenshot.js
it('should save a screenshot of the browser view', async () => {
await browser.saveScreenshot('./some/path/screenshot.png');
});
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');
}