Skip to main content

saveScreenshot

Save a screenshot of the current browsing context to a PNG file on your OS. Be aware that some browser drivers take screenshots of the whole document (e.g. Geckodriver with Firefox) and others only of the current viewport (e.g. Chromedriver with Chrome).

Usage
browser.saveScreenshot(filepath)
Parameters
NameTypeDetails
filepathStringpath to the generated image (.png suffix is required) relative to the execution directory
Examples
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');
}

Welcome! How can I help?

WebdriverIO AI Copilot