Skip to content

Commit f7cabb6

Browse files
committed
(docs): saveScreenshot requires afterTest hook to be async
When requesting a screenshot in the `afterTest` hook, I would sometime not have any screenshot generated. I eventually found `browser.saveScreenshot` is an async function and the hook has to be explicitly defined `async`: #5545 (comment) Add an example to the `browser.saveScreenshot` documentation showing how to use it in the `afterTest` hook. Signed-off-by: Antoine Musso <amusso@wikimedia.org>
1 parent 37ad290 commit f7cabb6

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

packages/webdriverio/src/commands/browser/saveScreenshot.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import { getAbsoluteFilepath, assertDirectoryExists } from '../../utils/index.js
1414
});
1515
* </example>
1616
*
17+
* When running from a hook, make sure to explicitly define the hook as async:
18+
* <example>
19+
:wdio.conf.js
20+
afterTest: async function(test) {
21+
await browser.saveScreenshot('./some/path/screenshot.png');
22+
}
23+
* </example>
1724
* @alias browser.saveScreenshot
1825
* @param {String} filepath path to the generated image (`.png` suffix is required) relative to the execution directory
1926
* @return {Buffer} screenshot buffer

0 commit comments

Comments
 (0)